[Django] #36937: Add missing positive test cases for @permission_required in test_client

0 views
Skip to first unread message

Django

unread,
Feb 19, 2026, 10:05:36 AMFeb 19
to django-...@googlegroups.com
#36937: Add missing positive test cases for @permission_required in test_client
-------------------------------------+-------------------------------------
Reporter: | Owner: saishmungase
saishmungase |
Type: | Status: assigned
Cleanup/optimization |
Component: Testing | Version: dev
framework |
Severity: Normal | Keywords: test_client
Triage Stage: | Has patch: 1
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/36937>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 19, 2026, 10:22:17 AMFeb 19
to django-...@googlegroups.com
#36937: Add missing positive test cases for @permission_required in test_client
-------------------------------------+-------------------------------------
Reporter: saishmungase | Owner:
Type: | saishmungase
Cleanup/optimization | Status: assigned
Component: Testing framework | Version: dev
Severity: Normal | Resolution:
Keywords: test_client | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* stage: Unreviewed => Accepted

--
Ticket URL: <https://code.djangoproject.com/ticket/36937#comment:1>

Django

unread,
Feb 19, 2026, 12:59:30 PMFeb 19
to django-...@googlegroups.com
#36937: Add missing positive test cases for @permission_required in test_client
-------------------------------------+-------------------------------------
Reporter: saishmungase | Owner:
Type: | saishmungase
Cleanup/optimization | Status: assigned
Component: Testing framework | Version: dev
Severity: Normal | Resolution:
Keywords: test_client | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by saishmungase):

https://github.com/django/django/pull/20733
--
Ticket URL: <https://code.djangoproject.com/ticket/36937#comment:2>

Django

unread,
Feb 21, 2026, 9:45:05 AM (13 days ago) Feb 21
to django-...@googlegroups.com
#36937: Add missing positive test cases for @permission_required in test_client
-------------------------------------+-------------------------------------
Reporter: saishmungase | Owner:
Type: | saishmungase
Cleanup/optimization | Status: assigned
Component: Testing framework | Version: dev
Severity: Normal | Resolution:
Keywords: test_client | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/36937#comment:3>

Django

unread,
Feb 21, 2026, 9:52:48 AM (13 days ago) Feb 21
to django-...@googlegroups.com
#36937: Add missing positive test cases for @permission_required in test_client
-------------------------------------+-------------------------------------
Reporter: saishmungase | Owner:
Type: | saishmungase
Cleanup/optimization | Status: closed
Component: Testing framework | Version: dev
Severity: Normal | Resolution: fixed
Keywords: test_client | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls <jacobtylerwalls@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"e85db77e11e37d6ec82526557c4dafe4b30dc699" e85db77e]:
{{{#!CommitTicketReference repository=""
revision="e85db77e11e37d6ec82526557c4dafe4b30dc699"
Fixed #36937 -- Added missing positive permission cases in test_client
tests.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36937#comment:4>
Reply all
Reply to author
Forward
0 new messages