summaryrefslogtreecommitdiff
path: root/tests/migrations/test_commands.py
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2020-05-28 09:32:43 +0200
committerGitHub <noreply@github.com>2020-05-28 09:32:43 +0200
commit42de52affe20e399554d984cc7848bf8e0368b41 (patch)
tree0eea7e21dfacabaadf89665e2bc931f440dbc8d4 /tests/migrations/test_commands.py
parent62f1655a64795d055f72e53557fb8404c5430963 (diff)
Fixed isolation of test_migrate_fake_initial.
Diffstat (limited to 'tests/migrations/test_commands.py')
-rw-r--r--tests/migrations/test_commands.py62
1 files changed, 31 insertions, 31 deletions
diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py
index 69fdf28747..50f3ea8965 100644
--- a/tests/migrations/test_commands.py
+++ b/tests/migrations/test_commands.py
@@ -161,37 +161,37 @@ class MigrateTests(MigrationTestBase):
"migrations.0001_initial... faked",
out.getvalue().lower()
)
- # Run migrations all the way
- call_command("migrate", verbosity=0)
- call_command("migrate", verbosity=0, database="other")
- # Make sure the right tables exist
- self.assertTableExists("migrations_author")
- self.assertTableNotExists("migrations_tribble")
- self.assertTableExists("migrations_book")
- self.assertTableNotExists("migrations_author", using="other")
- self.assertTableNotExists("migrations_tribble", using="other")
- self.assertTableNotExists("migrations_book", using="other")
- # Fake a roll-back
- call_command("migrate", "migrations", "zero", fake=True, verbosity=0)
- call_command("migrate", "migrations", "zero", fake=True, verbosity=0, database="other")
- # Make sure the tables still exist
- self.assertTableExists("migrations_author")
- self.assertTableNotExists("migrations_tribble")
- self.assertTableExists("migrations_book")
- # Try to run initial migration
- with self.assertRaises(DatabaseError):
- call_command("migrate", "migrations", verbosity=0)
- # Run initial migration with an explicit --fake-initial
- with self.assertRaises(DatabaseError):
- # Fails because "migrations_tribble" does not exist but needs to in
- # order to make --fake-initial work.
- call_command("migrate", "migrations", fake_initial=True, verbosity=0)
- # Fake an apply
- call_command("migrate", "migrations", fake=True, verbosity=0)
- call_command("migrate", "migrations", fake=True, verbosity=0, database="other")
- # Unmigrate everything
- call_command("migrate", "migrations", "zero", verbosity=0)
- call_command("migrate", "migrations", "zero", verbosity=0, database="other")
+ try:
+ # Run migrations all the way.
+ call_command('migrate', verbosity=0)
+ call_command('migrate', verbosity=0, database="other")
+ self.assertTableExists('migrations_author')
+ self.assertTableNotExists('migrations_tribble')
+ self.assertTableExists('migrations_book')
+ self.assertTableNotExists('migrations_author', using='other')
+ self.assertTableNotExists('migrations_tribble', using='other')
+ self.assertTableNotExists('migrations_book', using='other')
+ # Fake a roll-back.
+ call_command('migrate', 'migrations', 'zero', fake=True, verbosity=0)
+ call_command('migrate', 'migrations', 'zero', fake=True, verbosity=0, database='other')
+ self.assertTableExists('migrations_author')
+ self.assertTableNotExists('migrations_tribble')
+ self.assertTableExists('migrations_book')
+ # Run initial migration.
+ with self.assertRaises(DatabaseError):
+ call_command('migrate', 'migrations', verbosity=0)
+ # Run initial migration with an explicit --fake-initial.
+ with self.assertRaises(DatabaseError):
+ # Fails because "migrations_tribble" does not exist but needs
+ # to in order to make --fake-initial work.
+ call_command('migrate', 'migrations', fake_initial=True, verbosity=0)
+ # Fake an apply.
+ call_command('migrate', 'migrations', fake=True, verbosity=0)
+ call_command('migrate', 'migrations', fake=True, verbosity=0, database='other')
+ finally:
+ # Unmigrate everything.
+ call_command('migrate', 'migrations', 'zero', verbosity=0)
+ call_command('migrate', 'migrations', 'zero', verbosity=0, database='other')
# Make sure it's all gone
for db in self.databases:
self.assertTableNotExists("migrations_author", using=db)