mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #23750 -- Allowed core.checks.register to be used as a function
This commit is contained in:
parent
b3fd39f7c8
commit
b7a5b6ab86
8 changed files with 71 additions and 14 deletions
|
@ -31,17 +31,47 @@ class DummyObj(object):
|
|||
class SystemCheckFrameworkTests(TestCase):
|
||||
|
||||
def test_register_and_run_checks(self):
|
||||
calls = [0]
|
||||
|
||||
registry = CheckRegistry()
|
||||
|
||||
@registry.register()
|
||||
def f(**kwargs):
|
||||
calls[0] += 1
|
||||
return [1, 2, 3]
|
||||
|
||||
def f2(**kwargs):
|
||||
return [4, ]
|
||||
|
||||
def f3(**kwargs):
|
||||
return [5, ]
|
||||
|
||||
calls = [0]
|
||||
|
||||
# test register as decorator
|
||||
registry = CheckRegistry()
|
||||
registry.register()(f)
|
||||
registry.register("tag1", "tag2")(f2)
|
||||
registry.register("tag2", deploy=True)(f3)
|
||||
|
||||
# test register as function
|
||||
registry2 = CheckRegistry()
|
||||
registry2.register(f)
|
||||
registry2.register(f2, "tag1", "tag2")
|
||||
registry2.register(f3, "tag2", deploy=True)
|
||||
|
||||
# check results
|
||||
errors = registry.run_checks()
|
||||
self.assertEqual(errors, [1, 2, 3])
|
||||
self.assertEqual(calls[0], 1)
|
||||
errors2 = registry2.run_checks()
|
||||
self.assertEqual(errors, errors2)
|
||||
self.assertEqual(sorted(errors), [1, 2, 3, 4])
|
||||
self.assertEqual(calls[0], 2)
|
||||
|
||||
errors = registry.run_checks(tags=["tag1"])
|
||||
errors2 = registry2.run_checks(tags=["tag1"])
|
||||
self.assertEqual(errors, errors2)
|
||||
self.assertEqual(sorted(errors), [4])
|
||||
|
||||
errors = registry.run_checks(tags=["tag1", "tag2"], include_deployment_checks=True)
|
||||
errors2 = registry2.run_checks(tags=["tag1", "tag2"], include_deployment_checks=True)
|
||||
self.assertEqual(errors, errors2)
|
||||
self.assertEqual(sorted(errors), [4, 5])
|
||||
|
||||
|
||||
class MessageTests(TestCase):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue