Kaydet (Commit) 28753258 authored tarafından Jon Dufresne's avatar Jon Dufresne Kaydeden (comit) Tim Graham

Fixed #25500 -- Added --fail-level option to check command.

This option specifies the level that check command exits with a
non-zero status. Default is ``ERROR``.
üst b215a3ab
...@@ -48,8 +48,8 @@ class CheckMessage(object): ...@@ -48,8 +48,8 @@ class CheckMessage(object):
return "<%s: level=%r, msg=%r, hint=%r, obj=%r, id=%r>" % \ return "<%s: level=%r, msg=%r, hint=%r, obj=%r, id=%r>" % \
(self.__class__.__name__, self.level, self.msg, self.hint, self.obj, self.id) (self.__class__.__name__, self.level, self.msg, self.hint, self.obj, self.id)
def is_serious(self): def is_serious(self, level=ERROR):
return self.level >= ERROR return self.level >= level
def is_silenced(self): def is_silenced(self):
from django.conf import settings from django.conf import settings
......
...@@ -355,7 +355,7 @@ class BaseCommand(object): ...@@ -355,7 +355,7 @@ class BaseCommand(object):
translation.activate(saved_locale) translation.activate(saved_locale)
def check(self, app_configs=None, tags=None, display_num_errors=False, def check(self, app_configs=None, tags=None, display_num_errors=False,
include_deployment_checks=False): include_deployment_checks=False, fail_level=checks.ERROR):
""" """
Uses the system check framework to validate entire Django project. Uses the system check framework to validate entire Django project.
Raises CommandError for any serious message (error or critical errors). Raises CommandError for any serious message (error or critical errors).
...@@ -409,7 +409,7 @@ class BaseCommand(object): ...@@ -409,7 +409,7 @@ class BaseCommand(object):
len(all_issues) - visible_issue_count, len(all_issues) - visible_issue_count,
) )
if any(e.is_serious() and not e.is_silenced() for e in all_issues): if any(e.is_serious(fail_level) and not e.is_silenced() for e in all_issues):
msg = self.style.ERROR("SystemCheckError: %s" % header) + body + footer msg = self.style.ERROR("SystemCheckError: %s" % header) + body + footer
raise SystemCheckError(msg) raise SystemCheckError(msg)
else: else:
......
...@@ -20,6 +20,16 @@ class Command(BaseCommand): ...@@ -20,6 +20,16 @@ class Command(BaseCommand):
help='List available tags.') help='List available tags.')
parser.add_argument('--deploy', action='store_true', dest='deploy', parser.add_argument('--deploy', action='store_true', dest='deploy',
help='Check deployment settings.') help='Check deployment settings.')
parser.add_argument(
'--fail-level',
default='ERROR',
choices=['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG'],
dest='fail_level',
help=(
'Message level that will cause the command to exit with a '
'non-zero status. Default is ERROR.'
),
)
def handle(self, *app_labels, **options): def handle(self, *app_labels, **options):
include_deployment_checks = options['deploy'] include_deployment_checks = options['deploy']
...@@ -49,4 +59,5 @@ class Command(BaseCommand): ...@@ -49,4 +59,5 @@ class Command(BaseCommand):
tags=tags, tags=tags,
display_num_errors=True, display_num_errors=True,
include_deployment_checks=include_deployment_checks, include_deployment_checks=include_deployment_checks,
fail_level=getattr(checks, options['fail_level']),
) )
...@@ -147,6 +147,16 @@ Or you could run it directly on a production or staging deployment to verify ...@@ -147,6 +147,16 @@ Or you could run it directly on a production or staging deployment to verify
that the correct settings are in use (omitting ``--settings``). You could even that the correct settings are in use (omitting ``--settings``). You could even
make it part of your integration test suite. make it part of your integration test suite.
.. django-admin-option:: --fail-level
.. versionadded:: 1.10
Specifies the message level that will cause the command to exit with a non-zero
status. Default is ``ERROR``.
Available levels are: ``CRITICAL``, ``ERROR``, ``WARNING``, ``INFO``, and
``DEBUG``.
compilemessages compilemessages
--------------- ---------------
......
...@@ -150,7 +150,9 @@ Internationalization ...@@ -150,7 +150,9 @@ Internationalization
Management Commands Management Commands
^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^
* ... * The new :djadminopt:`--fail-level` option of the :djadmin:`check` command
allows specifying the message level that will cause the command to exit with
a non-zero status.
Migrations Migrations
^^^^^^^^^^ ^^^^^^^^^^
......
...@@ -116,7 +116,7 @@ def simple_system_check(**kwargs): ...@@ -116,7 +116,7 @@ def simple_system_check(**kwargs):
def tagged_system_check(**kwargs): def tagged_system_check(**kwargs):
tagged_system_check.kwargs = kwargs tagged_system_check.kwargs = kwargs
return [] return [checks.Warning('System Check')]
tagged_system_check.tags = ['simpletag'] tagged_system_check.tags = ['simpletag']
...@@ -192,6 +192,11 @@ class CheckCommandTests(SimpleTestCase): ...@@ -192,6 +192,11 @@ class CheckCommandTests(SimpleTestCase):
call_command('check', deploy=True, tags=['deploymenttag']) call_command('check', deploy=True, tags=['deploymenttag'])
self.assertIn('Deployment Check', sys.stderr.getvalue()) self.assertIn('Deployment Check', sys.stderr.getvalue())
@override_system_checks([tagged_system_check])
def test_fail_level(self):
with self.assertRaises(CommandError):
call_command('check', fail_level='WARNING')
def custom_error_system_check(app_configs, **kwargs): def custom_error_system_check(app_configs, **kwargs):
return [ return [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment