From a3b17d1ed40ae50239eee394d405796a1fd0390c Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 13 Dec 2020 23:14:18 +0100 Subject: [PATCH] admin: add tests for hidden form fields --- authentik/admin/tests/test_policy_binding.py | 9 +++++++++ authentik/admin/tests/test_stage_bindings.py | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/authentik/admin/tests/test_policy_binding.py b/authentik/admin/tests/test_policy_binding.py index dcefeff27..034cfd1d1 100644 --- a/authentik/admin/tests/test_policy_binding.py +++ b/authentik/admin/tests/test_policy_binding.py @@ -1,11 +1,13 @@ """admin tests""" from uuid import uuid4 +from django import forms from django.test import TestCase from django.test.client import RequestFactory from authentik.admin.views.policies_bindings import PolicyBindingCreateView from authentik.core.models import Application +from authentik.policies.forms import PolicyBindingForm class TestPolicyBindingView(TestCase): @@ -32,3 +34,10 @@ class TestPolicyBindingView(TestCase): request = self.factory.get("/", {"target": target.pk.hex}) view = PolicyBindingCreateView(request=request) self.assertEqual(view.get_initial(), {"target": target, "order": 0}) + + self.assertTrue( + isinstance( + PolicyBindingForm(initial={"target": "foo"}).fields["target"].widget, + forms.HiddenInput, + ) + ) diff --git a/authentik/admin/tests/test_stage_bindings.py b/authentik/admin/tests/test_stage_bindings.py index 8895f99d1..481fcaca4 100644 --- a/authentik/admin/tests/test_stage_bindings.py +++ b/authentik/admin/tests/test_stage_bindings.py @@ -1,10 +1,12 @@ """admin tests""" from uuid import uuid4 +from django import forms from django.test import TestCase from django.test.client import RequestFactory from authentik.admin.views.stages_bindings import StageBindingCreateView +from authentik.flows.forms import FlowStageBindingForm from authentik.flows.models import Flow @@ -32,3 +34,10 @@ class TestStageBindingView(TestCase): request = self.factory.get("/", {"target": target.pk.hex}) view = StageBindingCreateView(request=request) self.assertEqual(view.get_initial(), {"target": target, "order": 0}) + + self.assertTrue( + isinstance( + FlowStageBindingForm(initial={"target": "foo"}).fields["target"].widget, + forms.HiddenInput, + ) + )