Skip to content

Commit

Permalink
Fix test due to change in CommonMiddleware in Django 1.9.
Browse files Browse the repository at this point in the history
References GH-46, GH-51.
  • Loading branch information
tkaemming committed Dec 17, 2015
1 parent 3677f54 commit 42280f6
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions subdomains/tests/tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import functools
import mock
import urlparse
import warnings

from django.core.urlresolvers import NoReverseMatch, set_urlconf
Expand Down Expand Up @@ -154,9 +156,26 @@ def urlconf(subdomain):
def test_appends_slash(self):
for subdomain in (None, 'api', 'wildcard'):
host = self.get_host_for_subdomain(subdomain)
response = self.client.get('/example', HTTP_HOST=host)
path = '/example' # No trailing slash.
response = self.client.get(path, HTTP_HOST=host)
self.assertEqual(response.status_code, 301)
self.assertEqual(response['Location'], 'http://%s/example/' % host)

# Whether the response's Location header contains the URL prefix
# here doesn't actually matter, since it will be considered
# relative to the request URL, which *did* include the HTTP Host
# header. To pave over inconsistencies between Django versions, we
# normalize them both to be prefixed with the requested host. (If a
# *different* base host is returned in the Location header, this
# should override our default base and error.)
normalize = functools.partial(
urlparse.urljoin,
'http://%s/' % (host,),
)

self.assertEqual(
normalize(response['Location']),
normalize(path + '/'),
)


class SubdomainURLReverseTestCase(SubdomainTestMixin, TestCase):
Expand Down

0 comments on commit 42280f6

Please sign in to comment.