From 6f58fdf15856ce05620d033220b0221ab36b6311 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 10 May 2021 19:51:29 +0200 Subject: [PATCH] api: add more tests Signed-off-by: Jens Langhammer --- authentik/admin/tests/test_api.py | 18 ++++++++++++++++++ authentik/api/auth.py | 2 +- authentik/api/tests/test_swagger.py | 7 +++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/authentik/admin/tests/test_api.py b/authentik/admin/tests/test_api.py index 1c2ff2266..7d98357ad 100644 --- a/authentik/admin/tests/test_api.py +++ b/authentik/admin/tests/test_api.py @@ -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() diff --git a/authentik/api/auth.py b/authentik/api/auth.py index 1992061f8..97f821b56 100644 --- a/authentik/api/auth.py +++ b/authentik/api/auth.py @@ -54,4 +54,4 @@ class AuthentikTokenAuthentication(BaseAuthentication): if not token: return None - return (token.user, None) + return (token.user, None) # pragma: no cover diff --git a/authentik/api/tests/test_swagger.py b/authentik/api/tests/test_swagger.py index b8095a388..7857248ce 100644 --- a/authentik/api/tests/test_swagger.py +++ b/authentik/api/tests/test_swagger.py @@ -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)