summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2012-06-13 11:36:27 +0200
committerClaude Paroz <claude@2xlibre.net>2012-06-13 12:04:46 +0200
commite9ef9776d186a3379cdbf47a73b14e89b74d0926 (patch)
treeaeda39158b9b1fc8751e74d806e81159d0f3002c /tests
parenta7ef802fa4b48d0c159940d405d83522adb9d4b3 (diff)
Fixed #18461 -- Ensured that last_executed_query returns Unicode
Thanks Anssi Kääriäinen for the review.
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/backends/tests.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py
index 53551fa54d..cf6b964070 100644
--- a/tests/regressiontests/backends/tests.py
+++ b/tests/regressiontests/backends/tests.py
@@ -125,20 +125,14 @@ class DateQuotingTest(TestCase):
classes = models.SchoolClass.objects.filter(last_updated__day=20)
self.assertEqual(len(classes), 1)
-class LastExecutedQueryTest(TestCase):
-
- def setUp(self):
- # connection.queries will not be filled in without this
- settings.DEBUG = True
- def tearDown(self):
- settings.DEBUG = False
-
- # There are no tests for the sqlite backend because it does not
+class LastExecutedQueryTest(TestCase):
+ # There are no escaping tests for the sqlite backend because it does not
# implement paramater escaping. See #14091.
@unittest.skipUnless(connection.vendor in ('oracle', 'postgresql'),
"These backends use the standard parameter escaping rules")
+ @override_settings(DEBUG=True)
def test_parameter_escaping(self):
# check that both numbers and string are properly quoted
list(models.Tag.objects.filter(name="special:\\\"':", object_id=12))
@@ -148,6 +142,7 @@ class LastExecutedQueryTest(TestCase):
@unittest.skipUnless(connection.vendor == 'mysql',
"MySQL uses backslashes to escape parameters.")
+ @override_settings(DEBUG=True)
def test_parameter_escaping(self):
list(models.Tag.objects.filter(name="special:\\\"':", object_id=12))
sql = connection.queries[-1]['sql']
@@ -155,6 +150,17 @@ class LastExecutedQueryTest(TestCase):
self.assertTrue("= 'special:\\\\\\\"\\':' " in sql)
self.assertTrue("= 12 " in sql)
+ def test_query_encoding(self):
+ """
+ Test that last_executed_query() returns an Unicode string
+ """
+ tags = models.Tag.objects.filter(name="й", object_id=12).extra(select={'föö':1})
+ sql, params = tags.query.sql_with_params()
+ cursor = tags.query.get_compiler('default').execute_sql(None)
+ last_sql = cursor.db.ops.last_executed_query(cursor, sql, params)
+ self.assertTrue(isinstance(last_sql, unicode))
+
+
class ParameterHandlingTest(TestCase):
def test_bad_parameter_count(self):
"An executemany call with too many/not enough parameters will raise an exception (Refs #12612)"