From a772ea8117c42a0027c79212a572f87614bb7173 Mon Sep 17 00:00:00 2001 From: Markus Holtermann Date: Tue, 17 Sep 2013 11:54:55 +0200 Subject: [PATCH] Fixed #21115 -- Fixed NameError in migrate --list command --- django/core/management/commands/migrate.py | 2 +- tests/migrations/test_commands.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/django/core/management/commands/migrate.py b/django/core/management/commands/migrate.py index ba51dd87ff..aa74c9c9c3 100644 --- a/django/core/management/commands/migrate.py +++ b/django/core/management/commands/migrate.py @@ -264,7 +264,7 @@ class Command(BaseCommand): if apps: invalid_apps = [] for app in apps: - if app_label not in loader.migrated_apps: + if app not in loader.migrated_apps: invalid_apps.append(app) if invalid_apps: raise CommandError("No migrations present for: %s" % (", ".join(invalid_apps))) diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py index 93c871988e..01d11e2c0c 100644 --- a/tests/migrations/test_commands.py +++ b/tests/migrations/test_commands.py @@ -48,6 +48,28 @@ class MigrateTests(MigrationTestBase): self.assertTableNotExists("migrations_tribble") self.assertTableNotExists("migrations_book") + @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"}) + def test_migrate_list(self): + """ + Tests --list output of migrate command + """ + stdout = six.StringIO() + call_command("migrate", list=True, stdout=stdout, verbosity=0) + self.assertIn("migrations", stdout.getvalue().lower()) + self.assertIn("[ ] 0001_initial", stdout.getvalue().lower()) + self.assertIn("[ ] 0002_second", stdout.getvalue().lower()) + + call_command("migrate", "migrations", "0001", verbosity=0) + + stdout = six.StringIO() + # Giving the explicit app_label tests for selective `show_migration_list` in the command + call_command("migrate", "migrations", list=True, stdout=stdout, verbosity=0) + self.assertIn("migrations", stdout.getvalue().lower()) + self.assertIn("[x] 0001_initial", stdout.getvalue().lower()) + self.assertIn("[ ] 0002_second", stdout.getvalue().lower()) + # Cleanup by unmigrating everything + call_command("migrate", "migrations", "zero", verbosity=0) + @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"}) def test_sqlmigrate(self): """