Skip to content

Fix 4 failing view tests: missing error templates, dispatch routing, BookingEntry validation guard, equipment fixture#23

Merged
gb119 merged 2 commits into
mainfrom
copilot/fix-failing-view-tests
Mar 3, 2026
Merged

Fix 4 failing view tests: missing error templates, dispatch routing, BookingEntry validation guard, equipment fixture#23
gb119 merged 2 commits into
mainfrom
copilot/fix-failing-view-tests

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 3, 2026

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)

E403View referenced errors/403View.html which didn't exist, cascading to E500View referencing errors/500View.html — also missing. Created all four templates: 400View.html, 403View.html, 404View.html, 500View.html.

ErrorView returns 405 for non-GET requests (test_toggle_account_active_requires_superuser)

ErrorView inherits TemplateView which only handles GET. A POST to a superuser-only endpoint raised PermissionDeniedE403View called with POST → 405 instead of 403. Fixed by overriding dispatch() on ErrorView to route all methods to get().

def dispatch(self, request, *args, **kwargs):
    return self.get(request, *args, **kwargs)

RelatedObjectDoesNotExist escaping form validation (test_cost_centre_filter_view_returns_200_via_htmx)

BookinngDialogForm(empty_querydict).is_valid() triggered BookingEntry.clean()fix_project() accessed self.user when user_id is None, raising RelatedObjectDoesNotExist outside Django's ValidationError catch in _post_clean(). Added early-exit guards:

# fix_project()
if not self.user_id:
    return None

# clean()
elif self.user_id and self.user and self.user.username == "service":

Missing equipment fixture (test_all_calendar_view_returns_200)

AllCalendarView sets context["equipment"] = Equipment.objects.first(). With no equipment in the test DB this is None, and the template's {% url 'equipment:equipment_detail' equipment.pk %} raises NoReverseMatch. Added the equipment fixture 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.

…, 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
Copilot finished work on behalf of gb119 March 3, 2026 14:05
@codacy-production
Copy link
Copy Markdown

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.20% (target: -1.00%) 100.00%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (ac49dd1) 4845 3042 62.79%
Head commit (c3cde96) 4847 (+2) 3053 (+11) 62.99% (+0.20%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#23) 4 4 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

@gb119 gb119 marked this pull request as ready for review March 3, 2026 15:17
@gb119 gb119 merged commit b090336 into main Mar 3, 2026
4 checks passed
@gb119 gb119 deleted the copilot/fix-failing-view-tests branch March 3, 2026 15:18
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