Skip to content

Add view tests, including testing with OIDC on/off#147

Merged
dwilding merged 8 commits intocanonical:next-releasefrom
evildmp:add-view-tests
Apr 26, 2026
Merged

Add view tests, including testing with OIDC on/off#147
dwilding merged 8 commits intocanonical:next-releasefrom
evildmp:add-view-tests

Conversation

@evildmp
Copy link
Copy Markdown
Collaborator

@evildmp evildmp commented Apr 20, 2026

Based on #146, merge after merging that.

@evildmp evildmp requested a review from dwilding April 20, 2026 03:35
@dwilding dwilding mentioned this pull request Apr 20, 2026
@dwilding dwilding changed the base branch from main to next-release April 20, 2026 04:53
evildmp and others added 3 commits April 25, 2026 10:03
This allows tests in environments that haven't loaded OIDC to continue
running.

See https://docs.pytest.org/en/latest/reference/fixtures.html#conftest-py-sharing-fixtures-across-multiple-files
for notes on shared fixtures.
Updated:

test_toggle_condition_url_patterns (Simplified, and now only checks the
reversed route, rather than the string)

New checks for user permissions:

* test_action_toggle_commitment_denies_user_without_permission
* test_action_toggle_condition_denies_user_without_permission
* test_action_select_reason_denies_user_without_permission

New checks for HTTP methods:

* test_action_toggle_commitment_rejects_non_put_method
* test_action_toggle_condition_rejects_non_put_method
* test_action_select_reason_rejects_non_put_method

New checks for expected results:

new: test_action_toggle_commitment_allows_authorized_put_and_updates_commitment
new: test_action_toggle_condition_allows_authorized_put_and_updates_status
new: test_action_select_reason_allows_authorized_put_and_sets_reason

I used Copilot to help create these tests.
Comment thread dashboard/conftest.py
Comment on lines +7 to +9
# Creat a "fake" mozilla_django_oidc.views so that tests will run,
# even if mozilla_django_oidc is not available at import time for
# tests.
Copy link
Copy Markdown
Collaborator

@dwilding dwilding Apr 25, 2026

Choose a reason for hiding this comment

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

I'm not keen on this approach. mozilla_django_oidc is listed in our application's requirements.txt, so we ought to be able to assume it's available in the venv at runtime and testing time.

Unless you very strongly object, I'm going to remove this shim.

I think it's important that we run tests with a known combination of dependencies, otherwise it reduces the effectiveness of the tests.

If possible, I recommend the Makefile for running tests : make test. But I appreciate that the Makefile isn't set up in an offline-friendly way at the moment. So alternatively, when you're online, this will make sure your venv has everything needed for offline work:

. .venv/bin/activate && pip install -r requirements.txt -r requirements-dev.txt

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Agree. No objections.

@dwilding
Copy link
Copy Markdown
Collaborator

As I was reviewing this PR, I identified a few related improvements, which I've pushed:

  1. projects/test_models.py > test_project_detail_anchor_navigation fails if OIDC is configured because we require login. I changed the test to use a logged-in user.

  2. I added tests in projects/test_views.py to confirm that:

    • Project list is viewable by anyone by default
    • If OIDC is configured, project list is only viewable by logged-in users
    • Project detail pages are viewable by anyone by default
    • If OIDC is configured, project detail pages are only viewable by logged-in users
  3. I expanded our CI so that we do a second run of the tests, this time with OIDC configured. This is to catch incomplete tests like (1) rather than to test OIDC itself.

I also did some general formatting (using ruff) to keep the testing code tidy.

@dwilding dwilding changed the title Add view tests Add view tests, including testing with OIDC on/off Apr 26, 2026
@dwilding dwilding merged commit 5587ab5 into canonical:next-release Apr 26, 2026
5 checks passed
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