mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 11:41:20 +01:00
Split up TestFindSiteForRequest
This commit is contained in:
parent
7296a1dd71
commit
0dc8fdb3b3
@ -31,24 +31,37 @@ class TestSiteUrl(TestCase):
|
|||||||
|
|
||||||
|
|
||||||
class TestFindSiteForRequest(TestCase):
|
class TestFindSiteForRequest(TestCase):
|
||||||
def test_find_site_for_request(self):
|
def setUp(self):
|
||||||
site = Site.objects.create(hostname='example.com', port=80, root_page=Page.objects.get(pk=2))
|
self.default_site = Site.objects.get()
|
||||||
|
self.site = Site.objects.create(hostname='example.com', port=80, root_page=Page.objects.get(pk=2))
|
||||||
|
|
||||||
|
def test_default(self):
|
||||||
|
request = HttpRequest()
|
||||||
|
self.assertEqual(Site.find_for_request(request), self.default_site)
|
||||||
|
|
||||||
|
def test_with_host(self):
|
||||||
request = HttpRequest()
|
request = HttpRequest()
|
||||||
request.META = {'HTTP_HOST': 'example.com'}
|
request.META = {'HTTP_HOST': 'example.com'}
|
||||||
self.assertEqual(Site.find_for_request(request), site)
|
self.assertEqual(Site.find_for_request(request), self.site)
|
||||||
|
|
||||||
request2 = HttpRequest()
|
def test_with_unknown_host(self):
|
||||||
request2.META = {
|
request = HttpRequest()
|
||||||
|
request.META = {'HTTP_HOST': 'unknown.com'}
|
||||||
|
self.assertEqual(Site.find_for_request(request), self.default_site)
|
||||||
|
|
||||||
|
def test_with_server_name(self):
|
||||||
|
request = HttpRequest()
|
||||||
|
request.META = {
|
||||||
'SERVER_NAME': 'example.com',
|
'SERVER_NAME': 'example.com',
|
||||||
'SERVER_PORT': 80
|
'SERVER_PORT': 80
|
||||||
}
|
}
|
||||||
self.assertEqual(Site.find_for_request(request2), site)
|
self.assertEqual(Site.find_for_request(request), self.site)
|
||||||
|
|
||||||
|
def test_with_x_forwarded_host(self):
|
||||||
with self.settings(USE_X_FORWARDED_HOST=True):
|
with self.settings(USE_X_FORWARDED_HOST=True):
|
||||||
request3 = HttpRequest()
|
request = HttpRequest()
|
||||||
request3.META = {'HTTP_X_FORWARDED_HOST': 'example.com'}
|
request.META = {'HTTP_X_FORWARDED_HOST': 'example.com'}
|
||||||
self.assertEqual(Site.find_for_request(request3), site)
|
self.assertEqual(Site.find_for_request(request), self.site)
|
||||||
|
|
||||||
|
|
||||||
class TestDefaultSite(TestCase):
|
class TestDefaultSite(TestCase):
|
||||||
|
Loading…
Reference in New Issue
Block a user