Kaydet (Commit) c3c7d15c authored tarafından Claude Paroz's avatar Claude Paroz Kaydeden (comit) Tim Graham

Refs #29469 -- Reused get_app_config() error message in makemigrations error.

üst abbc9cd7
......@@ -65,23 +65,14 @@ class Command(BaseCommand):
# Make sure the app they asked for exists
app_labels = set(app_labels)
bad_app_labels = set()
has_bad_labels = False
for app_label in app_labels:
try:
apps.get_app_config(app_label)
except LookupError:
bad_app_labels.add(app_label)
if bad_app_labels:
for app_label in bad_app_labels:
if '.' in app_label:
self.stderr.write(
"'%s' is not a valid app label. Did you mean '%s'?" % (
app_label,
app_label.split('.')[-1],
)
)
else:
self.stderr.write("App '%s' could not be found. Is it in INSTALLED_APPS?" % app_label)
except LookupError as err:
self.stderr.write(str(err))
has_bad_labels = True
if has_bad_labels:
sys.exit(2)
# Load the current graph state. Pass in None for the connection so
......
......@@ -1408,20 +1408,20 @@ class AppLabelErrorTests(TestCase):
app. 'django.contrib.auth' must be in INSTALLED_APPS for some of these
tests.
"""
nonexistent_app_error = "No installed app with label 'nonexistent_app'."
did_you_mean_auth_error = (
"No installed app with label 'django.contrib.auth'. Did you mean "
"'auth'?"
)
def test_makemigrations_nonexistent_app_label(self):
err = io.StringIO()
with self.assertRaises(SystemExit):
call_command('makemigrations', 'nonexistent_app', stderr=err)
self.assertIn(
"App 'nonexistent_app' could not be found. Is it in "
"INSTALLED_APPS?", err.getvalue()
)
self.assertIn(self.nonexistent_app_error, err.getvalue())
def test_makemigrations_app_name_specified_as_label(self):
err = io.StringIO()
with self.assertRaises(SystemExit):
call_command('makemigrations', 'django.contrib.auth', stderr=err)
self.assertIn(
"'django.contrib.auth' is not a valid app label. Did you mean 'auth'?",
err.getvalue()
)
self.assertIn(self.did_you_mean_auth_error, err.getvalue())
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