summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSebastian Spiegel <sbast@users.noreply.github.com>2016-11-06 13:52:06 +0100
committerTim Graham <timograham@gmail.com>2017-01-06 19:50:31 -0500
commit8b734d2f990063df2988143dfb5f4449b60b9ca3 (patch)
treec35e0418b8e3e2f58cc514d621f4e2c57a5665d8 /tests
parentd976760260c2d8371c1535a7bdeba9a2e0568a34 (diff)
Fixed #27432 -- Made app_label arguments limit showmigrations --plan output.
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_commands.py91
1 files changed, 91 insertions, 0 deletions
diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py
index 3ec3cfed1d..6477873e0d 100644
--- a/tests/migrations/test_commands.py
+++ b/tests/migrations/test_commands.py
@@ -339,6 +339,97 @@ class MigrateTests(MigrationTestBase):
out.getvalue().lower()
)
+ @override_settings(INSTALLED_APPS=[
+ 'migrations.migrations_test_apps.mutate_state_b',
+ 'migrations.migrations_test_apps.alter_fk.author_app',
+ 'migrations.migrations_test_apps.alter_fk.book_app',
+ ])
+ def test_showmigrations_plan_single_app_label(self):
+ """
+ `showmigrations --plan app_label` output with a single app_label.
+ """
+ # Single app with no dependencies on other apps.
+ out = six.StringIO()
+ call_command('showmigrations', 'mutate_state_b', format='plan', stdout=out)
+ self.assertEqual(
+ '[ ] mutate_state_b.0001_initial\n'
+ '[ ] mutate_state_b.0002_add_field\n',
+ out.getvalue()
+ )
+ # Single app with dependencies.
+ out = six.StringIO()
+ call_command('showmigrations', 'author_app', format='plan', stdout=out)
+ self.assertEqual(
+ '[ ] author_app.0001_initial\n'
+ '[ ] book_app.0001_initial\n'
+ '[ ] author_app.0002_alter_id\n',
+ out.getvalue()
+ )
+ # Some migrations already applied.
+ call_command('migrate', 'author_app', '0001', verbosity=0)
+ out = six.StringIO()
+ call_command('showmigrations', 'author_app', format='plan', stdout=out)
+ self.assertEqual(
+ '[X] author_app.0001_initial\n'
+ '[ ] book_app.0001_initial\n'
+ '[ ] author_app.0002_alter_id\n',
+ out.getvalue()
+ )
+ # Cleanup by unmigrating author_app.
+ call_command('migrate', 'author_app', 'zero', verbosity=0)
+
+ @override_settings(INSTALLED_APPS=[
+ 'migrations.migrations_test_apps.mutate_state_b',
+ 'migrations.migrations_test_apps.alter_fk.author_app',
+ 'migrations.migrations_test_apps.alter_fk.book_app',
+ ])
+ def test_showmigrations_plan_multiple_app_labels(self):
+ """
+ `showmigrations --plan app_label` output with multiple app_labels.
+ """
+ # Multiple apps: author_app depends on book_app; mutate_state_b doesn't
+ # depend on other apps.
+ out = six.StringIO()
+ call_command('showmigrations', 'mutate_state_b', 'author_app', format='plan', stdout=out)
+ self.assertEqual(
+ '[ ] author_app.0001_initial\n'
+ '[ ] book_app.0001_initial\n'
+ '[ ] author_app.0002_alter_id\n'
+ '[ ] mutate_state_b.0001_initial\n'
+ '[ ] mutate_state_b.0002_add_field\n',
+ out.getvalue()
+ )
+ # Multiple apps: args order shouldn't matter (the same result is
+ # expected as above).
+ out = six.StringIO()
+ call_command('showmigrations', 'author_app', 'mutate_state_b', format='plan', stdout=out)
+ self.assertEqual(
+ '[ ] author_app.0001_initial\n'
+ '[ ] book_app.0001_initial\n'
+ '[ ] author_app.0002_alter_id\n'
+ '[ ] mutate_state_b.0001_initial\n'
+ '[ ] mutate_state_b.0002_add_field\n',
+ out.getvalue()
+ )
+
+ @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')
+
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
def test_sqlmigrate_forwards(self):
"""