Пример #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)
Пример #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)
Пример #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)
Пример #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)), [])
Пример #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)), [])
Пример #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])
Пример #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])
Пример #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])
Пример #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)
Пример #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)
Пример #11
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')
Пример #12
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')
Пример #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')
Пример #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')