[3.1.x] Fixed isolation of test_migrate_fake_initial.

Backport of 42de52affe from master
This commit is contained in:
Mariusz Felisiak 2020-05-28 09:32:43 +02:00
parent bd766ac8bf
commit 15fc360b91
1 changed files with 31 additions and 31 deletions

View File

@ -160,37 +160,37 @@ class MigrateTests(MigrationTestBase):
"migrations.0001_initial... faked", "migrations.0001_initial... faked",
out.getvalue().lower() out.getvalue().lower()
) )
# Run migrations all the way try:
call_command("migrate", verbosity=0) # Run migrations all the way.
call_command("migrate", verbosity=0, database="other") call_command('migrate', verbosity=0)
# Make sure the right tables exist call_command('migrate', verbosity=0, database="other")
self.assertTableExists("migrations_author") self.assertTableExists('migrations_author')
self.assertTableNotExists("migrations_tribble") self.assertTableNotExists('migrations_tribble')
self.assertTableExists("migrations_book") self.assertTableExists('migrations_book')
self.assertTableNotExists("migrations_author", using="other") self.assertTableNotExists('migrations_author', using='other')
self.assertTableNotExists("migrations_tribble", using="other") self.assertTableNotExists('migrations_tribble', using='other')
self.assertTableNotExists("migrations_book", using="other") self.assertTableNotExists('migrations_book', using='other')
# Fake a roll-back # Fake a roll-back.
call_command("migrate", "migrations", "zero", fake=True, verbosity=0) call_command('migrate', 'migrations', 'zero', fake=True, verbosity=0)
call_command("migrate", "migrations", "zero", fake=True, verbosity=0, database="other") call_command('migrate', 'migrations', 'zero', fake=True, verbosity=0, database='other')
# Make sure the tables still exist self.assertTableExists('migrations_author')
self.assertTableExists("migrations_author") self.assertTableNotExists('migrations_tribble')
self.assertTableNotExists("migrations_tribble") self.assertTableExists('migrations_book')
self.assertTableExists("migrations_book") # Run initial migration.
# Try to run initial migration with self.assertRaises(DatabaseError):
with self.assertRaises(DatabaseError): call_command('migrate', 'migrations', verbosity=0)
call_command("migrate", "migrations", verbosity=0) # Run initial migration with an explicit --fake-initial.
# Run initial migration with an explicit --fake-initial with self.assertRaises(DatabaseError):
with self.assertRaises(DatabaseError): # Fails because "migrations_tribble" does not exist but needs
# Fails because "migrations_tribble" does not exist but needs to in # to in order to make --fake-initial work.
# order to make --fake-initial work. call_command('migrate', 'migrations', fake_initial=True, verbosity=0)
call_command("migrate", "migrations", fake_initial=True, verbosity=0) # Fake an apply.
# Fake an apply call_command('migrate', 'migrations', fake=True, verbosity=0)
call_command("migrate", "migrations", fake=True, verbosity=0) call_command('migrate', 'migrations', fake=True, verbosity=0, database='other')
call_command("migrate", "migrations", fake=True, verbosity=0, database="other") finally:
# Unmigrate everything # Unmigrate everything.
call_command("migrate", "migrations", "zero", verbosity=0) call_command('migrate', 'migrations', 'zero', verbosity=0)
call_command("migrate", "migrations", "zero", verbosity=0, database="other") call_command('migrate', 'migrations', 'zero', verbosity=0, database='other')
# Make sure it's all gone # Make sure it's all gone
for db in self.databases: for db in self.databases:
self.assertTableNotExists("migrations_author", using=db) self.assertTableNotExists("migrations_author", using=db)