Skip to content

Commit 74eb3e4

Browse files
committed
Split unit test into 3
1 parent 7a87af1 commit 74eb3e4

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

tests/test_testing.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,27 +81,44 @@ def test_credentials(self):
8181
response = self.client.get('/view/')
8282
assert response.data['auth'] == 'example'
8383

84-
def test_force_authenticate(self):
84+
def test_force_authenticate_with_user(self):
8585
"""
86-
Setting `.force_authenticate()` forcibly authenticates each request.
86+
Setting `.force_authenticate()` with a user forcibly authenticates each
87+
request with that user.
8788
"""
88-
# User only
8989
user = User.objects.create_user('example', '[email protected]')
90+
9091
self.client.force_authenticate(user=user)
9192
response = self.client.get('/view/')
93+
9294
assert response.data['user'] == 'example'
9395
assert 'token' not in response.data
9496

95-
# Token only
97+
def test_force_authenticate_with_token(self):
98+
"""
99+
Setting `.force_authenticate()` with a token forcibly authenticates each
100+
request with that token.
101+
"""
102+
user = User.objects.create_user('example', '[email protected]')
96103
token = Token.objects.create(key='xyz', user=user)
104+
97105
self.client.force_authenticate(token=token)
98106
response = self.client.get('/view/')
107+
99108
assert response.data['token'] == 'xyz'
100109
assert 'user' not in response.data
101110

102-
# User and token
111+
def test_force_authenticate_with_user_and_token(self):
112+
"""
113+
Setting `.force_authenticate()` with a user and token forcibly
114+
authenticates each request with that user and token.
115+
"""
116+
user = User.objects.create_user('example', '[email protected]')
117+
token = Token.objects.create(key='xyz', user=user)
118+
103119
self.client.force_authenticate(user=user, token=token)
104120
response = self.client.get('/view/')
121+
105122
assert response.data['user'] == 'example'
106123
assert response.data['token'] == 'xyz'
107124

0 commit comments

Comments
 (0)