Beispiel #1
0
 def test_sites_callback_with_parent_host(self):
     rf = RequestFactory(HTTP_HOST='wiki.site2')
     request = rf.get('/simple/')
     middleware = HostsMiddleware()
     middleware.process_request(request)
     self.assertEqual(request.urlconf, 'django_hosts.tests.urls.simple')
     self.assertEqual(request.site.pk, self.site2.pk)
Beispiel #2
0
 def test_sites_callback_with_parent_host(self):
     rf = RequestFactory(HTTP_HOST="wiki.site2")
     request = rf.get("/simple/")
     middleware = HostsMiddleware()
     middleware.process_request(request)
     self.assertEqual(request.urlconf, "django_hosts.tests.urls.simple")
     self.assertEqual(request.site, self.site2)
Beispiel #3
0
 def test_sites_callback_with_parent_host(self):
     rf = RequestFactory(HTTP_HOST='wiki.site2')
     request = rf.get('/simple/')
     middleware = HostsMiddleware()
     middleware.process_request(request)
     self.assertEqual(request.urlconf, 'django_hosts.tests.urls.simple')
     self.assertEqual(request.site.pk, self.site2.pk)
Beispiel #4
0
 def test_manager_missing_site(self):
     rf = RequestFactory(HTTP_HOST='static')
     request = rf.get('/simple/')
     middleware = HostsMiddleware()
     middleware.process_request(request)
     self.assertEqual(request.urlconf, 'django_hosts.tests.urls.simple')
     self.assertRaises(AttributeError, lambda: request.site)
     self.assertEqual(list(WikiPage.on_site.by_request(request)), [])
Beispiel #5
0
 def test_manager_missing_site(self):
     rf = RequestFactory(HTTP_HOST="static")
     request = rf.get("/simple/")
     middleware = HostsMiddleware()
     middleware.process_request(request)
     self.assertEqual(request.urlconf, "django_hosts.tests.urls.simple")
     self.assertRaises(AttributeError, lambda: request.site)
     self.assertEqual(list(WikiPage.on_site.by_request(request)), [])
Beispiel #6
0
 def test_manager_simple(self):
     rf = RequestFactory(HTTP_HOST="wiki.site2")
     request = rf.get("/simple/")
     middleware = HostsMiddleware()
     middleware.process_request(request)
     self.assertEqual(request.urlconf, "django_hosts.tests.urls.simple")
     self.assertEqual(request.site, self.site2)
     self.assertEqual(list(WikiPage.on_site.by_request(request)), [self.page3])
Beispiel #7
0
 def test_manager_simple(self):
     rf = RequestFactory(HTTP_HOST='wiki.site2')
     request = rf.get('/simple/')
     middleware = HostsMiddleware()
     middleware.process_request(request)
     self.assertEqual(request.urlconf, 'django_hosts.tests.urls.simple')
     self.assertEqual(request.site.pk, self.site2.pk)
     self.assertEqual(list(WikiPage.on_site.by_request(request)),
                      [self.page3])
Beispiel #8
0
 def test_manager_simple(self):
     rf = RequestFactory(HTTP_HOST='wiki.site2')
     request = rf.get('/simple/')
     middleware = HostsMiddleware()
     middleware.process_request(request)
     self.assertEqual(request.urlconf, 'django_hosts.tests.urls.simple')
     self.assertEqual(request.site.pk, self.site2.pk)
     self.assertEqual(list(WikiPage.on_site.by_request(request)),
                      [self.page3])
Beispiel #9
0
    def test_sites_cached_callback(self):
        rf = RequestFactory(HTTP_HOST='admin.site4')
        request = rf.get('/simple/')
        middleware = HostsMiddleware()
        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)
Beispiel #10
0
    def test_sites_cached_callback(self):
        rf = RequestFactory(HTTP_HOST='admin.site4')
        request = rf.get('/simple/')
        middleware = HostsMiddleware()
        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)
 def test_fallback_to_defaulthost(self):
     rf = RequestFactory(HTTP_HOST='ss.example.com')
     request = rf.get('/template/test/')
     middleware = HostsMiddleware()
     middleware.process_request(request)
     self.assertEqual(request.urlconf, 'django_hosts.tests.urls.complex')
 def test_request_urlconf_module(self):
     rf = RequestFactory(HTTP_HOST='other.example.com')
     request = rf.get('/simple/')
     middleware = HostsMiddleware()
     middleware.process_request(request)
     self.assertEqual(request.urlconf, 'django_hosts.tests.urls.simple')
Beispiel #13
0
 def test_fallback_to_defaulthost(self):
     rf = RequestFactory(HTTP_HOST='ss.example.com')
     request = rf.get('/template/test/')
     middleware = HostsMiddleware()
     middleware.process_request(request)
     self.assertEqual(request.urlconf, 'django_hosts.tests.urls.complex')
Beispiel #14
0
 def test_request_urlconf_module(self):
     rf = RequestFactory(HTTP_HOST='other.example.com')
     request = rf.get('/simple/')
     middleware = HostsMiddleware()
     middleware.process_request(request)
     self.assertEqual(request.urlconf, 'django_hosts.tests.urls.simple')