summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMarkus Holtermann <info@markusholtermann.eu>2015-03-29 16:59:35 +0200
committerMarkus Holtermann <info@markusholtermann.eu>2015-03-30 16:31:20 +0200
commitc5cc332bf2a0b3ebfa3ad5d26c5b308de5e505be (patch)
tree58e095966c96de38f50a96ab94386db80d9fa78a /tests
parentdc27f3ee0c3eb9bb17d6cb764788eeaf73a371d7 (diff)
Fixed #24550 -- Added migration operation description to sqlmigrate output
Thanks Tim Graham for the review.
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_commands.py57
1 files changed, 46 insertions, 11 deletions
diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py
index bc289d2f91..7e258b451d 100644
--- a/tests/migrations/test_commands.py
+++ b/tests/migrations/test_commands.py
@@ -289,29 +289,64 @@ class MigrateTests(MigrationTestBase):
)
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
- def test_sqlmigrate(self):
+ def test_sqlmigrate_forwards(self):
"""
Makes sure that sqlmigrate does something.
"""
- # Make sure the output is wrapped in a transaction
out = six.StringIO()
call_command("sqlmigrate", "migrations", "0001", stdout=out)
- output = out.getvalue()
- self.assertIn(connection.ops.start_transaction_sql(), output)
- self.assertIn(connection.ops.end_transaction_sql(), output)
+ output = out.getvalue().lower()
- # Test forwards. All the databases agree on CREATE TABLE, at least.
- out = six.StringIO()
- call_command("sqlmigrate", "migrations", "0001", stdout=out)
- self.assertIn("create table", out.getvalue().lower())
+ index_tx_start = output.find(connection.ops.start_transaction_sql().lower())
+ index_op_desc_author = output.find('-- create model author')
+ index_create_table = output.find('create table')
+ index_op_desc_tribble = output.find('-- create model tribble')
+ index_op_desc_unique_together = output.find('-- alter unique_together')
+ index_tx_end = output.find(connection.ops.end_transaction_sql().lower())
+
+ self.assertGreater(index_tx_start, -1, "Transaction start not found")
+ self.assertGreater(index_op_desc_author, index_tx_start,
+ "Operation description (author) not found or found before transaction start")
+ self.assertGreater(index_create_table, index_op_desc_author,
+ "CREATE TABLE not found or found before operation description (author)")
+ self.assertGreater(index_op_desc_tribble, index_create_table,
+ "Operation description (tribble) not found or found before CREATE TABLE (author)")
+ self.assertGreater(index_op_desc_unique_together, index_op_desc_tribble,
+ "Operation description (unique_together) not found or found before operation description (tribble)")
+ self.assertGreater(index_tx_end, index_op_desc_unique_together,
+ "Transaction end not found or found before operation description (unique_together)")
+ @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
+ def test_sqlmigrate_backwards(self):
+ """
+ Makes sure that sqlmigrate does something.
+ """
# Cannot generate the reverse SQL unless we've applied the migration.
call_command("migrate", "migrations", verbosity=0)
- # And backwards is a DROP TABLE
out = six.StringIO()
call_command("sqlmigrate", "migrations", "0001", stdout=out, backwards=True)
- self.assertIn("drop table", out.getvalue().lower())
+ output = out.getvalue().lower()
+
+ index_tx_start = output.find(connection.ops.start_transaction_sql().lower())
+ index_op_desc_unique_together = output.find('-- alter unique_together')
+ index_op_desc_tribble = output.find('-- create model tribble')
+ index_op_desc_author = output.find('-- create model author')
+ index_drop_table = output.rfind('drop table')
+ index_tx_end = output.find(connection.ops.end_transaction_sql().lower())
+
+ self.assertGreater(index_tx_start, -1, "Transaction start not found")
+ self.assertGreater(index_op_desc_unique_together, index_tx_start,
+ "Operation description (unique_together) not found or found before transaction start")
+ self.assertGreater(index_op_desc_tribble, index_op_desc_unique_together,
+ "Operation description (tribble) not found or found before operation description (unique_together)")
+ self.assertGreater(index_op_desc_author, index_op_desc_tribble,
+ "Operation description (author) not found or found before operation description (tribble)")
+
+ self.assertGreater(index_drop_table, index_op_desc_author,
+ "DROP TABLE not found or found before operation description (author)")
+ self.assertGreater(index_tx_end, index_op_desc_unique_together,
+ "Transaction end not found or found before DROP TABLE")
# Cleanup by unmigrating everything
call_command("migrate", "migrations", "zero", verbosity=0)