From 7296a1dd7198ab60747572cde154fd927facebf0 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 20 Mar 2016 02:09:33 -0400 Subject: [PATCH] Added tests for Site.find_for_request --- wagtail/wagtailcore/tests/test_sites.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/wagtail/wagtailcore/tests/test_sites.py b/wagtail/wagtailcore/tests/test_sites.py index 2d42b23113..7c164c362c 100644 --- a/wagtail/wagtailcore/tests/test_sites.py +++ b/wagtail/wagtailcore/tests/test_sites.py @@ -1,5 +1,6 @@ from django.core.exceptions import ValidationError from django.test import TestCase +from django.http.request import HttpRequest from wagtail.wagtailcore.models import Page, Site @@ -29,6 +30,27 @@ class TestSiteUrl(TestCase): self.assertEqual(site.root_url, 'http://example.com:8000') +class TestFindSiteForRequest(TestCase): + def test_find_site_for_request(self): + site = Site.objects.create(hostname='example.com', port=80, root_page=Page.objects.get(pk=2)) + + request = HttpRequest() + request.META = {'HTTP_HOST': 'example.com'} + self.assertEqual(Site.find_for_request(request), site) + + request2 = HttpRequest() + request2.META = { + 'SERVER_NAME': 'example.com', + 'SERVER_PORT': 80 + } + self.assertEqual(Site.find_for_request(request2), site) + + with self.settings(USE_X_FORWARDED_HOST=True): + request3 = HttpRequest() + request3.META = {'HTTP_X_FORWARDED_HOST': 'example.com'} + self.assertEqual(Site.find_for_request(request3), site) + + class TestDefaultSite(TestCase): def test_create_default_site(self): Site.objects.all().delete()