Add testing utilities for building review request Q-expressions.
Review Request #13414 — Created Nov. 14, 2023 and submitted
This introduces several new functions in
reviewboard.reviews.testing.queries.review_requests
for building
expected queries for unit tests:
get_review_requests_accessible_q()
get_review_requests_from_user_q()
get_review_requests_to_group_q()
get_review_requests_to_user_q()
get_review_requests_to_user_directly_q()
get_review_requests_to_user_groups_q()
get_review_requests_to_or_from_user_q()
get_review_requests_accessible_prep_equeries()
get_review_requests_accessible_equeries()
get_review_requests_accessible_from_user_equeries()
get_review_requests_accessible_to_group_equeries()
get_review_requests_accessible_to_user_equeries()
get_review_requests_accessible_to_user_directly_equeries()
get_review_requests_accessible_to_user_groups_equeries()
get_review_requests_accessible_to_or_from_user_equeries()
This covers all the queries used via ReviewRequestManager
, offering
both Q
-expressions (for embedding in other queries, needed for the
datagrids) and standalone queries.
The logic for building Q-expressions is verbose, checking each
combination of states individually and returning complete Q-expressions
as often as possible. Truth tables and comments help document these.
This is built this way in order to ensure we're testing against
fully-known expressions, making it harder to introduce a bug in any
queries.
Unit tests for ReviewRequestManager
have been updated to use these.
There's still work that should be done to make these tests more
comprehensive, but between them, upcoming dashboard unit test changes,
and API tests, we have complete coverage.
As an implementation note, this is also the first change to make use of
the new PEP 692 support for defining **kwargs
arguments using
TypedDict
, helping with the complexity of the number of arguments
these functions all take. With this PEP, a value in the TypedDict
cannot also be present as a standalone argument (to, say, type-narrow
or override a value), and cannot be passed to a function if also
present in kwargs
, so we have to resort to manipulating kwargs
directly. This is a reasonable trade-off in this code, but we'll need
to consider this approach elsewhere on a case-by-case basis.
All unit tests pass.
Summary | ID |
---|---|
cfd9a1e3232cbef3eb39b0a8a9ea03ad01fbe8f2 |
- Change Summary:
-
Fixed an unwanted trailing comma on an import.
- Commits:
-
Summary ID 06124c52ee27e4bcdbd74048c991a553327d1138 d2fd3ccbd8f93fcc7425afa4da9b1e976f7727f1
Checks run (2 succeeded)
- Description:
-
This introduces several new functions in
reviewboard.reviews.testing.queries.review_requests
for building~ Q-expressions for unit tests: ~ expected queries for unit tests: get_review_requests_accessible_q()
get_review_requests_from_user_q()
get_review_requests_to_group_q()
get_review_requests_to_user_q()
get_review_requests_to_user_directly_q()
get_review_requests_to_user_groups_q()
get_review_requests_to_or_from_user_q()
get_review_requests_accessible_prep_equeries()
get_review_requests_accessible_equeries()
get_review_requests_accessible_from_user_equeries()
get_review_requests_accessible_to_group_equeries()
get_review_requests_accessible_to_user_equeries()
get_review_requests_accessible_to_user_directly_equeries()
get_review_requests_accessible_to_user_groups_equeries()
get_review_requests_accessible_to_or_from_user_equeries()
This covers all the queries used via
ReviewRequestManager
, offeringboth Q
-expressions (for embedding in other queries, needed for thedatagrids) and standalone queries. The logic for building Q-expressions is verbose, checking each
combination of states individually and returning complete Q-expressions as often as possible. Truth tables and comments help document these. This is built this way in order to ensure we're testing against fully-known expressions, making it harder to introduce a bug in any queries. Unit tests for
ReviewRequestManager
have been updated to use these.There's still work that should be done to make these tests more comprehensive, but between them, upcoming dashboard unit test changes, and API tests, we have complete coverage. As an implementation note, this is also the first change to make use of
the new PEP 692 support for defining **kwargs
arguments usingTypedDict
, helping with the complexity of the number of argumentsthese functions all take. With this PEP, a value in the TypedDict
cannot also be present as a standalone argument (to, say, type-narrow or override a value), and cannot be passed to a function if also present in kwargs
, so we have to resort to manipulatingkwargs
directly. This is a reasonable trade-off in this code, but we'll need to consider this approach elsewhere on a case-by-case basis.
- Change Summary:
-
- Fixed docs for
get_review_requests_accessible_equeries()
. - Switched arguments from
List[...]
toSequence[...]
.
- Fixed docs for
- Commits:
-
Summary ID d2fd3ccbd8f93fcc7425afa4da9b1e976f7727f1 066eadd679fcbd13a975990cecd3e638b17d16a1
Checks run (2 succeeded)
- Change Summary:
-
Added a missing table join expectation in
get_review_requests_from_user_q()
when passing a user as a string. - Commits:
-
Summary ID 066eadd679fcbd13a975990cecd3e638b17d16a1 b3596dc11e0d36587d8dbb6b871fb702245d15c7
Checks run (2 succeeded)
- Change Summary:
-
- Fixed a typo in the docs.
- Changed the structure of some code to assert in an
else
case, rather than having a separateelse
case raising a `ValueError.
- Commits:
-
Summary ID b3596dc11e0d36587d8dbb6b871fb702245d15c7 cfd9a1e3232cbef3eb39b0a8a9ea03ad01fbe8f2