Add routing test for when two sites have the same hostname but different ports

This commit is contained in:
Nick Smith 2014-06-25 11:03:30 +01:00
parent 49cb5b1025
commit eccb87d9a0

View file

@ -16,6 +16,7 @@ class TestRouting(TestCase):
default_site = Site.objects.get(is_default_site=True)
events_page = Page.objects.get(url_path='/home/events/')
events_site = Site.objects.create(hostname='events.example.com', root_page=events_page)
alternate_port_events_site = Site.objects.create(hostname='events.example.com', root_page=events_page, port='8765')
# requests without a Host: header should be directed to the default site
request = HttpRequest()
@ -28,6 +29,12 @@ class TestRouting(TestCase):
request.META['HTTP_HOST'] = 'events.example.com'
self.assertEqual(Site.find_for_request(request), events_site)
# ports in the Host: header should be respected
request = HttpRequest()
request.path = '/'
request.META['HTTP_HOST'] = 'events.example.com:8765'
self.assertEqual(Site.find_for_request(request), alternate_port_events_site)
# requests with an unrecognised Host: header should be directed to the default site
request = HttpRequest()
request.path = '/'