Skip to content

Commit

Permalink
Adds tests for cursor.executemany.
Browse files Browse the repository at this point in the history
  • Loading branch information
BertrandBordage committed Dec 7, 2014
1 parent abee1be commit 3293c2c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cachalot/tests/read.py
Expand Up @@ -549,6 +549,23 @@ def test_cursor_execute(self):
self.assertListEqual(data2, data1)
self.assertListEqual(data2, list(Test.objects.values_list()))

def test_cursor_executemany(self):
sql = 'SELECT * FROM %s WHERE name = %%s;' % Test._meta.db_table

param_list = [('test1',)]
with self.assertNumQueries(1):
cursor = connection.cursor()
cursor.executemany(sql, param_list)
data1 = list(cursor.fetchall())
cursor.close()
with self.assertNumQueries(1):
cursor = connection.cursor()
cursor.executemany(sql, param_list)
data2 = list(cursor.fetchall())
cursor.close()
self.assertListEqual(data2, data1)
self.assertListEqual(data2, list(Test.objects.filter(name='test1').values_list()))

def test_missing_table_cache_key(self):
with self.assertNumQueries(1):
list(Test.objects.all())
Expand Down
13 changes: 13 additions & 0 deletions cachalot/tests/write.py
Expand Up @@ -640,6 +640,19 @@ def test_raw_insert(self):
list(Test.objects.values_list('name', flat=True)),
['test1', 'test2'])

with self.assertNumQueries(1):
cursor = connection.cursor()
cursor.executemany(
"INSERT INTO cachalot_test (name, public) "
"VALUES ('test3', %s)", [[1 if self.is_sqlite else 'true']])
cursor.close()

with self.assertNumQueries(1):
self.assertListEqual(
list(Test.objects.values_list('name', flat=True)),
['test1', 'test2', 'test3'])


@skip(NotImplementedError)
def test_raw_update(self):
pass
Expand Down

0 comments on commit 3293c2c

Please sign in to comment.