コード例 #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()
コード例 #2
0
ファイル: test_sites.py プロジェクト: timgraham/django-hosts
 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)
コード例 #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')
コード例 #4
0
ファイル: test_sites.py プロジェクト: timgraham/django-hosts
 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)), [])
コード例 #5
0
ファイル: test_sites.py プロジェクト: timgraham/django-hosts
 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])
コード例 #6
0
ファイル: test_sites.py プロジェクト: timgraham/django-hosts
    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)
コード例 #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')
コード例 #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')