Exemplo n.º 1
0
 def test_debug_toolbar_new_warning(self):
     msg = (
         'The django-hosts and django-debug-toolbar middlewares are in the '
         'wrong order. Make sure the django-hosts middleware comes before '
         'the django-debug-toolbar middleware in the MIDDLEWARE setting.')
     with self.assertRaisesMessage(ImproperlyConfigured, msg):
         HostsRequestMiddleware()
Exemplo n.º 2
0
 def test_sites_callback_with_parent_host(self):
     rf = RequestFactory(HTTP_HOST='wiki.site2')
     request = rf.get('/simple/')
     middleware = HostsRequestMiddleware()
     middleware.process_request(request)
     self.assertEqual(request.urlconf, 'tests.urls.simple')
     self.assertEqual(request.site.pk, self.site2.pk)
Exemplo n.º 3
0
 def test_fallback_to_defaulthost(self):
     rf = RequestFactory(HTTP_HOST='ss.example.com')
     request = rf.get('/template/test/')
     middleware = HostsRequestMiddleware()
     middleware.process_request(request)
     self.assertEqual(request.urlconf, 'tests.urls.complex')
     host, kwargs = middleware.get_host('non-existing')
     self.assertEqual(host.name, 'with_view_kwargs')
Exemplo n.º 4
0
 def test_manager_missing_site(self):
     rf = RequestFactory(HTTP_HOST='static')
     request = rf.get('/simple/')
     middleware = HostsRequestMiddleware()
     middleware.process_request(request)
     self.assertEqual(request.urlconf, 'tests.urls.simple')
     self.assertRaises(AttributeError, lambda: request.site)
     self.assertEqual(list(WikiPage.on_site.by_request(request)), [])
Exemplo n.º 5
0
 def test_manager_simple(self):
     rf = RequestFactory(HTTP_HOST='wiki.site2')
     request = rf.get('/simple/')
     middleware = HostsRequestMiddleware()
     middleware.process_request(request)
     self.assertEqual(request.urlconf, 'tests.urls.simple')
     self.assertEqual(request.site.pk, self.site2.pk)
     self.assertEqual(list(WikiPage.on_site.by_request(request)),
                      [self.page3])
Exemplo n.º 6
0
    def test_sites_cached_callback(self):
        rf = RequestFactory(HTTP_HOST='admin.site4')
        request = rf.get('/simple/')
        middleware = HostsRequestMiddleware()
        middleware.process_request(request)

        get_site = lambda: request.site.domain

        # first checking if there is a db query
        self.assertEqual(request.site._wrapped, empty)
        self.assertNumQueries(1, get_site)
        self.assertEqual(request.site._wrapped, self.site4)

        # resetting the wrapped site instance to check the cache value
        request.site._wrapped = empty
        self.assertNumQueries(0, get_site)
        self.assertEqual(request.site.pk, self.site4.pk)
Exemplo n.º 7
0
 def test_request_urlconf_module(self):
     rf = RequestFactory(HTTP_HOST='other.example.com')
     request = rf.get('/simple/')
     middleware = HostsRequestMiddleware()
     middleware.process_request(request)
     self.assertEqual(request.urlconf, 'tests.urls.simple')
Exemplo n.º 8
0
 def test_multiple_subdomains(self):
     rf = RequestFactory(HTTP_HOST='spam.eggs.example.com')
     request = rf.get('/multiple/')
     middleware = HostsRequestMiddleware()
     middleware.process_request(request)
     self.assertEqual(request.urlconf, 'tests.urls.multiple')