flows: add tests for stage type, component and ui_user_settings
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
e9e0992dce
commit
776c3128b8
|
@ -0,0 +1,16 @@
|
||||||
|
"""Test config API"""
|
||||||
|
from json import loads
|
||||||
|
|
||||||
|
from django.urls import reverse
|
||||||
|
from rest_framework.test import APITestCase
|
||||||
|
|
||||||
|
|
||||||
|
class TestConfig(APITestCase):
|
||||||
|
"""Test config API"""
|
||||||
|
|
||||||
|
def test_config(self):
|
||||||
|
"""Test YAML generation"""
|
||||||
|
response = self.client.get(
|
||||||
|
reverse("authentik_api:configs-list"),
|
||||||
|
)
|
||||||
|
self.assertTrue(loads(response.content.decode()))
|
|
@ -20,10 +20,12 @@ def is_dict(value: Any):
|
||||||
class PassiveSerializer(Serializer):
|
class PassiveSerializer(Serializer):
|
||||||
"""Base serializer class which doesn't implement create/update methods"""
|
"""Base serializer class which doesn't implement create/update methods"""
|
||||||
|
|
||||||
def create(self, validated_data: dict) -> Model:
|
def create(self, validated_data: dict) -> Model: # pragma: no cover
|
||||||
return Model()
|
return Model()
|
||||||
|
|
||||||
def update(self, instance: Model, validated_data: dict) -> Model:
|
def update(
|
||||||
|
self, instance: Model, validated_data: dict
|
||||||
|
) -> Model: # pragma: no cover
|
||||||
return Model()
|
return Model()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
"""base model tests"""
|
||||||
|
from typing import Callable, Type
|
||||||
|
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
from authentik.flows.models import Stage
|
||||||
|
from authentik.flows.stage import StageView
|
||||||
|
from authentik.lib.utils.reflection import all_subclasses
|
||||||
|
|
||||||
|
|
||||||
|
class TestModels(TestCase):
|
||||||
|
"""Generic model properties tests"""
|
||||||
|
|
||||||
|
|
||||||
|
def model_tester_factory(test_model: Type[Stage]) -> Callable:
|
||||||
|
"""Test a form"""
|
||||||
|
|
||||||
|
def tester(self: TestModels):
|
||||||
|
try:
|
||||||
|
model_class = None
|
||||||
|
if test_model._meta.abstract:
|
||||||
|
model_class = test_model.__bases__[0]()
|
||||||
|
else:
|
||||||
|
model_class = test_model()
|
||||||
|
self.assertTrue(issubclass(model_class.type, StageView))
|
||||||
|
self.assertIsNotNone(test_model.component)
|
||||||
|
_ = test_model.ui_user_settings
|
||||||
|
except NotImplementedError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return tester
|
||||||
|
|
||||||
|
|
||||||
|
for model in all_subclasses(Stage):
|
||||||
|
setattr(TestModels, f"test_model_{model.__name__}", model_tester_factory(model))
|
Reference in New Issue