Skip to content

Commit

Permalink
Adds 2 tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
BertrandBordage committed Jun 6, 2017
1 parent e3f770c commit 78c4345
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cachalot/tests/read.py
Expand Up @@ -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.
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 78c4345

Please sign in to comment.