Refs #32686 -- Added tests for adding a semicolon when collecting SQL for RunSQL.

This commit is contained in:
Hannes Ljungberg 2021-04-27 07:57:34 +02:00 committed by Mariusz Felisiak
parent 4e5bbb6ef2
commit 95754dbc9b
1 changed files with 14 additions and 0 deletions

View File

@ -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