Add new options, normalization, and empty result checks in assertQueries().
Review Request #12367 — Created June 14, 2022 and submitted — Latest diff uploaded
This introduces the following new comparison keys in
TestCase.assertQueries()
:
limit
- The value for a SQLLIMIT
offset
- The value for a SQLOFFSET
select_for_update
- Whethermodel.select_for_update(...)
was usedvalues_select
- Any fields passed to.values()
or.value_list()
It also does a few other things to fix and aid in comparisons.
Any values in extra
are now normalized. Whitespace is collapsed and
stripped. Unit tests no longer have to be aware of the exact formatting
of the SQL, which helps for more complex statements.
Queries that are generated but not executed (any that would raise a
EmptyResultSet
) are now skipped for comparison. An example would be a
query on pk__in=[]
, which Django knows makes no sense to pass to the
database. This is a way that code can short-circuit and optimize out an
entire query or a particular clause of the query in Django.
assertQueries()
now ignores it just as Django does.
Made use of these in other unit tests.