MCPcopy
hub / github.com/django/django / test_get_current_site

Method test_get_current_site

tests/sites_tests/tests.py:60–81  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

58
59 @override_settings(ALLOWED_HOSTS=["example.com"])
60 def test_get_current_site(self):
61 # The correct Site object is returned
62 request = HttpRequest()
63 request.META = {
64 "SERVER_NAME": "example.com",
65 "SERVER_PORT": "80",
66 }
67 site = get_current_site(request)
68 self.assertIsInstance(site, Site)
69 self.assertEqual(site.id, settings.SITE_ID)
70
71 # An exception is raised if the sites framework is installed
72 # but there is no matching Site
73 site.delete()
74 with self.assertRaises(ObjectDoesNotExist):
75 get_current_site(request)
76
77 # A RequestSite is returned if the sites framework is not installed
78 with self.modify_settings(INSTALLED_APPS={"remove": "django.contrib.sites"}):
79 site = get_current_site(request)
80 self.assertIsInstance(site, RequestSite)
81 self.assertEqual(site.name, "example.com")
82
83 @override_settings(SITE_ID=None, ALLOWED_HOSTS=["example.com"])
84 def test_get_current_site_no_site_id(self):

Callers

nothing calls this directly

Calls 4

HttpRequestClass · 0.90
get_current_siteFunction · 0.90
modify_settingsMethod · 0.80
deleteMethod · 0.45

Tested by

no test coverage detected