pythondjangopython-2.7django-unittest

Is there any way to get the default domain of Client() in unittest of Django?


I would like to get the default domain name of Client() in Django unittests. I saw a way to change the default one. But didn't find a way to get the default domain name.


Solution

  • The default domain name for Django's test client is testserver. It's hardcoded in the RequestFactory base class.

    If you want to change the domain for the specific request, you can just pass it as the kwarg:

    self.client.get('/some-path', SERVER_NAME="anotherdomain.com")