core: add tests for token API

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-03-31 20:36:28 +02:00
parent e476186cbc
commit 330d5047e7
2 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,22 @@
"""Test token API"""
from django.urls.base import reverse
from rest_framework.test import APITestCase
from authentik.core.models import Token, User
class TestTokenAPI(APITestCase):
"""Test token API"""
def setUp(self) -> None:
super().setUp()
self.user = User.objects.get(username="akadmin")
self.client.force_login(self.user)
def test_test_call(self):
"""Test token creation endpoint"""
response = self.client.post(
reverse("authentik_api:token-list"), {"identifier": "test-token"}
)
self.assertEqual(response.status_code, 201)
self.assertEqual(Token.objects.get(identifier="test-token").user, self.user)