About RequestFactory in Django Tests
In Django tests when you use RequestFactory
to create fake requests, you can pass extra META parameters to the get()
, post()
, etc. methods as additional keyword arguments.
For example to pass a custom user agent you would do this:
factory = RequestFactory()
request = factory.get(
"/",
{"page": "1"},
HTTP_USER_AGENT="Facebot",
)
Tips and Tricks Programming Testing Django 4.2 Django 3.2 Django 2.2
Also by me
Django Paddle Subscriptions app
For Django-based SaaS projects.
Django GDPR Cookie Consent app
For Django websites that use cookies.