samedi 22 août 2015

django test Client does not resolve subdomains in tests

using django-subdomains for subdomain in project, the following code works as expected on the console:

from django.test import Client
from subdomains.utils import reverse

c = Client()
v = reverse('articles:index', 'articles')
r = c.get(v, HTTP_HOST='articles.lvh.me:8000')
print r.status_code  # returns 200

But the same code does not work inside a TestCase

class TestTest(TestCase):

    def testOne(self):
        c = Client()
        u = reverse('articles:index', 'articles')
        r = c.get(u, HTTP_HOST='articles.lvh.me:8000')
        print r.status_code  # returns 404

Funny enough, the generated url(reverse) is correct, and works through RequestFactory.

lvh.me redirects to localhost
lvh.me:8000 is the SITE_DOMAIN configured in settings/database

Aucun commentaire:

Enregistrer un commentaire