Add new options, normalization, and empty result checks in assertQueries().

Review Request #12367 — Created June 14, 2022 and submitted — Latest diff uploaded

Information

Djblets
release-3.x

Reviewers

This introduces the following new comparison keys in
TestCase.assertQueries():

  • limit - The value for a SQL LIMIT
  • offset - The value for a SQL OFFSET
  • select_for_update - Whether model.select_for_update(...) was used
  • values_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.

Commits

Files