This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/passbook/policies/dummy/tests.py

40 lines
1.1 KiB
Python
Raw Normal View History

2020-05-13 21:20:27 +00:00
"""dummy policy tests"""
from django.test import TestCase
from guardian.shortcuts import get_anonymous_user
from passbook.policies.dummy.forms import DummyPolicyForm
from passbook.policies.dummy.models import DummyPolicy
from passbook.policies.engine import PolicyRequest
class TestDummyPolicy(TestCase):
"""Test dummy policy"""
def setUp(self):
super().setUp()
self.request = PolicyRequest(user=get_anonymous_user())
def test_policy(self):
"""test policy .passes"""
policy: DummyPolicy = DummyPolicy.objects.create(
name="dummy", wait_min=1, wait_max=2
)
result = policy.passes(self.request)
self.assertFalse(result.passing)
self.assertEqual(result.messages, ("dummy",))
def test_form(self):
"""test form"""
form = DummyPolicyForm(
data={
"name": "dummy",
"negate": False,
"order": 0,
"timeout": 1,
"result": True,
"wait_min": 1,
"wait_max": 2,
}
)
self.assertTrue(form.is_valid())