stages/email: add tests for API
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
90e7856efb
commit
8cae1f2ab5
|
@ -30,7 +30,6 @@ class EmailTemplates(models.TextChoices):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# TODO: Create api for choices
|
|
||||||
def get_template_choices():
|
def get_template_choices():
|
||||||
"""Get all available Email templates, including dynamically mounted ones.
|
"""Get all available Email templates, including dynamically mounted ones.
|
||||||
Directories are taken from TEMPLATES.DIR setting"""
|
Directories are taken from TEMPLATES.DIR setting"""
|
||||||
|
|
32
authentik/stages/email/tests/test_api.py
Normal file
32
authentik/stages/email/tests/test_api.py
Normal file
|
@ -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"))
|
|
@ -1,10 +1,8 @@
|
||||||
"""email tests"""
|
"""email tests"""
|
||||||
from os import unlink
|
from os import unlink
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from sys import platform
|
|
||||||
from tempfile import gettempdir, mkstemp
|
from tempfile import gettempdir, mkstemp
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from unittest.case import skipUnless
|
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
@ -19,7 +17,6 @@ def get_templates_setting(temp_dir: str) -> dict[str, Any]:
|
||||||
return templates_setting
|
return templates_setting
|
||||||
|
|
||||||
|
|
||||||
@skipUnless(platform.startswith("linux"), "requires local docker")
|
|
||||||
class TestEmailStageTemplates(TestCase):
|
class TestEmailStageTemplates(TestCase):
|
||||||
"""Email tests"""
|
"""Email tests"""
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ extension-pkg-whitelist=["lxml","xmlsec"]
|
||||||
# Allow constants to be shorter than normal (and lowercase, for settings.py)
|
# Allow constants to be shorter than normal (and lowercase, for settings.py)
|
||||||
const-rgx="[a-zA-Z0-9_]{1,40}$"
|
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.*"]
|
generated-members=["xmlsec.constants.*","xmlsec.tree.*","xmlsec.template.*"]
|
||||||
ignore="migrations"
|
ignore="migrations"
|
||||||
max-attributes=12
|
max-attributes=12
|
||||||
|
|
Reference in a new issue