From af438af8ace7e82a2694ed82eb53e1f3e8c55048 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Wed, 31 Mar 2021 20:43:43 +0200 Subject: [PATCH] stages/invitation: add API tests Signed-off-by: Jens Langhammer --- authentik/policies/tests/test_bindings_api.py | 2 +- authentik/stages/invitation/tests.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/authentik/policies/tests/test_bindings_api.py b/authentik/policies/tests/test_bindings_api.py index 4d3a0d3f9..fc699391d 100644 --- a/authentik/policies/tests/test_bindings_api.py +++ b/authentik/policies/tests/test_bindings_api.py @@ -3,7 +3,7 @@ from django.urls import reverse from rest_framework.test import APITestCase from authentik.core.models import Group, User -from authentik.policies.models import PolicyBinding, PolicyBindingModel +from authentik.policies.models import PolicyBindingModel class TestBindingsAPI(APITestCase): diff --git a/authentik/stages/invitation/tests.py b/authentik/stages/invitation/tests.py index 85b263c31..c0df4b6f7 100644 --- a/authentik/stages/invitation/tests.py +++ b/authentik/stages/invitation/tests.py @@ -5,6 +5,7 @@ from django.test import Client, TestCase from django.urls import reverse from django.utils.encoding import force_str from guardian.shortcuts import get_anonymous_user +from rest_framework.test import APITestCase from authentik.core.models import User from authentik.flows.challenge import ChallengeTypes @@ -134,3 +135,20 @@ class TestUserLoginStage(TestCase): force_str(response.content), {"to": reverse("authentik_core:root-redirect"), "type": "redirect"}, ) + + +class TestInvitationsAPI(APITestCase): + """Test Invitations API""" + + def setUp(self) -> None: + super().setUp() + self.user = User.objects.get(username="akadmin") + self.client.force_login(self.user) + + def test_invite_create(self): + """Test Invitations creation endpoint""" + response = self.client.post( + reverse("authentik_api:invitation-list"), {"identifier": "test-token"} + ) + self.assertEqual(response.status_code, 201) + self.assertEqual(Invitation.objects.first().created_by, self.user)