Fix 4 failing view tests: missing error templates, dispatch routing, BookingEntry validation guard, equipment fixture#23
Merged
Conversation
…, guard BookingEntry.user_id, add equipment fixture Co-authored-by: gb119 <4428426+gb119@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix failing tests for views modules in pytest action
Fix 4 failing view tests: missing error templates, dispatch routing, BookingEntry validation guard, equipment fixture
Mar 3, 2026
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferences |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Four recently added view tests were failing due to cascading issues around missing error templates, incorrect HTTP method handling in error views, unguarded model field access during form validation, and missing test fixtures.
Root Causes & Fixes
Missing error templates (
test_new_cost_centre_dialog_requires_superuser)E403Viewreferencederrors/403View.htmlwhich didn't exist, cascading toE500Viewreferencingerrors/500View.html— also missing. Created all four templates:400View.html,403View.html,404View.html,500View.html.ErrorViewreturns 405 for non-GET requests (test_toggle_account_active_requires_superuser)ErrorViewinheritsTemplateViewwhich only handles GET. A POST to a superuser-only endpoint raisedPermissionDenied→E403Viewcalled withPOST→ 405 instead of 403. Fixed by overridingdispatch()onErrorViewto route all methods toget().RelatedObjectDoesNotExistescaping form validation (test_cost_centre_filter_view_returns_200_via_htmx)BookinngDialogForm(empty_querydict).is_valid()triggeredBookingEntry.clean()→fix_project()accessedself.userwhenuser_idisNone, raisingRelatedObjectDoesNotExistoutside Django'sValidationErrorcatch in_post_clean(). Added early-exit guards:Missing
equipmentfixture (test_all_calendar_view_returns_200)AllCalendarViewsetscontext["equipment"] = Equipment.objects.first(). With no equipment in the test DB this isNone, and the template's{% url 'equipment:equipment_detail' equipment.pk %}raisesNoReverseMatch. Added theequipmentfixture to the test.🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.