lundi 22 février 2021

Sending an array as data with APIClient on Django?

I'm designing a backend with Django Rest Framework. I have this endpoint that expects to receive with each HTTP request, an array of numbers in the data of the request. This works just fine when the frontend communicates with the backend, the problem is that I can't test it. I'm currently using the APIClient class that comes with the framework for my integration tests, but if I try to write inside a test something like:

client.post('/my-endpoint/', data=[1,2,3])

I get the error:

AttributeError: 'list' object has no attribute 'items'

If I try passing the array as a positional argument instead of as 'data' I get the same error.

How can I pass an array as data with APIClient?

Aucun commentaire:

Enregistrer un commentaire