summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHannes Ljungberg <hannes.ljungberg@gmail.com>2021-04-27 07:57:34 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-04-27 07:59:41 +0200
commit95754dbc9b9479787e422f32b028493a4d2a6ec1 (patch)
tree3548eadc251e67c76202bea1ac506c2637d36cef
parent4e5bbb6ef2287126badd32842b239f4a8a7394ca (diff)
Refs #32686 -- Added tests for adding a semicolon when collecting SQL for RunSQL.
-rw-r--r--tests/migrations/test_operations.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py
index cbd65bdb37..3070aece2b 100644
--- a/tests/migrations/test_operations.py
+++ b/tests/migrations/test_operations.py
@@ -3003,6 +3003,20 @@ class OperationTests(OperationTestBase):
operation.database_forwards("test_runsql", editor, None, None)
operation.database_backwards("test_runsql", editor, None, None)
+ def test_run_sql_add_missing_semicolon_on_collect_sql(self):
+ project_state = self.set_up_test_model('test_runsql')
+ new_state = project_state.clone()
+ tests = [
+ 'INSERT INTO test_runsql_pony (pink, weight) VALUES (1, 1)\n',
+ ]
+ for sql in tests:
+ with self.subTest(sql=sql):
+ operation = migrations.RunSQL(sql, migrations.RunPython.noop)
+ with connection.schema_editor(collect_sql=True) as editor:
+ operation.database_forwards('test_runsql', editor, project_state, new_state)
+ collected_sql = '\n'.join(editor.collected_sql)
+ self.assertEqual(collected_sql.count(';'), 1)
+
def test_run_python(self):
"""
Tests the RunPython operation