Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parametrize test #4729

Merged
merged 3 commits into from
Nov 8, 2024
Merged

Parametrize test #4729

merged 3 commits into from
Nov 8, 2024

Conversation

iaindillingham
Copy link
Member

We parametrize the test to demonstrate that the filter operates on global and local roles. Ideally, the test wouldn't depend on us knowing that OutputPublisher is a global role and ProjectDeveloper is a local role, but making it so would add (arguably unnecessary) complexity. To clarify our intent, we assign descriptive IDs to each parameter set using pytest.param.

@KatieB5 and I parametrized the test when considering #4632. We didn't need to do so to address that issue, but running the test once for a global role and once for a local role has the benefit of documenting how we expect UserList to behave.

We need to create two users to demonstrate that one user was filtered
out. However, the `staff_area_administrator` fixture already creates a
user, so we need only create one more.
@mikerkelly
Copy link
Contributor

We parametrize the test to demonstrate that the filter operates on global and local roles.

It's somewhat surprising that this behavior persists, perhaps enough to warrant a comment in the test. The roles in the view's context only include global roles (as of #4632). Under the current template design, a real user won't normally submit a request with a non-global role. However, the get_queryset() code in the view will still filter by a local role if one is provided in a GET request, and this test demonstrates that.

Ideally, the test wouldn't depend on us knowing that OutputPublisher is a global role and ProjectDeveloper is a local role, but making it so would add (arguably unnecessary) complexity.

This seems fine for this test. I imagine there may be other tests that want a User assigned an arbitrary global or non-global role? I wonder if UserFactory could take an option to generate such a User. This would centralize the dependency somewhat, and it could be tested against GLOBAL_ROLES from #4632.

"role",
[
pytest.param(OutputPublisher, id="global"),
pytest.param(ProjectDeveloper, id="local"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see we use 'local' as an antonym to 'global' for ProjectMembership-based roles vs. User-based roles in a few places. I find this wording a little tough to intuit the meaning of and wonder if "user-based" vs "project-based" might be simpler. Or "global" vs "non-global" or "project" vs "non-project". Hmm.

I'm not suggesting this needs to change here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, we do. And yup, "global" vs "non-global" makes sense; as does "project" vs "non-project". (We also implemented, but don't actually use, OrgMembership-based roles, just to 🤯.)

iaindillingham and others added 2 commits November 8, 2024 17:26
We parametrize the test to demonstrate that the filter operates on
global *and* local roles. Ideally, the test wouldn't depend on us
knowing that `OutputPublisher` is a global role and `ProjectDeveloper`
is a local role, but making it so would add (arguably unnecessary)
complexity. To clarify our intent, we assign descriptive IDs to each
parameter set using `pytest.param`.

Co-authored-by: Mike Kelly <[email protected]>
Pedantically, we group arrange steps into a single paragraph because
paragraphs are meaningful.
@iaindillingham
Copy link
Member Author

I imagine there may be other tests that want a User assigned an arbitrary global or non-global role?

I imagine so, too. Rather than updating UserFactory, we could create a new factory (e.g. UserWithGlobalRoleFactory) and, as you say, centralise the dependency. Thanks for the suggestion.

@iaindillingham iaindillingham merged commit afb4bdb into main Nov 8, 2024
7 checks passed
@iaindillingham iaindillingham deleted the iaindillingham/parametrize-test branch November 8, 2024 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants