mirror of
https://github.com/django/django.git
synced 2024-11-21 19:09:18 +01:00
Fixed #35689 -- Handled custom labels in LabelCommand.missing_args_message.
This commit is contained in:
parent
47b921391f
commit
f72bbd4480
@ -672,7 +672,13 @@ class LabelCommand(BaseCommand):
|
||||
"""
|
||||
|
||||
label = "label"
|
||||
missing_args_message = "Enter at least one %s." % label
|
||||
missing_args_message = "Enter at least one %s."
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
if self.missing_args_message == LabelCommand.missing_args_message:
|
||||
self.missing_args_message = self.missing_args_message % self.label
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument("args", metavar=self.label, nargs="+")
|
||||
|
@ -25,6 +25,7 @@ from django.core.management import (
|
||||
color,
|
||||
execute_from_command_line,
|
||||
)
|
||||
from django.core.management.base import LabelCommand
|
||||
from django.core.management.commands.loaddata import Command as LoaddataCommand
|
||||
from django.core.management.commands.runserver import Command as RunserverCommand
|
||||
from django.core.management.commands.testserver import Command as TestserverCommand
|
||||
@ -2280,6 +2281,20 @@ class CommandTypes(AdminScriptTestCase):
|
||||
"('settings', None), ('traceback', False), ('verbosity', 1)]",
|
||||
)
|
||||
|
||||
def test_custom_label_command_custom_missing_args_message(self):
|
||||
class Command(LabelCommand):
|
||||
missing_args_message = "Missing argument."
|
||||
|
||||
with self.assertRaisesMessage(CommandError, "Error: Missing argument."):
|
||||
call_command(Command())
|
||||
|
||||
def test_custom_label_command_none_missing_args_message(self):
|
||||
class Command(LabelCommand):
|
||||
missing_args_message = None
|
||||
|
||||
with self.assertRaisesMessage(CommandError, ""):
|
||||
call_command(Command())
|
||||
|
||||
def test_suppress_base_options_command_help(self):
|
||||
args = ["suppress_base_options_command", "--help"]
|
||||
out, err = self.run_manage(args)
|
||||
|
@ -124,6 +124,11 @@ class TestFindStatic(TestDefaults, CollectionTestCase):
|
||||
searched_locations,
|
||||
)
|
||||
|
||||
def test_missing_args_message(self):
|
||||
msg = "Enter at least one staticfile."
|
||||
with self.assertRaisesMessage(CommandError, msg):
|
||||
call_command("findstatic")
|
||||
|
||||
|
||||
class TestConfiguration(StaticFilesTestCase):
|
||||
def test_location_empty(self):
|
||||
|
Loading…
Reference in New Issue
Block a user