api: add more tests
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
5d4051f547
commit
6f58fdf158
|
@ -1,4 +1,5 @@
|
|||
"""test admin api"""
|
||||
from authentik.events.monitored_tasks import TaskResultStatus
|
||||
from json import loads
|
||||
|
||||
from django.test import TestCase
|
||||
|
@ -30,6 +31,23 @@ class TestAdminAPI(TestCase):
|
|||
any(task["task_name"] == "clean_expired_models" for task in body)
|
||||
)
|
||||
|
||||
def test_tasks_single(self):
|
||||
"""Test Task API (read single)"""
|
||||
clean_expired_models.delay()
|
||||
response = self.client.get(
|
||||
reverse("authentik_api:admin_system_tasks-detail", kwargs={
|
||||
"pk": "clean_expired_models"
|
||||
}))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
body = loads(response.content)
|
||||
self.assertEqual(body["status"], TaskResultStatus.SUCCESSFUL.name)
|
||||
self.assertEqual(body["task_name"], "clean_expired_models")
|
||||
response = self.client.get(
|
||||
reverse("authentik_api:admin_system_tasks-detail", kwargs={
|
||||
"pk": "qwerqwer"
|
||||
}))
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
def test_tasks_retry(self):
|
||||
"""Test Task API (retry)"""
|
||||
clean_expired_models.delay()
|
||||
|
|
|
@ -54,4 +54,4 @@ class AuthentikTokenAuthentication(BaseAuthentication):
|
|||
if not token:
|
||||
return None
|
||||
|
||||
return (token.user, None)
|
||||
return (token.user, None) # pragma: no cover
|
||||
|
|
|
@ -22,3 +22,10 @@ class TestSwaggerGeneration(APITestCase):
|
|||
reverse("authentik_api:schema-json", kwargs={"format": ".json"}),
|
||||
)
|
||||
self.assertTrue(loads(response.content.decode()))
|
||||
|
||||
def test_browser(self):
|
||||
"""Test API Browser"""
|
||||
response = self.client.get(
|
||||
reverse("authentik_api:swagger"),
|
||||
)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
|
Reference in New Issue