Skip to content

Commit 11db342

Browse files
authored
Add request.user to example (#905)
Newcomers get very confused if `request.user` is not set. I think it makes sense to underline this in the example.
1 parent 04134ae commit 11db342

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

docs/helpers.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,13 @@ Example
130130

131131
from myapp.views import my_view
132132

133-
def test_details(rf):
133+
def test_details(rf, admin):
134134
request = rf.get('/customer/details')
135+
# Remember that when using RequestFactory, the request does not pass
136+
# through middleware. If your view expects fields such as request.user
137+
# to be set, you need to set them explicitly.
138+
# The following line sets request.user to an admin user.
139+
request.user = admin
135140
response = my_view(request)
136141
assert response.status_code == 200
137142

0 commit comments

Comments
 (0)