request.data not always a queryDict

Viewed 201

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?

1 Answers

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'
Related