Skip to content

Commit

Permalink
Add request.user to example (#905)
Browse files Browse the repository at this point in the history
Newcomers get very confused if `request.user` is not set. I think it makes sense to underline this in the example.
  • Loading branch information
guettli committed Mar 18, 2021
1 parent 04134ae commit 11db342
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion docs/helpers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,13 @@ Example

from myapp.views import my_view

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

Expand Down

0 comments on commit 11db342

Please sign in to comment.