diff options
| author | Claude Paroz <claude@2xlibre.net> | 2016-03-19 12:15:09 +0100 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2016-04-08 20:28:00 +0200 |
| commit | 0d3c616fbb2f49fa7ff6809e5a6777275352b35b (patch) | |
| tree | e444996e32456a0ab64f65ee76e1d0c110f25ff5 /tests/check_framework | |
| parent | 5ac7c8f7ab2b2e1fec50abb14539a2eb520d1995 (diff) | |
Refs #26351 -- Added check hook to support database-related checks
Thanks Tim Graham and Shai Berger for the reviews.
Diffstat (limited to 'tests/check_framework')
| -rw-r--r-- | tests/check_framework/test_database.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/check_framework/test_database.py b/tests/check_framework/test_database.py new file mode 100644 index 0000000000..73edd6234c --- /dev/null +++ b/tests/check_framework/test_database.py @@ -0,0 +1,33 @@ +import unittest + +from django.core.checks import Tags, run_checks +from django.core.checks.registry import CheckRegistry +from django.db import connection +from django.test import TestCase, mock + + +class DatabaseCheckTests(TestCase): + @property + def func(self): + from django.core.checks.database import check_database_backends + return check_database_backends + + def test_database_checks_not_run_by_default(self): + """ + `database` checks are only run when their tag is specified. + """ + def f1(**kwargs): + return [5] + + registry = CheckRegistry() + registry.register(Tags.database)(f1) + errors = registry.run_checks() + self.assertEqual(errors, []) + + errors2 = registry.run_checks(tags=[Tags.database]) + self.assertEqual(errors2, [5]) + + def test_database_checks_called(self): + with mock.patch('django.db.backends.base.validation.BaseDatabaseValidation.check') as mocked_check: + run_checks(tags=[Tags.database]) + self.assertTrue(mocked_check.called) |
