MCPcopy
hub / github.com/django/django / test_last_executed_query

Method test_last_executed_query

tests/backends/tests.py:102–119  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

100 self.assertIsInstance(last_sql, str)
101
102 def test_last_executed_query(self):
103 # last_executed_query() interpolate all parameters, in most cases it is
104 # not equal to QuerySet.query.
105 for qs in (
106 Article.objects.filter(pk=1),
107 Article.objects.filter(pk__in=(1, 2), reporter__pk=3),
108 Article.objects.filter(
109 pk=1,
110 reporter__pk=9,
111 ).exclude(reporter__pk__in=[2, 1]),
112 Article.objects.filter(pk__in=list(range(20, 31))),
113 ):
114 sql, params = qs.query.sql_with_params()
115 with qs.query.get_compiler(DEFAULT_DB_ALIAS).execute_sql(CURSOR) as cursor:
116 self.assertEqual(
117 cursor.db.ops.last_executed_query(cursor, sql, params),
118 str(qs.query),
119 )
120
121 @skipUnlessDBFeature("supports_paramstyle_pyformat")
122 def test_last_executed_query_dict(self):

Callers

nothing calls this directly

Calls 6

excludeMethod · 0.80
sql_with_paramsMethod · 0.80
get_compilerMethod · 0.80
filterMethod · 0.45
execute_sqlMethod · 0.45
last_executed_queryMethod · 0.45

Tested by

no test coverage detected