summaryrefslogtreecommitdiff
path: root/tests/migrations
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2023-03-04 13:09:38 +0100
committerGitHub <noreply@github.com>2023-03-04 13:09:38 +0100
commit61f599aeb991095baa510225a4adeee91d0d43cc (patch)
treedc2282082077f241ae07672ef3d39186f358eda4 /tests/migrations
parent868e2fcddae6720d5713924a785339d1665f1bb9 (diff)
downloaddjango-61f599aeb991095baa510225a4adeee91d0d43cc.tar.gz
Refs #34381 -- Fixed isolation of MigrateTests.test_migrate_fake_initial().
Diffstat (limited to 'tests/migrations')
-rw-r--r--tests/migrations/test_commands.py78
1 files changed, 42 insertions, 36 deletions
diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py
index 0117d1e4aa..b1c91bcf5c 100644
--- a/tests/migrations/test_commands.py
+++ b/tests/migrations/test_commands.py
@@ -173,50 +173,56 @@ class MigrateTests(MigrationTestBase):
for db in self.databases:
self.assertTableNotExists("migrations_author", using=db)
self.assertTableNotExists("migrations_tribble", using=db)
- # Run the migrations to 0001 only
- call_command("migrate", "migrations", "0001", verbosity=0)
- call_command("migrate", "migrations", "0001", verbosity=0, database="other")
- # Make sure the right tables exist
- self.assertTableExists("migrations_author")
- self.assertTableNotExists("migrations_tribble")
- # Also check the "other" database
- self.assertTableNotExists("migrations_author", using="other")
- self.assertTableExists("migrations_tribble", 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.assertTableExists("migrations_tribble", using="other")
- # Try to run initial migration
- with self.assertRaises(DatabaseError):
+ try:
+ # Run the migrations to 0001 only
call_command("migrate", "migrations", "0001", verbosity=0)
- # Run initial migration with an explicit --fake-initial
- out = io.StringIO()
- with mock.patch(
- "django.core.management.color.supports_color", lambda *args: False
- ):
- call_command(
- "migrate",
- "migrations",
- "0001",
- fake_initial=True,
- stdout=out,
- verbosity=1,
- )
+ call_command("migrate", "migrations", "0001", verbosity=0, database="other")
+ # Make sure the right tables exist
+ self.assertTableExists("migrations_author")
+ self.assertTableNotExists("migrations_tribble")
+ # Also check the "other" database
+ self.assertTableNotExists("migrations_author", using="other")
+ self.assertTableExists("migrations_tribble", using="other")
+ # Fake a roll-back
+ call_command("migrate", "migrations", "zero", fake=True, verbosity=0)
call_command(
"migrate",
"migrations",
- "0001",
- fake_initial=True,
+ "zero",
+ fake=True,
verbosity=0,
database="other",
)
- self.assertIn("migrations.0001_initial... faked", out.getvalue().lower())
- try:
+ # Make sure the tables still exist
+ self.assertTableExists("migrations_author")
+ self.assertTableExists("migrations_tribble", using="other")
+ # Try to run initial migration
+ with self.assertRaises(DatabaseError):
+ call_command("migrate", "migrations", "0001", verbosity=0)
+ # Run initial migration with an explicit --fake-initial
+ out = io.StringIO()
+ with mock.patch(
+ "django.core.management.color.supports_color", lambda *args: False
+ ):
+ call_command(
+ "migrate",
+ "migrations",
+ "0001",
+ fake_initial=True,
+ stdout=out,
+ verbosity=1,
+ )
+ call_command(
+ "migrate",
+ "migrations",
+ "0001",
+ fake_initial=True,
+ verbosity=0,
+ database="other",
+ )
+ self.assertIn("migrations.0001_initial... faked", out.getvalue().lower())
+
# Run migrations all the way.
call_command("migrate", verbosity=0)
call_command("migrate", verbosity=0, database="other")