summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMarkus Holtermann <info@markusholtermann.eu>2014-09-23 23:17:00 +0200
committerTim Graham <timograham@gmail.com>2014-09-24 07:21:50 -0400
commitae14c75014379d1cf405509b65eb986c0cb3b0f3 (patch)
tree9ab1904ea23550d54041f326a6944b500bb13703 /tests
parentcc74d8e02e8b659b914859d60002aaa47600f0ff (diff)
[1.7.x] Fixed #23426 -- Don't require double percent sign in RunSQL without parameters
Backport of b9a670b227 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_operations.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py
index f9aa8b12a1..1f5088c38b 100644
--- a/tests/migrations/test_operations.py
+++ b/tests/migrations/test_operations.py
@@ -1156,10 +1156,18 @@ class OperationTests(OperationTestBase):
# Create the operation
operation = migrations.RunSQL(
# Use a multi-line string with a comment to test splitting on SQLite and MySQL respectively
- "CREATE TABLE i_love_ponies (id int, special_thing int);\n"
- "INSERT INTO i_love_ponies (id, special_thing) VALUES (1, 42); -- this is magic!\n"
- "INSERT INTO i_love_ponies (id, special_thing) VALUES (2, 51);\n",
+ "CREATE TABLE i_love_ponies (id int, special_thing varchar(15));\n"
+ "INSERT INTO i_love_ponies (id, special_thing) VALUES (1, 'i love ponies'); -- this is magic!\n"
+ "INSERT INTO i_love_ponies (id, special_thing) VALUES (2, 'i love django');\n"
+ "UPDATE i_love_ponies SET special_thing = 'Ponies' WHERE special_thing LIKE '%%ponies';"
+ "UPDATE i_love_ponies SET special_thing = 'Django' WHERE special_thing LIKE '%django';",
+
+ # Run delete queries to test for parameter substitution failure
+ # reported in #23426
+ "DELETE FROM i_love_ponies WHERE special_thing LIKE '%Django%';"
+ "DELETE FROM i_love_ponies WHERE special_thing LIKE '%%Ponies%%';"
"DROP TABLE i_love_ponies",
+
state_operations=[migrations.CreateModel("SomethingElse", [("id", models.AutoField(primary_key=True))])],
)
self.assertEqual(operation.describe(), "Raw SQL operation")
@@ -1177,6 +1185,10 @@ class OperationTests(OperationTestBase):
with connection.cursor() as cursor:
cursor.execute("SELECT COUNT(*) FROM i_love_ponies")
self.assertEqual(cursor.fetchall()[0][0], 2)
+ cursor.execute("SELECT COUNT(*) FROM i_love_ponies WHERE special_thing = 'Django'")
+ self.assertEqual(cursor.fetchall()[0][0], 1)
+ cursor.execute("SELECT COUNT(*) FROM i_love_ponies WHERE special_thing = 'Ponies'")
+ self.assertEqual(cursor.fetchall()[0][0], 1)
# And test reversal
self.assertTrue(operation.reversible)
with connection.schema_editor() as editor: