Search code examples
djangodjango-rest-frameworkdjango-tests

request.data not always a queryDict


Using a PATCH request on a RetrieveUpdateDestroyAPIView I receive the following in RetrieveUpdateDestroyAPIView.update when i run print(request.data):

{'myVar': ''} 

when running automated tests using django rest framework's APIClient I get this:

<QueryDict: {'myVar': ['']}>

Why is this different? What can i do to ensure consistency between my environments of test and dev?


Solution

  • You need to be explicit that you're passing json, you can do this by either:

    response = self.client.patch(self.url, json={'myVar': ''})
    

    Or:

    response = self.client.patch(self.url, {'myVar': ''}, format='json') # added , format='json'