summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2014-08-29 14:54:08 +0200
committerClaude Paroz <claude@2xlibre.net>2014-08-30 12:37:10 +0200
commit66757fee7e921ad4c35e0b3f80c25e026100b31c (patch)
tree0b6a6e10a1d800532d114ab4b5b4a2d6f7d73abd /tests
parent05a8cef4288e2a85dbaff12bc2683a75c9998618 (diff)
Fixed #23384 -- Allowed overriding part of a dictionary-type setting
This change is needed for upcoming changes where settings might be grouped in a parent dictionary. Thanks Tim Graham for the review.
Diffstat (limited to 'tests')
-rw-r--r--tests/cache/tests.py6
-rw-r--r--tests/migrations/test_executor.py2
-rw-r--r--tests/migrations/test_loader.py5
-rw-r--r--tests/settings_tests/tests.py57
4 files changed, 67 insertions, 3 deletions
diff --git a/tests/cache/tests.py b/tests/cache/tests.py
index 4677791fcd..2ee7a6200b 100644
--- a/tests/cache/tests.py
+++ b/tests/cache/tests.py
@@ -522,6 +522,7 @@ class BaseCacheTests(object):
def _perform_cull_test(self, cull_cache, initial_count, final_count):
# Create initial cache key entries. This will overflow the cache,
# causing a cull.
+ cull_cache.clear()
for i in range(1, initial_count):
cull_cache.set('cull%d' % i, 'value', 1000)
count = 0
@@ -918,7 +919,10 @@ class DBCacheTests(BaseCacheTests, TransactionTestCase):
stdout=stdout
)
self.assertEqual(stdout.getvalue(),
- "Cache table 'test cache table' already exists.\n" * len(settings.CACHES))
+ "Cache table 'test cache table' already exists.\n" * len([
+ k for k, v in settings.CACHES.items()
+ if v['BACKEND']=='django.core.cache.backends.db.DatabaseCache'])
+ )
def test_createcachetable_with_table_argument(self):
"""
diff --git a/tests/migrations/test_executor.py b/tests/migrations/test_executor.py
index d07eecfcef..7563381abe 100644
--- a/tests/migrations/test_executor.py
+++ b/tests/migrations/test_executor.py
@@ -196,7 +196,7 @@ class ExecutorTests(MigrationTestBase):
@override_settings(
MIGRATION_MODULES={
"migrations": "migrations.test_migrations_custom_user",
- "django.contrib.auth": "django.contrib.auth.migrations",
+ "auth": "django.contrib.auth.migrations",
},
AUTH_USER_MODEL="migrations.Author",
)
diff --git a/tests/migrations/test_loader.py b/tests/migrations/test_loader.py
index 68d05d296f..9f7ce9a8e7 100644
--- a/tests/migrations/test_loader.py
+++ b/tests/migrations/test_loader.py
@@ -81,7 +81,10 @@ class LoaderTests(TestCase):
# Ensure we've included unmigrated apps in there too
self.assertIn("basic", project_state.real_apps)
- @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_unmigdep"})
+ @override_settings(MIGRATION_MODULES={
+ "_clear_defaults": True,
+ "migrations": "migrations.test_migrations_unmigdep"
+ })
def test_load_unmigrated_dependency(self):
"""
Makes sure the loader can load migrations with a dependency on an unmigrated app.
diff --git a/tests/settings_tests/tests.py b/tests/settings_tests/tests.py
index 2dcf62abb5..784346946d 100644
--- a/tests/settings_tests/tests.py
+++ b/tests/settings_tests/tests.py
@@ -273,6 +273,63 @@ class SettingsTests(TestCase):
self.assertRaises(ValueError, setattr, settings,
'ALLOWED_INCLUDE_ROOTS', '/var/www/ssi/')
+ def test_dict_setting(self):
+ """
+ Test that dictionary-type settings can be "complemented", that is existing
+ setting keys/values are not overriden by user settings, but merged into the
+ existing dict.
+ """
+ s = LazySettings() # Start with fresh settings from global_settings.py
+ # Simply overwriting the key
+ s.configure(CACHES={'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}})
+ self.assertEqual(s.CACHES['default']['BACKEND'],
+ 'django.core.cache.backends.dummy.DummyCache')
+
+ s = LazySettings()
+ # More complex overwriting
+ s.configure(CACHES={
+ 'default': {'LOCATION': 'unique-snowflake'},
+ 'temp': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}
+ })
+ self.assertDictEqual(s.CACHES, {
+ 'default': {
+ 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
+ 'LOCATION': 'unique-snowflake'
+ },
+ 'temp': {
+ 'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
+ }
+ })
+
+ def test_dict_setting_clear_defaults(self):
+ """
+ Test the ability to deactivate the merge feature of dictionary settings.
+ """
+ s = LazySettings()
+ s.configure(CACHES={
+ '_clear_defaults': True,
+ 'temp': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}
+ })
+ self.assertDictEqual(s.CACHES, {
+ '_clear_defaults': True,
+ 'temp': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}
+ })
+
+ # Also work on a subkey
+ s = LazySettings()
+ s.configure(CACHES={
+ 'default': {
+ '_clear_defaults': True,
+ 'LOCATION': 'unique-snowflake',
+ }
+ })
+ self.assertDictEqual(s.CACHES, {
+ 'default': {
+ '_clear_defaults': True,
+ 'LOCATION': 'unique-snowflake',
+ }
+ })
+
class TestComplexSettingOverride(TestCase):
def setUp(self):