From 78c4345364b3fd92ab610295538a03bf3ad152a1 Mon Sep 17 00:00:00 2001 From: Bertrand Bordage Date: Tue, 6 Jun 2017 16:14:38 +0200 Subject: [PATCH] Adds 2 tests. --- cachalot/tests/read.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/cachalot/tests/read.py b/cachalot/tests/read.py index 25ae8962e..d10e51632 100644 --- a/cachalot/tests/read.py +++ b/cachalot/tests/read.py @@ -581,6 +581,16 @@ def test_raw(self): self.assertListEqual(data2, data1) self.assertListEqual(data2, [self.t1, self.t2]) + def test_raw_no_table(self): + sql = 'SELECT * FROM (SELECT 1 AS id UNION ALL SELECT 2) AS t;' + + with self.assertNumQueries(1): + data1 = list(Test.objects.raw(sql)) + with self.assertNumQueries(1): + data2 = list(Test.objects.raw(sql)) + self.assertListEqual(data2, data1) + self.assertListEqual(data2, [Test(pk=1), Test(pk=2)]) + def test_cursor_execute_unicode(self): """ Tests if queries executed from a DB cursor are not cached. @@ -630,6 +640,19 @@ def test_cursor_execute_bytes(self): data2, [('é',) + l for l in Test.objects.values_list(*attnames)]) + def test_cursor_execute_no_table(self): + sql = 'SELECT * FROM (SELECT 1 AS id UNION ALL SELECT 2) AS t;' + with self.assertNumQueries(1): + with connection.cursor() as cursor: + cursor.execute(sql) + data1 = list(cursor.fetchall()) + with self.assertNumQueries(1): + with connection.cursor() as cursor: + cursor.execute(sql) + data2 = list(cursor.fetchall()) + self.assertListEqual(data2, data1) + self.assertListEqual(data2, [(1,), (2,)]) + def test_missing_table_cache_key(self): qs = Test.objects.all() self.assert_tables(qs, 'cachalot_test')