diff options
author | Arsa <arsalan.ghassemi@gmail.com> | 2021-12-06 16:55:29 +0100 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-12-09 11:16:04 +0100 |
commit | 17df72114e222d63c2af9ed9780583f4cb0689eb (patch) | |
tree | 3c30852ef05c67eb291df8249cbbeb653bb3e6d2 /tests/cache | |
parent | eba9a9b7f72995206af867600d6685b5405f172a (diff) | |
download | django-17df72114e222d63c2af9ed9780583f4cb0689eb.tar.gz |
Fixed #33340 -- Fixed unquoted column names in queries used by DatabaseCache.
Diffstat (limited to 'tests/cache')
-rw-r--r-- | tests/cache/tests.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/tests/cache/tests.py b/tests/cache/tests.py index ddfe9ddfe6..7a98fc4ba1 100644 --- a/tests/cache/tests.py +++ b/tests/cache/tests.py @@ -1113,7 +1113,7 @@ class DBCacheTests(BaseCacheTests, TransactionTestCase): with self.assertNumQueries(1): cache.delete_many(['a', 'b', 'c']) - def test_cull_count_queries(self): + def test_cull_queries(self): old_max_entries = cache._max_entries # Force _cull to delete on first cached record. cache._max_entries = -1 @@ -1124,6 +1124,13 @@ class DBCacheTests(BaseCacheTests, TransactionTestCase): cache._max_entries = old_max_entries num_count_queries = sum('COUNT' in query['sql'] for query in captured_queries) self.assertEqual(num_count_queries, 1) + # Column names are quoted. + for query in captured_queries: + sql = query['sql'] + if 'expires' in sql: + self.assertIn(connection.ops.quote_name('expires'), sql) + if 'cache_key' in sql: + self.assertIn(connection.ops.quote_name('cache_key'), sql) def test_delete_cursor_rowcount(self): """ @@ -1180,6 +1187,15 @@ class DBCacheTests(BaseCacheTests, TransactionTestCase): ) self.assertEqual(out.getvalue(), "Cache table 'test cache table' created.\n") + def test_has_key_query_columns_quoted(self): + with CaptureQueriesContext(connection) as captured_queries: + cache.has_key('key') + self.assertEqual(len(captured_queries), 1) + sql = captured_queries[0]['sql'] + # Column names are quoted. + self.assertIn(connection.ops.quote_name('expires'), sql) + self.assertIn(connection.ops.quote_name('cache_key'), sql) + @override_settings(USE_TZ=True) class DBCacheWithTimeZoneTests(DBCacheTests): |