Add view tests, including testing with OIDC on/off#147
Add view tests, including testing with OIDC on/off#147dwilding merged 8 commits intocanonical:next-releasefrom
Conversation
3a8a10d to
8e537f8
Compare
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.
8e537f8 to
c9aae5f
Compare
| # 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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Agree. No objections.
|
As I was reviewing this PR, I identified a few related improvements, which I've pushed:
I also did some general formatting (using ruff) to keep the testing code tidy. |
Based on #146, merge after merging that.