Refs #32508 -- Raised Type/ValueError instead of using "assert" in django.core.

This commit is contained in:
Daniyal 2021-03-16 21:11:27 +05:30 committed by Mariusz Felisiak
parent 37044817f9
commit 474cc420bf
8 changed files with 76 additions and 11 deletions

View file

@ -4,6 +4,7 @@ from io import StringIO
from django.apps import apps
from django.core import checks
from django.core.checks import Error, Warning
from django.core.checks.messages import CheckMessage
from django.core.checks.registry import CheckRegistry
from django.core.management import call_command
from django.core.management.base import CommandError
@ -74,6 +75,20 @@ class SystemCheckFrameworkTests(SimpleTestCase):
def no_kwargs(app_configs, databases):
pass
def test_register_run_checks_non_iterable(self):
registry = CheckRegistry()
@registry.register
def return_non_iterable(**kwargs):
return Error('Message')
msg = (
'The function %r did not return a list. All functions registered '
'with the checks registry must return a list.' % return_non_iterable
)
with self.assertRaisesMessage(TypeError, msg):
registry.run_checks()
class MessageTests(SimpleTestCase):
@ -132,6 +147,11 @@ class MessageTests(SimpleTestCase):
e = Error("Error", obj=DummyObj())
self.assertNotEqual(e, 'a string')
def test_invalid_level(self):
msg = 'The first argument should be level.'
with self.assertRaisesMessage(TypeError, msg):
CheckMessage('ERROR', 'Message')
def simple_system_check(**kwargs):
simple_system_check.kwargs = kwargs