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/authentik/flows/tests/test_views_helper.py

41 lines
1.5 KiB
Python
Raw Normal View History

"""flow views tests"""
from django.test import TestCase
from django.urls import reverse
2020-12-05 21:08:42 +00:00
from authentik.flows.models import Flow, FlowDesignation
from authentik.flows.planner import FlowPlan
from authentik.flows.views import SESSION_KEY_PLAN
class TestHelperView(TestCase):
"""Test helper views logic"""
def test_default_view(self):
"""Test that ToDefaultFlow returns the expected URL"""
2020-09-30 17:34:22 +00:00
flow = Flow.objects.filter(
designation=FlowDesignation.INVALIDATION,
).first()
response = self.client.get(
2020-12-05 21:08:42 +00:00
reverse("authentik_flows:default-invalidation"),
2020-09-30 17:34:22 +00:00
)
expected_url = reverse("authentik_core:if-flow", kwargs={"flow_slug": flow.slug})
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, expected_url)
def test_default_view_invalid_plan(self):
"""Test that ToDefaultFlow returns the expected URL (with an invalid plan)"""
2020-09-30 17:34:22 +00:00
flow = Flow.objects.filter(
designation=FlowDesignation.INVALIDATION,
).first()
plan = FlowPlan(flow_pk=flow.pk.hex + "aa")
session = self.client.session
session[SESSION_KEY_PLAN] = plan
session.save()
2020-09-30 17:34:22 +00:00
response = self.client.get(
2020-12-05 21:08:42 +00:00
reverse("authentik_flows:default-invalidation"),
2020-09-30 17:34:22 +00:00
)
expected_url = reverse("authentik_core:if-flow", kwargs={"flow_slug": flow.slug})
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, expected_url)