(self)
| 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): |
nothing calls this directly
no test coverage detected