summaryrefslogtreecommitdiff
path: root/tests/sites_tests
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2015-02-12 13:58:37 -0500
committerTim Graham <timograham@gmail.com>2015-02-13 07:01:28 -0500
commite8cf4f8abec87b9da6ed8e5c8cf833af9b27f4dd (patch)
tree0790b14fb20617b490765e9b5cd5ba14a4ffdaad /tests/sites_tests
parentbd4afef98490198e325654952d38a5735ee7e358 (diff)
downloaddjango-e8cf4f8abec87b9da6ed8e5c8cf833af9b27f4dd.tar.gz
Fixed #24332 -- Fixed contrib.sites create_default_site() when 'default' DATABASES is empty.
Diffstat (limited to 'tests/sites_tests')
-rw-r--r--tests/sites_tests/tests.py30
1 files changed, 28 insertions, 2 deletions
diff --git a/tests/sites_tests/tests.py b/tests/sites_tests/tests.py
index eeb6a44646..7eb1c20b60 100644
--- a/tests/sites_tests/tests.py
+++ b/tests/sites_tests/tests.py
@@ -17,6 +17,7 @@ from django.test.utils import captured_stdout
@modify_settings(INSTALLED_APPS={'append': 'django.contrib.sites'})
class SitesFrameworkTests(TestCase):
+ multi_db = True
def setUp(self):
self.site = Site(
@@ -112,7 +113,26 @@ class SitesFrameworkTests(TestCase):
expected_cache.update({self.site.domain: self.site})
self.assertEqual(models.SITE_CACHE, expected_cache)
- clear_site_cache(Site, instance=self.site)
+ clear_site_cache(Site, instance=self.site, using='default')
+ self.assertEqual(models.SITE_CACHE, {})
+
+ @override_settings(SITE_ID='')
+ def test_clear_site_cache_domain(self):
+ site = Site.objects.create(name='example2.com', domain='example2.com')
+ request = HttpRequest()
+ request.META = {
+ "SERVER_NAME": "example2.com",
+ "SERVER_PORT": "80",
+ }
+ get_current_site(request) # prime the models.SITE_CACHE
+ expected_cache = {site.domain: site}
+ self.assertEqual(models.SITE_CACHE, expected_cache)
+
+ # Site exists in 'default' database so using='other' shouldn't clear.
+ clear_site_cache(Site, instance=site, using='other')
+ self.assertEqual(models.SITE_CACHE, expected_cache)
+ # using='default' should clear.
+ clear_site_cache(Site, instance=site, using='default')
self.assertEqual(models.SITE_CACHE, {})
@@ -146,7 +166,7 @@ class CreateDefaultSiteTests(TestCase):
self.assertEqual("", stdout.getvalue())
@override_settings(DATABASE_ROUTERS=[JustOtherRouter()])
- def test_multi_db(self):
+ def test_multi_db_with_router(self):
"""
#16353, #16828 - The default site creation should respect db routing.
"""
@@ -155,6 +175,12 @@ class CreateDefaultSiteTests(TestCase):
self.assertFalse(Site.objects.using('default').exists())
self.assertTrue(Site.objects.using('other').exists())
+ def test_multi_db(self):
+ create_default_site(self.app_config, using='default', verbosity=0)
+ create_default_site(self.app_config, using='other', verbosity=0)
+ self.assertTrue(Site.objects.using('default').exists())
+ self.assertTrue(Site.objects.using('other').exists())
+
def test_save_another(self):
"""
#17415 - Another site can be created right after the default one.