From d818e0c9b2b88276cc499974f9eee893170bf0a8 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Mon, 20 Jan 2014 10:45:21 +0800 Subject: Fixed #16905 -- Added extensible checks (nee validation) framework MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../admin_scripts/app_raising_messages/__init__.py | 0 tests/admin_scripts/app_raising_messages/models.py | 27 +++ .../admin_scripts/app_raising_warning/__init__.py | 0 tests/admin_scripts/app_raising_warning/models.py | 16 ++ .../management/commands/app_command.py | 2 +- .../management/commands/base_command.py | 2 +- .../management/commands/label_command.py | 2 +- .../management/commands/noargs_command.py | 2 +- .../management/commands/validation_command.py | 11 ++ tests/admin_scripts/tests.py | 197 +++++++++++++++------ 10 files changed, 202 insertions(+), 57 deletions(-) create mode 100644 tests/admin_scripts/app_raising_messages/__init__.py create mode 100644 tests/admin_scripts/app_raising_messages/models.py create mode 100644 tests/admin_scripts/app_raising_warning/__init__.py create mode 100644 tests/admin_scripts/app_raising_warning/models.py create mode 100644 tests/admin_scripts/management/commands/validation_command.py (limited to 'tests/admin_scripts') diff --git a/tests/admin_scripts/app_raising_messages/__init__.py b/tests/admin_scripts/app_raising_messages/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/admin_scripts/app_raising_messages/models.py b/tests/admin_scripts/app_raising_messages/models.py new file mode 100644 index 0000000000..aece8a8176 --- /dev/null +++ b/tests/admin_scripts/app_raising_messages/models.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.core import checks +from django.db import models + + +class ModelRaisingMessages(models.Model): + @classmethod + def check(self, **kwargs): + return [ + checks.Warning( + 'First warning', + hint='Hint', + obj='obj' + ), + checks.Warning( + 'Second warning', + hint=None, + obj='a' + ), + checks.Error( + 'An error', + hint='Error hint', + obj=None, + ) + ] diff --git a/tests/admin_scripts/app_raising_warning/__init__.py b/tests/admin_scripts/app_raising_warning/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/admin_scripts/app_raising_warning/models.py b/tests/admin_scripts/app_raising_warning/models.py new file mode 100644 index 0000000000..8f58abe127 --- /dev/null +++ b/tests/admin_scripts/app_raising_warning/models.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.core import checks +from django.db import models + + +class ModelRaisingMessages(models.Model): + @classmethod + def check(self, **kwargs): + return [ + checks.Warning( + 'A warning', + hint=None, + ), + ] diff --git a/tests/admin_scripts/management/commands/app_command.py b/tests/admin_scripts/management/commands/app_command.py index 4706645484..f0981eba2d 100644 --- a/tests/admin_scripts/management/commands/app_command.py +++ b/tests/admin_scripts/management/commands/app_command.py @@ -3,7 +3,7 @@ from django.core.management.base import AppCommand class Command(AppCommand): help = 'Test Application-based commands' - requires_model_validation = False + requires_system_checks = False args = '[app_label ...]' def handle_app_config(self, app_config, **options): diff --git a/tests/admin_scripts/management/commands/base_command.py b/tests/admin_scripts/management/commands/base_command.py index 6e37ca238e..c313235ead 100644 --- a/tests/admin_scripts/management/commands/base_command.py +++ b/tests/admin_scripts/management/commands/base_command.py @@ -10,7 +10,7 @@ class Command(BaseCommand): make_option('--option_c', '-c', action='store', dest='option_c', default='3'), ) help = 'Test basic commands' - requires_model_validation = False + requires_system_checks = False args = '[labels ...]' def handle(self, *labels, **options): diff --git a/tests/admin_scripts/management/commands/label_command.py b/tests/admin_scripts/management/commands/label_command.py index 3bce1305bc..9bba413ff3 100644 --- a/tests/admin_scripts/management/commands/label_command.py +++ b/tests/admin_scripts/management/commands/label_command.py @@ -3,7 +3,7 @@ from django.core.management.base import LabelCommand class Command(LabelCommand): help = "Test Label-based commands" - requires_model_validation = False + requires_system_checks = False args = '