Skip to content

Commit

Permalink
Adding docs how to add a user in a test (#1341)
Browse files Browse the repository at this point in the history
It was not clear how to test endpoints with a user
  • Loading branch information
pinguin999 authored Nov 20, 2024
1 parent ee0f27b commit 63c0c6c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/docs/guides/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,12 @@ It is also possible to specify cookies, both from the TestCase instantiation and
# The request will be made with {"A": "na", "B": "b", "C": "nc"} cookies
response = client.get("/test-cookies", COOKIES={"A": "na", "C": "nc"})
```

### Users
It is also possible to specify a User for the request:
```python
user = User.objects.create(...)
client = TestClient(router)
# The request will be made with user logged in
response = client.get("/test-with-user", user=user)
```

0 comments on commit 63c0c6c

Please sign in to comment.