Esempio n. 1
0
    def test_oops_there_is_more_than_one(self):
        Site.objects.create(hostname='example.com', is_default_site=True,
                            root_page=Page.objects.get(pk=2))

        site = Site(hostname='test.com', is_default_site=True,
                    root_page=Page.objects.get(pk=2))
        with self.assertRaises(Site.MultipleObjectsReturned):
            # If there already are multiple default sites, you're in trouble
            site.clean_fields()
Esempio n. 2
0
 def test_with_server_name(self):
     request = HttpRequest()
     request.META = {
         'SERVER_NAME': 'example.com',
         'SERVER_PORT': 80
     }
     self.assertEqual(Site.find_for_request(request), self.site)
Esempio n. 3
0
 def process_request(self, request):
     """
     Set request.site to contain the Site object responsible for handling this request,
     according to hostname matching rules
     """
     try:
         request.site = Site.find_for_request(request)
     except Site.DoesNotExist:
         request.site = None
Esempio n. 4
0
    def setUp(self):
        self.home_page = Page.objects.get(id=2)
        self.routable_page = self.home_page.add_child(
            instance=RoutablePageTest(
                title="Routable Page",
                live=True,
            ))

        self.rf = RequestFactory()
        self.request = self.rf.get(self.routable_page.url)
        self.request.site = Site.find_for_request(self.request)
        self.context = {'request': self.request}
Esempio n. 5
0
 def test_with_x_forwarded_host(self):
     with self.settings(USE_X_FORWARDED_HOST=True):
         request = HttpRequest()
         request.META = {'HTTP_X_FORWARDED_HOST': 'example.com'}
         self.assertEqual(Site.find_for_request(request), self.site)
Esempio n. 6
0
 def test_with_unknown_host(self):
     request = HttpRequest()
     request.META = {'HTTP_HOST': 'unknown.com'}
     self.assertEqual(Site.find_for_request(request), self.default_site)
Esempio n. 7
0
 def test_with_host(self):
     request = HttpRequest()
     request.META = {'HTTP_HOST': 'example.com'}
     self.assertEqual(Site.find_for_request(request), self.site)
Esempio n. 8
0
 def test_default(self):
     request = HttpRequest()
     self.assertEqual(Site.find_for_request(request), self.default_site)
Esempio n. 9
0
 def test_no_site_name_default_port_n(self):
     site = Site(hostname='example.com', port=8080, is_default_site=True)
     self.assertEqual(site.__str__(), 'example.com:8080 [default]')
Esempio n. 10
0
 def test_no_site_name_not_default_port_80(self):
     site = Site(hostname='example.com', port=80, is_default_site=False)
     self.assertEqual(site.__str__(), 'example.com')
Esempio n. 11
0
 def test_site_name_default(self):
     site = Site(hostname='example.com', port=80, site_name='example dot com', is_default_site=True)
     self.assertEqual(site.__str__(), 'example dot com [default]')
Esempio n. 12
0
 def test_root_url_custom_port(self):
     site = Site(hostname='example.com', port=8000)
     self.assertEqual(site.root_url, 'http://example.com:8000')
Esempio n. 13
0
 def test_root_url_https(self):
     site = Site(hostname='example.com', port=443)
     self.assertEqual(site.root_url, 'https://example.com')
Esempio n. 14
0
 def test_there_can_only_be_one(self):
     site = Site(hostname='test.com', is_default_site=True,
                 root_page=Page.objects.get(pk=2))
     with self.assertRaises(ValidationError):
         site.clean_fields()
Esempio n. 15
0
 def test_natural_key(self):
     site = Site(hostname='example.com', port=8080)
     self.assertEqual(site.natural_key(), ('example.com', 8080))