Skip to content

Commit

Permalink
Split unit test into 3
Browse files Browse the repository at this point in the history
  • Loading branch information
willbeaufoy committed Jul 3, 2022
1 parent 7a87af1 commit b15cd52
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions tests/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down

0 comments on commit b15cd52

Please sign in to comment.