stages/email: make template tests less flaky
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
ee615c2d22
commit
11b1eb4173
|
@ -3,12 +3,12 @@ from dataclasses import asdict, is_dataclass
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import TYPE_CHECKING, Optional, TypedDict
|
from typing import TYPE_CHECKING, Optional, TypedDict
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
from rest_framework.request import Request
|
|
||||||
|
|
||||||
from django.core.serializers.json import DjangoJSONEncoder
|
from django.core.serializers.json import DjangoJSONEncoder
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
from rest_framework.fields import CharField, ChoiceField, DictField
|
from rest_framework.fields import CharField, ChoiceField, DictField
|
||||||
|
from rest_framework.request import Request
|
||||||
|
|
||||||
from authentik.core.api.utils import PassiveSerializer
|
from authentik.core.api.utils import PassiveSerializer
|
||||||
from authentik.lib.utils.errors import exception_to_string
|
from authentik.lib.utils.errors import exception_to_string
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
"""email tests"""
|
"""email tests"""
|
||||||
from os import chmod, unlink
|
from os import chmod, unlink
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from tempfile import gettempdir, mkstemp
|
from shutil import rmtree
|
||||||
|
from tempfile import gettempdir, mkdtemp, mkstemp
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
@ -20,11 +21,17 @@ def get_templates_setting(temp_dir: str) -> dict[str, Any]:
|
||||||
class TestEmailStageTemplates(TestCase):
|
class TestEmailStageTemplates(TestCase):
|
||||||
"""Email tests"""
|
"""Email tests"""
|
||||||
|
|
||||||
|
def setUp(self) -> None:
|
||||||
|
self.dir = mkdtemp()
|
||||||
|
|
||||||
|
def tearDown(self) -> None:
|
||||||
|
rmtree(self.dir)
|
||||||
|
|
||||||
def test_custom_template(self):
|
def test_custom_template(self):
|
||||||
"""Test with custom template"""
|
"""Test with custom template"""
|
||||||
with self.settings(TEMPLATES=get_templates_setting(gettempdir())):
|
with self.settings(TEMPLATES=get_templates_setting(self.dir)):
|
||||||
_, file = mkstemp(suffix=".html")
|
_, file = mkstemp(suffix=".html", dir=self.dir)
|
||||||
_, file2 = mkstemp(suffix=".html")
|
_, file2 = mkstemp(suffix=".html", dir=self.dir)
|
||||||
chmod(file2, 0o000) # Remove all permissions so we can't read the file
|
chmod(file2, 0o000) # Remove all permissions so we can't read the file
|
||||||
choices = get_template_choices()
|
choices = get_template_choices()
|
||||||
self.assertEqual(choices[-1][0], Path(file).name)
|
self.assertEqual(choices[-1][0], Path(file).name)
|
||||||
|
|
Reference in New Issue