summaryrefslogtreecommitdiff
path: root/django/test
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2014-01-20 10:45:21 +0800
committerRussell Keith-Magee <russell@keith-magee.com>2014-01-20 10:45:21 +0800
commitd818e0c9b2b88276cc499974f9eee893170bf0a8 (patch)
tree13ef631f7ba50bf81fa36f484abf925ba8172651 /django/test
parent6e7bd0b63bd01949ac4fd647f2597639bed0c3a2 (diff)
Fixed #16905 -- Added extensible checks (nee validation) framework
This is the result of Christopher Medrela's 2013 Summer of Code project. Thanks also to Preston Holmes, Tim Graham, Anssi Kääriäinen, Florian Apolloner, and Alex Gaynor for review notes along the way. Also: Fixes #8579, fixes #3055, fixes #19844.
Diffstat (limited to 'django/test')
-rw-r--r--django/test/__init__.py3
-rw-r--r--django/test/testcases.py6
-rw-r--r--django/test/utils.py20
3 files changed, 25 insertions, 4 deletions
diff --git a/django/test/__init__.py b/django/test/__init__.py
index c611ef6850..32608a94f2 100644
--- a/django/test/__init__.py
+++ b/django/test/__init__.py
@@ -8,10 +8,11 @@ from django.test.testcases import (
SimpleTestCase, LiveServerTestCase, skipIfDBFeature,
skipUnlessDBFeature
)
-from django.test.utils import modify_settings, override_settings
+from django.test.utils import modify_settings, override_settings, override_system_checks
__all__ = [
'Client', 'RequestFactory', 'TestCase', 'TransactionTestCase',
'SimpleTestCase', 'LiveServerTestCase', 'skipIfDBFeature',
'skipUnlessDBFeature', 'modify_settings', 'override_settings',
+ 'override_system_checks'
]
diff --git a/django/test/testcases.py b/django/test/testcases.py
index 056eb5469f..4a44a171bc 100644
--- a/django/test/testcases.py
+++ b/django/test/testcases.py
@@ -787,7 +787,7 @@ class TransactionTestCase(SimpleTestCase):
# We have to use this slightly awkward syntax due to the fact
# that we're using *args and **kwargs together.
call_command('loaddata', *self.fixtures,
- **{'verbosity': 0, 'database': db_name, 'skip_validation': True})
+ **{'verbosity': 0, 'database': db_name, 'skip_checks': True})
def _post_teardown(self):
"""Performs any post-test things. This includes:
@@ -820,7 +820,7 @@ class TransactionTestCase(SimpleTestCase):
# when flushing only a subset of the apps
for db_name in self._databases_names(include_mirrors=False):
call_command('flush', verbosity=0, interactive=False,
- database=db_name, skip_validation=True,
+ database=db_name, skip_checks=True,
reset_sequences=False,
allow_cascade=self.available_apps is not None,
inhibit_post_migrate=self.available_apps is not None)
@@ -887,7 +887,7 @@ class TestCase(TransactionTestCase):
'verbosity': 0,
'commit': False,
'database': db_name,
- 'skip_validation': True,
+ 'skip_checks': True,
})
except Exception:
self._fixture_teardown()
diff --git a/django/test/utils.py b/django/test/utils.py
index 42cb127129..d205f5c9fb 100644
--- a/django/test/utils.py
+++ b/django/test/utils.py
@@ -300,6 +300,26 @@ class modify_settings(override_settings):
super(modify_settings, self).enable()
+def override_system_checks(new_checks):
+ """ Acts as a decorator. Overrides list of registered system checks.
+ Useful when you override `INSTALLED_APPS`, e.g. if you exclude `auth` app,
+ you also need to exclude its system checks. """
+
+ from django.core.checks.registry import registry
+
+ def outer(test_func):
+ @wraps(test_func)
+ def inner(*args, **kwargs):
+ old_checks = registry.registered_checks
+ registry.registered_checks = new_checks
+ try:
+ return test_func(*args, **kwargs)
+ finally:
+ registry.registered_checks = old_checks
+ return inner
+ return outer
+
+
def compare_xml(want, got):
"""Tries to do a 'xml-comparison' of want and got. Plain string
comparison doesn't always work because, for example, attribute