From 1dc01ef857165462df0ecbecdfeb51c1ab3b5c2d Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 2 Apr 2021 23:11:53 +0200 Subject: [PATCH] *: add API tests for types endpoints Signed-off-by: Jens Langhammer --- authentik/admin/tests/test_api.py | 5 ++++ .../core/tests/test_property_mapping_api.py | 7 ++++++ authentik/core/tests/test_providers_api.py | 24 +++++++++++++++++++ authentik/crypto/api.py | 2 +- authentik/events/tests/test_api.py | 12 ++++++++-- authentik/flows/tests/test_api.py | 10 ++++++++ authentik/outposts/tests/__init__.py | 0 authentik/outposts/tests/test_api.py | 24 +++++++++++++++++++ .../outposts/{tests.py => tests/test_sa.py} | 0 9 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 authentik/core/tests/test_providers_api.py create mode 100644 authentik/outposts/tests/__init__.py create mode 100644 authentik/outposts/tests/test_api.py rename authentik/outposts/{tests.py => tests/test_sa.py} (100%) diff --git a/authentik/admin/tests/test_api.py b/authentik/admin/tests/test_api.py index eaebf4fc9..293566875 100644 --- a/authentik/admin/tests/test_api.py +++ b/authentik/admin/tests/test_api.py @@ -71,3 +71,8 @@ class TestAdminAPI(TestCase): """Test metrics API""" response = self.client.get(reverse("authentik_api:admin_metrics-list")) self.assertEqual(response.status_code, 200) + + def test_apps(self): + """Test apps API""" + response = self.client.get(reverse("authentik_api:apps-list")) + self.assertEqual(response.status_code, 200) diff --git a/authentik/core/tests/test_property_mapping_api.py b/authentik/core/tests/test_property_mapping_api.py index 48b524b0f..74da28f5e 100644 --- a/authentik/core/tests/test_property_mapping_api.py +++ b/authentik/core/tests/test_property_mapping_api.py @@ -43,3 +43,10 @@ class TestPropertyMappingAPI(APITestCase): self.assertEqual(PropertyMappingSerializer().validate_expression(expr), expr) with self.assertRaises(ValidationError): print(PropertyMappingSerializer().validate_expression("/")) + + def test_types(self): + """Test PropertyMappigns's types endpoint""" + response = self.client.get( + reverse("authentik_api:propertymapping-types"), + ) + self.assertEqual(response.status_code, 200) diff --git a/authentik/core/tests/test_providers_api.py b/authentik/core/tests/test_providers_api.py new file mode 100644 index 000000000..dbfba2594 --- /dev/null +++ b/authentik/core/tests/test_providers_api.py @@ -0,0 +1,24 @@ +"""Test providers API""" +from django.urls import reverse +from rest_framework.test import APITestCase + +from authentik.core.models import PropertyMapping, User + + +class TestProvidersAPI(APITestCase): + """Test providers API""" + + def setUp(self) -> None: + super().setUp() + self.mapping = PropertyMapping.objects.create( + name="dummy", expression="""return {'foo': 'bar'}""" + ) + self.user = User.objects.get(username="akadmin") + self.client.force_login(self.user) + + def test_types(self): + """Test Providers's types endpoint""" + response = self.client.get( + reverse("authentik_api:provider-types"), + ) + self.assertEqual(response.status_code, 200) diff --git a/authentik/crypto/api.py b/authentik/crypto/api.py index b47745144..f600ec67c 100644 --- a/authentik/crypto/api.py +++ b/authentik/crypto/api.py @@ -104,7 +104,7 @@ class CertificateKeyPairFilter(django_filters.FilterSet): ) # pylint: disable=unused-argument - def filter_has_key(self, queryset, name, value): + def filter_has_key(self, queryset, name, value): # pragma: no cover """Only return certificate-key pairs with keys""" return queryset.exclude(key_data__exact="") diff --git a/authentik/events/tests/test_api.py b/authentik/events/tests/test_api.py index 7a2812e02..b7b4c15fc 100644 --- a/authentik/events/tests/test_api.py +++ b/authentik/events/tests/test_api.py @@ -10,11 +10,12 @@ from authentik.events.models import Event, EventAction class TestEventsAPI(APITestCase): """Test Event API""" - def test_top_n(self): - """Test top_per_user""" + def setUp(self) -> None: user = User.objects.get(username="akadmin") self.client.force_login(user) + def test_top_n(self): + """Test top_per_user""" event = Event.new(EventAction.AUTHORIZE_APPLICATION) event.save() # We save to ensure nothing is un-saveable response = self.client.get( @@ -22,3 +23,10 @@ class TestEventsAPI(APITestCase): data={"filter_action": EventAction.AUTHORIZE_APPLICATION}, ) self.assertEqual(response.status_code, 200) + + def test_actions(self): + """Test actions""" + response = self.client.get( + reverse("authentik_api:event-actions"), + ) + self.assertEqual(response.status_code, 200) diff --git a/authentik/flows/tests/test_api.py b/authentik/flows/tests/test_api.py index 6af98198e..07b8eb1b4 100644 --- a/authentik/flows/tests/test_api.py +++ b/authentik/flows/tests/test_api.py @@ -90,3 +90,13 @@ class TestFlowsAPI(APITestCase): ) self.assertEqual(response.status_code, 200) self.assertJSONEqual(response.content, {"diagram": DIAGRAM_SHORT_EXPECTED}) + + def test_types(self): + """Test Stage's types endpoint""" + user = User.objects.get(username="akadmin") + self.client.force_login(user) + + response = self.client.get( + reverse("authentik_api:stage-types"), + ) + self.assertEqual(response.status_code, 200) diff --git a/authentik/outposts/tests/__init__.py b/authentik/outposts/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/authentik/outposts/tests/test_api.py b/authentik/outposts/tests/test_api.py new file mode 100644 index 000000000..841f52a15 --- /dev/null +++ b/authentik/outposts/tests/test_api.py @@ -0,0 +1,24 @@ +"""Test outpost service connection API""" +from django.urls import reverse +from rest_framework.test import APITestCase + +from authentik.core.models import PropertyMapping, User + + +class TestOutpostServiceConnectionsAPI(APITestCase): + """Test outpost service connection API""" + + def setUp(self) -> None: + super().setUp() + self.mapping = PropertyMapping.objects.create( + name="dummy", expression="""return {'foo': 'bar'}""" + ) + self.user = User.objects.get(username="akadmin") + self.client.force_login(self.user) + + def test_types(self): + """Test OutpostServiceConnections's types endpoint""" + response = self.client.get( + reverse("authentik_api:outpostserviceconnection-types"), + ) + self.assertEqual(response.status_code, 200) diff --git a/authentik/outposts/tests.py b/authentik/outposts/tests/test_sa.py similarity index 100% rename from authentik/outposts/tests.py rename to authentik/outposts/tests/test_sa.py