summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJunyoung <cupjoo@naver.com>2018-10-01 23:03:10 +0900
committerTim Graham <timograham@gmail.com>2018-10-30 19:29:00 -0400
commitdf448bfd0259edb7df19c9c445ab4ee58624245d (patch)
treee4380afab5ea2fb1161302318855ab1783fe223d /tests
parent817c6cdf0e2a72362045ca503af01830df9b9d36 (diff)
Fixed #29783 -- Added app label validation to showmigrations command.
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_commands.py45
1 files changed, 23 insertions, 22 deletions
diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py
index 816abea65a..63e8615e67 100644
--- a/tests/migrations/test_commands.py
+++ b/tests/migrations/test_commands.py
@@ -381,8 +381,9 @@ class MigrateTests(MigrationTestBase):
@override_settings(INSTALLED_APPS=['migrations.migrations_test_apps.unmigrated_app'])
def test_showmigrations_unmigrated_app(self):
- with self.assertRaisesMessage(CommandError, 'No migrations present for: unmigrated_app'):
- call_command('showmigrations', 'unmigrated_app')
+ out = io.StringIO()
+ call_command('showmigrations', 'unmigrated_app', stdout=out, no_color=True)
+ self.assertEqual('unmigrated_app\n (no migrations)\n', out.getvalue().lower())
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_empty"})
def test_showmigrations_plan_no_migrations(self):
@@ -390,12 +391,12 @@ class MigrateTests(MigrationTestBase):
Tests --plan output of showmigrations command without migrations
"""
out = io.StringIO()
- call_command("showmigrations", format='plan', stdout=out)
- self.assertEqual("", out.getvalue().lower())
+ call_command('showmigrations', format='plan', stdout=out, no_color=True)
+ self.assertEqual('(no migrations)\n', out.getvalue().lower())
out = io.StringIO()
- call_command("showmigrations", format='plan', stdout=out, verbosity=2)
- self.assertEqual("", out.getvalue().lower())
+ call_command('showmigrations', format='plan', stdout=out, verbosity=2, no_color=True)
+ self.assertEqual('(no migrations)\n', out.getvalue().lower())
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_squashed_complex"})
def test_showmigrations_plan_squashed(self):
@@ -522,22 +523,10 @@ class MigrateTests(MigrationTestBase):
)
@override_settings(INSTALLED_APPS=['migrations.migrations_test_apps.unmigrated_app'])
- def test_showmigrations_plan_app_label_error(self):
- """
- `showmigrations --plan app_label` raises an error when no app or
- no migrations are present in provided app labels.
- """
- # App with no migrations.
- with self.assertRaisesMessage(CommandError, 'No migrations present for: unmigrated_app'):
- call_command('showmigrations', 'unmigrated_app', format='plan')
- # Nonexistent app (wrong app label).
- with self.assertRaisesMessage(CommandError, 'No migrations present for: nonexistent_app'):
- call_command('showmigrations', 'nonexistent_app', format='plan')
- # Multiple nonexistent apps; input order shouldn't matter.
- with self.assertRaisesMessage(CommandError, 'No migrations present for: nonexistent_app1, nonexistent_app2'):
- call_command('showmigrations', 'nonexistent_app1', 'nonexistent_app2', format='plan')
- with self.assertRaisesMessage(CommandError, 'No migrations present for: nonexistent_app1, nonexistent_app2'):
- call_command('showmigrations', 'nonexistent_app2', 'nonexistent_app1', format='plan')
+ def test_showmigrations_plan_app_label_no_migrations(self):
+ out = io.StringIO()
+ call_command('showmigrations', 'unmigrated_app', format='plan', stdout=out, no_color=True)
+ self.assertEqual('(no migrations)\n', out.getvalue())
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
def test_sqlmigrate_forwards(self):
@@ -1561,6 +1550,18 @@ class AppLabelErrorTests(TestCase):
with self.assertRaisesMessage(CommandError, self.did_you_mean_auth_error):
call_command('migrate', 'django.contrib.auth')
+ def test_showmigrations_nonexistent_app_label(self):
+ err = io.StringIO()
+ with self.assertRaises(SystemExit):
+ call_command('showmigrations', 'nonexistent_app', stderr=err)
+ self.assertIn(self.nonexistent_app_error, err.getvalue())
+
+ def test_showmigrations_app_name_specified_as_label(self):
+ err = io.StringIO()
+ with self.assertRaises(SystemExit):
+ call_command('showmigrations', 'django.contrib.auth', stderr=err)
+ self.assertIn(self.did_you_mean_auth_error, err.getvalue())
+
def test_sqlmigrate_nonexistent_app_label(self):
with self.assertRaisesMessage(CommandError, self.nonexistent_app_error):
call_command('sqlmigrate', 'nonexistent_app', '0002')