mirror of https://github.com/django/django.git
Ensured that registered checks accept keyword arguments.
This commit is contained in:
parent
ef39a8829b
commit
cf2ca22a57
|
@ -1,5 +1,6 @@
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
||||||
|
from django.utils.inspect import func_accepts_kwargs
|
||||||
from django.utils.itercompat import is_iterable
|
from django.utils.itercompat import is_iterable
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,13 +39,17 @@ class CheckRegistry:
|
||||||
|
|
||||||
registry = CheckRegistry()
|
registry = CheckRegistry()
|
||||||
@registry.register('mytag', 'anothertag')
|
@registry.register('mytag', 'anothertag')
|
||||||
def my_check(apps, **kwargs):
|
def my_check(app_configs, **kwargs):
|
||||||
# ... perform checks and collect `errors` ...
|
# ... perform checks and collect `errors` ...
|
||||||
return errors
|
return errors
|
||||||
# or
|
# or
|
||||||
registry.register(my_check, 'mytag', 'anothertag')
|
registry.register(my_check, 'mytag', 'anothertag')
|
||||||
"""
|
"""
|
||||||
def inner(check):
|
def inner(check):
|
||||||
|
if not func_accepts_kwargs(check):
|
||||||
|
raise TypeError(
|
||||||
|
'Check functions must accept keyword arguments (**kwargs).'
|
||||||
|
)
|
||||||
check.tags = tags
|
check.tags = tags
|
||||||
checks = self.deployment_checks if kwargs.get('deploy') else self.registered_checks
|
checks = self.deployment_checks if kwargs.get('deploy') else self.registered_checks
|
||||||
checks.add(check)
|
checks.add(check)
|
||||||
|
|
|
@ -66,6 +66,14 @@ class SystemCheckFrameworkTests(SimpleTestCase):
|
||||||
self.assertEqual(errors, errors2)
|
self.assertEqual(errors, errors2)
|
||||||
self.assertEqual(sorted(errors), [4, 5])
|
self.assertEqual(sorted(errors), [4, 5])
|
||||||
|
|
||||||
|
def test_register_no_kwargs_error(self):
|
||||||
|
registry = CheckRegistry()
|
||||||
|
msg = 'Check functions must accept keyword arguments (**kwargs).'
|
||||||
|
with self.assertRaisesMessage(TypeError, msg):
|
||||||
|
@registry.register
|
||||||
|
def no_kwargs(app_configs, databases):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class MessageTests(SimpleTestCase):
|
class MessageTests(SimpleTestCase):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue