How to send data in a GET request when doing unit tests in Django?

0

I am working on the backend of a web application using Django and Django Restframework. I have several viewsets defined according to the models that are handled and to which several requests are made ( GET, PUT, DELETE, POST ).

I have done several unit tests to verify that the requests return the appropriate values and until now everything is going well. A few days ago I did this question to know how to extract information from the request, and now I want to do a test where I send this information in the request. How can I do it?

Thanks in advance and sorry for the spelling.

    
asked by Ethan 25.01.2018 в 15:31
source

1 answer

2

Your question has little detail, a priori I can give you a very general solution. You could use django.test.Client to make requests:

>>> from django.test import Client
>>> c = Client()
>>> response = c.get('/customers/details/', {'name': 'fred', 'age': 7})

Then you should do a series of asserts to check the response returned by the server. For more info: link

    
answered by 25.01.2018 / 16:59
source