diff --git a/authentik/stages/email/models.py b/authentik/stages/email/models.py index c9a89f377..28ea6af95 100644 --- a/authentik/stages/email/models.py +++ b/authentik/stages/email/models.py @@ -30,7 +30,6 @@ class EmailTemplates(models.TextChoices): ) -# TODO: Create api for choices def get_template_choices(): """Get all available Email templates, including dynamically mounted ones. Directories are taken from TEMPLATES.DIR setting""" diff --git a/authentik/stages/email/tests/test_api.py b/authentik/stages/email/tests/test_api.py new file mode 100644 index 000000000..f3899850d --- /dev/null +++ b/authentik/stages/email/tests/test_api.py @@ -0,0 +1,32 @@ +"""email stage api tests""" +from django.urls import reverse +from rest_framework.serializers import ValidationError +from rest_framework.test import APITestCase + +from authentik.core.models import User +from authentik.stages.email.api import EmailStageSerializer +from authentik.stages.email.models import EmailTemplates + + +class TestEmailStageAPI(APITestCase): + """Email tests""" + + def setUp(self): + super().setUp() + self.akadmin = User.objects.get(username="akadmin") + self.client.force_login(self.akadmin) + + def test_templates(self): + """Test template list""" + response = self.client.get(reverse("authentik_api:emailstage-templates")) + self.assertEqual(response.status_code, 200) + + def test_validate(self): + """Test EmailStage's validation""" + self.assertEqual( + # pyright: reportGeneralTypeIssues=false + EmailStageSerializer().validate_template(EmailTemplates.ACCOUNT_CONFIRM), + EmailTemplates.ACCOUNT_CONFIRM, + ) + with self.assertRaises(ValidationError): + print(EmailStageSerializer().validate_template("foobar")) diff --git a/authentik/stages/email/tests/test_templates.py b/authentik/stages/email/tests/test_templates.py index a13344752..3c2c06c93 100644 --- a/authentik/stages/email/tests/test_templates.py +++ b/authentik/stages/email/tests/test_templates.py @@ -1,10 +1,8 @@ """email tests""" from os import unlink from pathlib import Path -from sys import platform from tempfile import gettempdir, mkstemp from typing import Any -from unittest.case import skipUnless from django.conf import settings from django.test import TestCase @@ -19,7 +17,6 @@ def get_templates_setting(temp_dir: str) -> dict[str, Any]: return templates_setting -@skipUnless(platform.startswith("linux"), "requires local docker") class TestEmailStageTemplates(TestCase): """Email tests""" diff --git a/pyproject.toml b/pyproject.toml index e695a3654..a4a3056ad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,7 +65,7 @@ extension-pkg-whitelist=["lxml","xmlsec"] # Allow constants to be shorter than normal (and lowercase, for settings.py) const-rgx="[a-zA-Z0-9_]{1,40}$" -ignored-modules=["django-otp","binascii", "socket"] +ignored-modules=["django-otp","binascii", "socket", "zlib"] generated-members=["xmlsec.constants.*","xmlsec.tree.*","xmlsec.template.*"] ignore="migrations" max-attributes=12