-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a87af1
commit b15cd52
Showing
1 changed file
with
12 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,27 +81,32 @@ def test_credentials(self): | |
response = self.client.get('/view/') | ||
assert response.data['auth'] == 'example' | ||
|
||
def test_force_authenticate(self): | ||
""" | ||
Setting `.force_authenticate()` forcibly authenticates each request. | ||
""" | ||
# User only | ||
def test_force_authenticate_with_user(self): | ||
user = User.objects.create_user('example', '[email protected]') | ||
|
||
self.client.force_authenticate(user=user) | ||
response = self.client.get('/view/') | ||
|
||
assert response.data['user'] == 'example' | ||
assert 'token' not in response.data | ||
|
||
# Token only | ||
def test_force_authenticate_with_token(self): | ||
user = User.objects.create_user('example', '[email protected]') | ||
token = Token.objects.create(key='xyz', user=user) | ||
|
||
self.client.force_authenticate(token=token) | ||
response = self.client.get('/view/') | ||
|
||
assert response.data['token'] == 'xyz' | ||
assert 'user' not in response.data | ||
|
||
# User and token | ||
def test_force_authenticate_with_user_and_token(self): | ||
user = User.objects.create_user('example', '[email protected]') | ||
token = Token.objects.create(key='xyz', user=user) | ||
|
||
self.client.force_authenticate(user=user, token=token) | ||
response = self.client.get('/view/') | ||
|
||
assert response.data['user'] == 'example' | ||
assert response.data['token'] == 'xyz' | ||
|
||
|