mirror of
https://github.com/inventree/InvenTree.git
synced 2026-11-25 01:03:07 +00:00
More tests for users app (#7479)
* disable patch coverage * also test for is_active flag * ignore edge case regarding coverage * add tests for api logout * test login redirects * style fixes * fully utilise serializer for /api/user/roles api * ignore logout mig from cov * bump api version as we are now documenting the roles endpoint * ignore on migration runs for coverage * remove dead code * ignore potential caching errors for coverage * test default dj_rest_auth token endpoint * move pragma * just ignore whole block * move ignore back * test for token based token revocation
This commit is contained in:
1 parent
5a6708a042
commit
935243c2d5
9 files changed
+86
-89
No files matched your search
@@ -48,6 +48,25 @@ class UserAPITests(InvenTreeAPITestCase):
|
||||
|
||||
self.assertIn('name', response.data)
|
||||
|
||||
def test_logout(self):
|
||||
"""Test api logout endpoint."""
|
||||
token_key = self.get(url=reverse('api-token')).data['token']
|
||||
self.client.logout()
|
||||
self.client.credentials(HTTP_AUTHORIZATION='Token ' + token_key)
|
||||
|
||||
self.post(reverse('api-logout'), expected_code=200)
|
||||
self.get(reverse('api-token'), expected_code=401)
|
||||
|
||||
def test_login_redirect(self):
|
||||
"""Test login redirect endpoint."""
|
||||
response = self.get(reverse('api-login-redirect'), expected_code=302)
|
||||
self.assertEqual(response.url, '/index/')
|
||||
|
||||
# PUI
|
||||
self.put(reverse('api-ui-preference'), {'preferred_method': 'pui'})
|
||||
response = self.get(reverse('api-login-redirect'), expected_code=302)
|
||||
self.assertEqual(response.url, '/platform/logged-in/')
|
||||
|
||||
|
||||
class UserTokenTests(InvenTreeAPITestCase):
|
||||
"""Tests for user token functionality."""
|
||||
@@ -156,3 +175,13 @@ class UserTokenTests(InvenTreeAPITestCase):
|
||||
token.save()
|
||||
|
||||
self.client.get(me, expected_code=200)
|
||||
|
||||
def test_buildin_token(self):
|
||||
"""Test the built-in token authentication."""
|
||||
response = self.post(
|
||||
reverse('rest_login'),
|
||||
{'username': self.username, 'password': self.password},
|
||||
expected_code=200,
|
||||
)
|
||||
self.assertIn('key', response.data)
|
||||
self.assertTrue(response.data['key'].startswith('inv-'))
|
||||
Reference in new issue
Block a user