39👍
✅
Django’s Client
extends RequestFactory
so you should be able to pass in extra params as keyword arguments.
Try:
response = self.c.get('/emails/html/upload', SERVER_NAME="mydomain.com")
1👍
The code can help not only in unit test, but it can also help for DRF to use context in a serializer
ResponseSerializer(instance=obj, context={'request': get_request}).data
from django.test.client import RequestFactory
rf = RequestFactory()
rf.defaults['SERVER_NAME'] = 'my-site.com'
get_request = rf.get('/hello/')
- [Django]-Where is the sqlite database file created by Django?
- [Django]-CSRF Token missing or incorrect
- [Django]-How to subquery in queryset in django?
Source:stackexchange.com