Tests for token Auth

This commit is contained in:
Matthias 2022-05-13 01:23:12 +02:00
parent a7a80da928
commit 6b550e0547
No known key found for this signature in database
GPG Key ID: AB6D0E6C4CB65093

View File

@ -47,3 +47,20 @@ class MiddlewareTests(TestCase):
# check that a 401 is raised
self.check_path(reverse('settings.js'), 401)
def test_token_auth(self):
"""Test auth with token auth"""
# get token
response = self.client.get(reverse('api-token'), format='json', data={})
token = response.data['token']
# logout
self.client.logout()
# this should raise a 401
self.check_path(reverse('settings.js'), 401)
# request with token
self.check_path(reverse('settings.js'), HTTP_Authorization= f'Token {token}')
# should still fail without token
self.check_path(reverse('settings.js'), 401)