admin: add tests for hidden form fields

This commit is contained in:
Jens Langhammer 2020-12-13 23:14:18 +01:00
parent 41576e27be
commit a3b17d1ed4
2 changed files with 18 additions and 0 deletions

View file

@ -1,11 +1,13 @@
"""admin tests""" """admin tests"""
from uuid import uuid4 from uuid import uuid4
from django import forms
from django.test import TestCase from django.test import TestCase
from django.test.client import RequestFactory from django.test.client import RequestFactory
from authentik.admin.views.policies_bindings import PolicyBindingCreateView from authentik.admin.views.policies_bindings import PolicyBindingCreateView
from authentik.core.models import Application from authentik.core.models import Application
from authentik.policies.forms import PolicyBindingForm
class TestPolicyBindingView(TestCase): class TestPolicyBindingView(TestCase):
@ -32,3 +34,10 @@ class TestPolicyBindingView(TestCase):
request = self.factory.get("/", {"target": target.pk.hex}) request = self.factory.get("/", {"target": target.pk.hex})
view = PolicyBindingCreateView(request=request) view = PolicyBindingCreateView(request=request)
self.assertEqual(view.get_initial(), {"target": target, "order": 0}) self.assertEqual(view.get_initial(), {"target": target, "order": 0})
self.assertTrue(
isinstance(
PolicyBindingForm(initial={"target": "foo"}).fields["target"].widget,
forms.HiddenInput,
)
)

View file

@ -1,10 +1,12 @@
"""admin tests""" """admin tests"""
from uuid import uuid4 from uuid import uuid4
from django import forms
from django.test import TestCase from django.test import TestCase
from django.test.client import RequestFactory from django.test.client import RequestFactory
from authentik.admin.views.stages_bindings import StageBindingCreateView from authentik.admin.views.stages_bindings import StageBindingCreateView
from authentik.flows.forms import FlowStageBindingForm
from authentik.flows.models import Flow from authentik.flows.models import Flow
@ -32,3 +34,10 @@ class TestStageBindingView(TestCase):
request = self.factory.get("/", {"target": target.pk.hex}) request = self.factory.get("/", {"target": target.pk.hex})
view = StageBindingCreateView(request=request) view = StageBindingCreateView(request=request)
self.assertEqual(view.get_initial(), {"target": target, "order": 0}) self.assertEqual(view.get_initial(), {"target": target, "order": 0})
self.assertTrue(
isinstance(
FlowStageBindingForm(initial={"target": "foo"}).fields["target"].widget,
forms.HiddenInput,
)
)