diff --git a/authentik/flows/challenge.py b/authentik/flows/challenge.py index 78645bb75..dd663068e 100644 --- a/authentik/flows/challenge.py +++ b/authentik/flows/challenge.py @@ -3,12 +3,12 @@ from dataclasses import asdict, is_dataclass from enum import Enum from typing import TYPE_CHECKING, Optional, TypedDict from uuid import UUID -from rest_framework.request import Request from django.core.serializers.json import DjangoJSONEncoder from django.db import models from django.http import JsonResponse from rest_framework.fields import CharField, ChoiceField, DictField +from rest_framework.request import Request from authentik.core.api.utils import PassiveSerializer from authentik.lib.utils.errors import exception_to_string diff --git a/authentik/stages/email/tests/test_templates.py b/authentik/stages/email/tests/test_templates.py index a60266a65..0e7d6d70a 100644 --- a/authentik/stages/email/tests/test_templates.py +++ b/authentik/stages/email/tests/test_templates.py @@ -1,7 +1,8 @@ """email tests""" from os import chmod, unlink from pathlib import Path -from tempfile import gettempdir, mkstemp +from shutil import rmtree +from tempfile import gettempdir, mkdtemp, mkstemp from typing import Any from django.conf import settings @@ -20,11 +21,17 @@ def get_templates_setting(temp_dir: str) -> dict[str, Any]: class TestEmailStageTemplates(TestCase): """Email tests""" + def setUp(self) -> None: + self.dir = mkdtemp() + + def tearDown(self) -> None: + rmtree(self.dir) + def test_custom_template(self): """Test with custom template""" - with self.settings(TEMPLATES=get_templates_setting(gettempdir())): - _, file = mkstemp(suffix=".html") - _, file2 = mkstemp(suffix=".html") + with self.settings(TEMPLATES=get_templates_setting(self.dir)): + _, file = mkstemp(suffix=".html", dir=self.dir) + _, file2 = mkstemp(suffix=".html", dir=self.dir) chmod(file2, 0o000) # Remove all permissions so we can't read the file choices = get_template_choices() self.assertEqual(choices[-1][0], Path(file).name)