diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2015-09-13 09:30:35 +0200 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2015-09-17 23:01:33 +0200 |
| commit | 4f6a7663bcddffb114f2647f9928cbf1fdd8e4b5 (patch) | |
| tree | 648c2ae602182f4ae41095ddd40a8515cf5a1ced /tests | |
| parent | fc8a6a9b002aef90ff68f3d95e560db1ea728c76 (diff) | |
Refs #14091 -- Fixed connection.queries on SQLite.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/backends/tests.py | 16 | ||||
| -rw-r--r-- | tests/test_runner/test_debug_sql.py | 48 |
2 files changed, 25 insertions, 39 deletions
diff --git a/tests/backends/tests.py b/tests/backends/tests.py index b7b8c9cade..39a2654a77 100644 --- a/tests/backends/tests.py +++ b/tests/backends/tests.py @@ -26,7 +26,6 @@ from django.test import ( SimpleTestCase, TestCase, TransactionTestCase, mock, override_settings, skipIfDBFeature, skipUnlessDBFeature, ) -from django.test.utils import str_prefix from django.utils import six from django.utils.six.moves import range @@ -388,8 +387,19 @@ class LastExecutedQueryTest(TestCase): # This shouldn't raise an exception query = "SELECT strftime('%Y', 'now');" connection.cursor().execute(query) - self.assertEqual(connection.queries[-1]['sql'], - str_prefix("QUERY = %(_)s\"SELECT strftime('%%Y', 'now');\" - PARAMS = ()")) + self.assertEqual(connection.queries[-1]['sql'], query) + + @unittest.skipUnless(connection.vendor == 'sqlite', + "This test is specific to SQLite.") + def test_parameter_quoting_on_sqlite(self): + # The implementation of last_executed_queries isn't optimal. It's + # worth testing that parameters are quoted. See #14091. + query = "SELECT %s" + params = ["\"'\\"] + connection.cursor().execute(query, params) + # Note that the single quote is repeated + substituted = "SELECT '\"''\\'" + self.assertEqual(connection.queries[-1]['sql'], substituted) class ParameterHandlingTest(TestCase): diff --git a/tests/test_runner/test_debug_sql.py b/tests/test_runner/test_debug_sql.py index b943e83e31..e230066100 100644 --- a/tests/test_runner/test_debug_sql.py +++ b/tests/test_runner/test_debug_sql.py @@ -61,28 +61,14 @@ class TestDebugSQL(unittest.TestCase): for output in self.verbose_expected_outputs: self.assertIn(output, full_output) - if six.PY3: - expected_outputs = [ - ('''QUERY = 'SELECT COUNT(*) AS "__count" ''' - '''FROM "test_runner_person" WHERE ''' - '''"test_runner_person"."first_name" = %s' ''' - '''- PARAMS = ('error',);'''), - ('''QUERY = 'SELECT COUNT(*) AS "__count" ''' - '''FROM "test_runner_person" WHERE ''' - '''"test_runner_person"."first_name" = %s' ''' - '''- PARAMS = ('fail',);'''), - ] - else: - expected_outputs = [ - ('''QUERY = u'SELECT COUNT(*) AS "__count" ''' - '''FROM "test_runner_person" WHERE ''' - '''"test_runner_person"."first_name" = %s' ''' - '''- PARAMS = (u'error',);'''), - ('''QUERY = u'SELECT COUNT(*) AS "__count" ''' - '''FROM "test_runner_person" WHERE ''' - '''"test_runner_person"."first_name" = %s' ''' - '''- PARAMS = (u'fail',);'''), - ] + expected_outputs = [ + ('''SELECT COUNT(*) AS "__count" ''' + '''FROM "test_runner_person" WHERE ''' + '''"test_runner_person"."first_name" = 'error';'''), + ('''SELECT COUNT(*) AS "__count" ''' + '''FROM "test_runner_person" WHERE ''' + '''"test_runner_person"."first_name" = 'fail';'''), + ] verbose_expected_outputs = [ # Output format changed in Python 3.5+ @@ -91,18 +77,8 @@ class TestDebugSQL(unittest.TestCase): 'runTest (test_runner.test_debug_sql.{}ErrorTest) ... ERROR', 'runTest (test_runner.test_debug_sql.{}PassingTest) ... ok', ] + ] + [ + ('''SELECT COUNT(*) AS "__count" ''' + '''FROM "test_runner_person" WHERE ''' + '''"test_runner_person"."first_name" = 'pass';'''), ] - if six.PY3: - verbose_expected_outputs += [ - ('''QUERY = 'SELECT COUNT(*) AS "__count" ''' - '''FROM "test_runner_person" WHERE ''' - '''"test_runner_person"."first_name" = %s' ''' - '''- PARAMS = ('pass',);'''), - ] - else: - verbose_expected_outputs += [ - ('''QUERY = u'SELECT COUNT(*) AS "__count" ''' - '''FROM "test_runner_person" WHERE ''' - '''"test_runner_person"."first_name" = %s' ''' - '''- PARAMS = (u'pass',);'''), - ] |
