Add expected queries and enhance tests for Group access queries.

Review Request #13406 — Created Nov. 7, 2023 and submitted — Latest diff uploaded

Information

Review Board
release-5.0.x

Reviewers

This introduces the reviewboard.reviews.testing.queries.review_groups
module for query-building functions for tests. It contains the following
methods:

  • get_review_groups_accessible_q()
  • get_review_groups_accessible_prep_equeries()
  • get_review_groups_accessible_equeries()
  • get_review_groups_accessible_ids_equeries()

These generate expected Q objects and queries that matches calls to
Group.objects.accessible() and Group.objects.accessible_ids().
They're written in a verbose manner that ensures we only ever test
against finalized Q expressions, to minimize chances of regressions or
unexpected behavior.

The unit tests for .accessible() and .accessible_ids() have been
completely rewritten. They now check against these expected queries, but
they've also been expanded considerably to more thoroughly check access
with positive and negative test data, to better catch regressions. The
approach being used here will be carried over to other accessibility
tests for the next batch of this peformance work.

Unit tests pass.

Diff Revision 2

This is not the most recent revision of the diff. The latest diff is revision 6. See what's changed.

orig
1
2
3
4
5
6

Commits

First Last Summary ID Author
Add expected queries and enhance tests for Group.objects.accessible_ids().
This introduces a new `reviewboard.reviews.testing.queries` module that contains the first utility function for building expected queries for unit tests: `get_review_groups_accessible_ids_equeries()`. This function generates expected queries that matches calls to `Group.objects.accessible_ids()`. This will be the first of many. This function very intently does not copy the `Q`-building logic of `accessible_ids()`, instead opting to have explicit conditionals that all result in fully-formed `Q` expressions to check against. This will likely get more complex in time. The unit tests for `accessible_ids()` have been updated to test for queries, and to broaden the test suite. Previously, we had test functions that tested multiple conditions at once, but this led to caching that would interfere with query expectations. These have now been split into individual test functions, which have themselves been extended to also incorporate Local Sites into the checks.
2c7bde47ac8de8081d81d8a68a3720282f1a97d7 Christian Hammond
reviewboard/reviews/managers.py
reviewboard/reviews/testing/__init__.py
reviewboard/reviews/testing/queries.py
reviewboard/reviews/tests/test_review_group_manager.py
Loading...