stages/email: add tests for API

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-04-04 14:14:58 +02:00
parent 90e7856efb
commit 8cae1f2ab5
4 changed files with 33 additions and 5 deletions

View File

@ -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"""

View 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"))

View File

@ -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"""

View File

@ -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