Opened 3 weeks ago

Closed 3 weeks ago

#36937 closed Cleanup/optimization (fixed)

Add missing positive test cases for @permission_required in test_client

Reported by: saishmungase Owned by: saishmungase
Component: Testing framework Version: dev
Severity: Normal Keywords: test_client
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

In tests/test_client/tests.py, the test_view_with_permissions and test_view_with_method_permissions methods contain TODO comments indicating missing positive test coverage. The tests successfully verify the negative paths (302 redirects for unauthorized users) but fail to verify the 200 OK path for authorized users.

Upon implementing the positive test cases, it became clear that the dummy views in tests/test_client/views.py were decorated with a malformed permission string ("permission_not_granted"). Because this string lacks a standard app_label.codename format, Django's standard ModelBackend fails to parse it during the has_perm() check. This made it impossible to test standard permission assignment properly without relying on workarounds like the is_superuser flag.

This patch:

  1. Updates the dummy views in tests/test_client/views.py to use a standard, valid permission string ("auth.add_user").
  2. Resolves the TODO comments in tests/test_client/tests.py by assigning the real auth.add_user permission to the test user and asserting the successful 200 OK response.

I have the patch ready and will submit a Pull Request shortly.

Change History (4)

comment:1 by Jacob Walls, 3 weeks ago

Triage Stage: UnreviewedAccepted

comment:3 by Jacob Walls, 3 weeks ago

Triage Stage: AcceptedReady for checkin

comment:4 by Jacob Walls <jacobtylerwalls@…>, 3 weeks ago

Resolution: fixed
Status: assignedclosed

In e85db77e:

Fixed #36937 -- Added missing positive permission cases in test_client tests.

Note: See TracTickets for help on using tickets.
Back to Top