0
class SampleTest(APITestCase):

   def setUp(self):
       self.id = 1 
       self.api_url = 'api/check_customers'
       self.token ='##############'

   def test_check_customer(self):
       self.client.credentials(HTTP_AUTHORIZATION='Bearer ' + self.token)
       response = self.client.post(self.api_url, data={'id': self.id})

       self.assertEqual(response.status_code, status.HTTP_200_OK)

When I test this code I get the error message which I have set for checking the emptyness of parameter like

{'message': 'id is empty', 'status': 'failed'}

and the way I check this is in views

class Customer(APIView):
    def post(self, request, *args, **kwargs):
        if "id" not in request.data:
        content = {"status": "failed",
                   "message": "id is empty"}
        return Response(content, status=STATUS.HTTP_400_BAD_REQUEST)

I am using DRF 3.3.0 and Django 1.9

Sagar
  • 159
  • 2
  • 17
  • https://github.com/ericleunghk?tab=overview&from=2016-12-01&to=2016-12-31 This link is stating the same problem – Sagar Jul 31 '17 at 20:56

1 Answers1

2
response = self.client.post(self.api_url, data={'id': self.id}, format='json')

This works Fine. Default format type is multipart that has to be json while passing dictionary

Sagar
  • 159
  • 2
  • 17