I am testing an API with Django test client. The API uses geo blocking so in my test I need to specify an IP address to make sure it works properly. How can I do that?
I am making a request in my test like this:
from django.test.client import Client as HttpClient
.
.
.
client = HttpClient()
response = client.get(uri + query_string)
The Client.get()
method has an extra
keyword arguments parameter, which can be used to specify headers.
c.get(/my-url/, REMOTE_ADDR="127.0.0.1")
Pass REMOTE_ADDR in constructor.
client = HttpClient(REMOTE_ADDR='127.0.0.1')
or
client.get('/path/', {'param':'foo'}, **{'HTTP_USER_AGENT':'firefox-22', 'REMOTE_ADDR':'127.0.0.1'})
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