summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBertrand Bordage <bordage.bertrand@gmail.com>2016-10-23 18:54:56 (GMT)
committerBertrand Bordage <bordage.bertrand@gmail.com>2016-10-23 18:54:56 (GMT)
commit770368b338023e4f6e54263a22760e98f69e45f8 (patch)
tree286c2154fd76037bdccbdb142b2ba0a75e6b59c7
parentc1f4be6b6fb992ad707b4500acb9afae448bb269 (diff)
downloaddjango-cachalot-770368b338023e4f6e54263a22760e98f69e45f8.zip
django-cachalot-770368b338023e4f6e54263a22760e98f69e45f8.tar.gz
django-cachalot-770368b338023e4f6e54263a22760e98f69e45f8.tar.bz2
Adds a test for the compatibility check.
-rw-r--r--cachalot/tests/settings.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/cachalot/tests/settings.py b/cachalot/tests/settings.py
index 8c07535..2e97bff 100644
--- a/cachalot/tests/settings.py
+++ b/cachalot/tests/settings.py
@@ -7,6 +7,7 @@ from unittest import skipIf
from django.conf import settings
from django.contrib.auth.models import User
from django.core.cache import DEFAULT_CACHE_ALIAS
+from django.core.checks import run_checks, Error, Tags
from django.db import connection
from django.test import TransactionTestCase
from django.test.utils import override_settings
@@ -226,3 +227,53 @@ class SettingsTestCase(TransactionTestCase):
list(User.objects.all())
with self.assertNumQueries(1):
list(User.objects.all())
+
+ def test_compatibility(self):
+ """
+ Checks that an error is raised:
+ - if an incompatible database is configured
+ - if an incompatible cache is configured as ``CACHALOT_CACHE``
+ """
+ def get_error(object_path):
+ return Error('`%s` is not compatible with django-cachalot.'
+ % object_path, id='cachalot.E001')
+
+ incompatible_database = {
+ 'ENGINE': 'django.db.backends.oracle',
+ 'NAME': 'non_existent_db',
+ }
+ incompatible_cache = {
+ 'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
+ 'LOCATION': 'cache_table'
+ }
+ with self.settings(DATABASES={'default': incompatible_database}):
+ errors = run_checks(tags=[Tags.compatibility])
+ self.assertListEqual(errors,
+ [get_error(incompatible_database['ENGINE'])])
+ with self.settings(CACHES={'default': incompatible_cache}):
+ errors = run_checks(tags=[Tags.compatibility])
+ self.assertListEqual(errors,
+ [get_error(incompatible_cache['BACKEND'])])
+ with self.settings(DATABASES={'default': incompatible_database},
+ CACHES={'default': incompatible_cache}):
+ errors = run_checks(tags=[Tags.compatibility])
+ self.assertListEqual(errors,
+ [get_error(incompatible_database['ENGINE']),
+ get_error(incompatible_cache['BACKEND'])])
+
+ compatible_database = {
+ 'ENGINE': 'django.db.backends.sqlite3',
+ 'NAME': 'non_existent_db.sqlite3',
+ }
+ compatible_cache = {
+ 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
+ }
+ with self.settings(DATABASES={'default': compatible_database,
+ 'secondary': incompatible_database}):
+ errors = run_checks(tags=[Tags.compatibility])
+ self.assertListEqual(errors,
+ [get_error(incompatible_database['ENGINE'])])
+ with self.settings(CACHES={'default': compatible_cache,
+ 'secondary': incompatible_cache}):
+ errors = run_checks(tags=[Tags.compatibility])
+ self.assertListEqual(errors, [])