Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixes #21115 -- Fixes NameError in migrate --list command #1637

Closed
wants to merge 1 commit into from

3 participants

@timgraham timgraham commented on the diff
tests/migrations/test_commands.py
((7 lines not shown))
+ """
+ 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())
+
@timgraham Owner

extra newline.

also, commit message should be in past tense "Fixed #...."

@MarkusH Collaborator
MarkusH added a note

Changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@timgraham
Owner

Looks like the test failures were due to the migration tables not being cleaned up -- presumably the tests executed in different orders on our systems. Added the following to the end of the new test to fix it:

call_command("migrate", "migrations", "zero", verbosity=0)

@andrewgodwin I'm guessing there might be a separate fix needed to make this sort of thing unnecessary?

merged in a772ea8.

@timgraham timgraham closed this
@andrewgodwin

@timgraham Unfortunately it has to be cleaned up manually (or in a tearDown, like in the schema tests) as migrations have to run outside transaction management. Adding that to the end is as good as a solution as I could suggest.

@MarkusH MarkusH deleted the MarkusH:ticket21115 branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  django/core/management/commands/migrate.py
@@ -264,7 +264,7 @@ def show_migration_list(self, connection, apps=None):
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)))
View
20 tests/migrations/test_commands.py
@@ -49,6 +49,26 @@ def test_migrate(self):
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())
+
@timgraham Owner

extra newline.

also, commit message should be in past tense "Fixed #...."

@MarkusH Collaborator
MarkusH added a note

Changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
def test_sqlmigrate(self):
"""
Makes sure that sqlmigrate does something.
Something went wrong with that request. Please try again.