Added tests for queries log in CursorDebugWrapper.executemany().
This commit is contained in:
parent
0dd2308cf6
commit
ed880d92b5
|
@ -429,18 +429,32 @@ class BackendTestCase(TransactionTestCase):
|
|||
"""
|
||||
Test the documented API of connection.queries.
|
||||
"""
|
||||
sql = 'SELECT 1' + connection.features.bare_select_suffix
|
||||
with connection.cursor() as cursor:
|
||||
reset_queries()
|
||||
cursor.execute("SELECT 1" + connection.features.bare_select_suffix)
|
||||
cursor.execute(sql)
|
||||
self.assertEqual(1, len(connection.queries))
|
||||
|
||||
self.assertIsInstance(connection.queries, list)
|
||||
self.assertIsInstance(connection.queries[0], dict)
|
||||
self.assertCountEqual(connection.queries[0], ['sql', 'time'])
|
||||
self.assertEqual(list(connection.queries[0]), ['sql', 'time'])
|
||||
self.assertEqual(connection.queries[0]['sql'], sql)
|
||||
|
||||
reset_queries()
|
||||
self.assertEqual(0, len(connection.queries))
|
||||
|
||||
sql = ('INSERT INTO %s (%s, %s) VALUES (%%s, %%s)' % (
|
||||
connection.introspection.identifier_converter('backends_square'),
|
||||
connection.ops.quote_name('root'),
|
||||
connection.ops.quote_name('square'),
|
||||
))
|
||||
with connection.cursor() as cursor:
|
||||
cursor.executemany(sql, [(1, 1), (2, 4)])
|
||||
self.assertEqual(1, len(connection.queries))
|
||||
self.assertIsInstance(connection.queries, list)
|
||||
self.assertIsInstance(connection.queries[0], dict)
|
||||
self.assertEqual(list(connection.queries[0]), ['sql', 'time'])
|
||||
self.assertEqual(connection.queries[0]['sql'], '2 times: %s' % sql)
|
||||
|
||||
# Unfortunately with sqlite3 the in-memory test database cannot be closed.
|
||||
@skipUnlessDBFeature('test_db_allows_multiple_connections')
|
||||
@override_settings(DEBUG=True)
|
||||
|
|
Loading…
Reference in New Issue