how to use headers with django test requests?
I have requests like this:
requests.get(url=MY_URL, headers={"key": MY_KEY})
requests.post(url=MY_URL, json=MY_DATA, headers={"key": MY_KEY})
and it's working.
Right now I'm writing tests for some module and I have problem with key varialbe, because I've tried:
self.client.get(MY_URL, **{"key": MY_KEY})
self.client.get(MY_URL, headers={"key": MY_KEY})
self.client.post(MY_URL, MY_DATA, **{"key": MY_KEY})
self.client.post(MY_URL, MY_DATA, headers={"key": MY_KEY})
and all this requests return response 400. My guess is that there is something wrong with header. Do you know how to write this correctly?
add the prefix HTTP_
to whatever objects you wanna pass.
for example, if I want to pass "dog": "rexy"
it will be a client.post("some_req", HTTP_dog="rexy")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With