Add Extra Headers to Test Client Requests

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
"""
example of using the **extra kwarg param to add headers to the test client request
"""
from django.test.utils import setup_test_environment
setup_test_environment()
from django.test.client import Client
c = Client()

#example using a query string param
c.get('/some/path/', {'qs_param':'foo'}, **{'HTTP_USER_AGENT':'silly-human', 'REMOTE_ADDR':'127.0.0.1'})

#example without a query string param
c.get('/some/path/', **{'HTTP_USER_AGENT':'silly-human', 'REMOTE_ADDR':'127.0.0.1'})

More like this

  1. Pretty print SQL of query sets by peterbe 4 years ago
  2. Effective content caching for mass-load site using redirect feature by nnseva 1 year, 10 months ago
  3. QuerySetManager - easily add new QuerySet methods using a Model inner class by simon 5 years ago
  4. django soaplib test client by erny 4 years, 1 month ago
  5. Add context_data to a UpdateView if form is valid by jayfk 1 week, 2 days ago

Comments

(Forgotten your password?)