2020-05-11 13:01:14 +00:00
|
|
|
"""flow views tests"""
|
|
|
|
from django.shortcuts import reverse
|
|
|
|
from django.test import Client, TestCase
|
|
|
|
|
|
|
|
from passbook.flows.models import Flow, FlowDesignation
|
|
|
|
from passbook.flows.planner import FlowPlan
|
|
|
|
from passbook.flows.views import SESSION_KEY_PLAN
|
|
|
|
|
|
|
|
|
|
|
|
class TestHelperView(TestCase):
|
|
|
|
"""Test helper views logic"""
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.client = Client()
|
|
|
|
|
|
|
|
def test_default_view(self):
|
|
|
|
"""Test that ToDefaultFlow returns the expected URL"""
|
|
|
|
flow = Flow.objects.filter(designation=FlowDesignation.INVALIDATION,).first()
|
|
|
|
response = self.client.get(reverse("passbook_flows:default-invalidation"),)
|
|
|
|
expected_url = reverse(
|
2020-05-23 22:57:25 +00:00
|
|
|
"passbook_flows:flow-executor-shell", kwargs={"flow_slug": flow.slug}
|
2020-05-11 13:01:14 +00:00
|
|
|
)
|
|
|
|
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)"""
|
|
|
|
flow = Flow.objects.filter(designation=FlowDesignation.INVALIDATION,).first()
|
2020-06-18 20:43:51 +00:00
|
|
|
plan = FlowPlan(flow_pk=flow.pk.hex + "aa")
|
2020-05-11 13:01:14 +00:00
|
|
|
session = self.client.session
|
|
|
|
session[SESSION_KEY_PLAN] = plan
|
|
|
|
session.save()
|
|
|
|
|
|
|
|
response = self.client.get(reverse("passbook_flows:default-invalidation"),)
|
|
|
|
expected_url = reverse(
|
2020-05-23 22:57:25 +00:00
|
|
|
"passbook_flows:flow-executor-shell", kwargs={"flow_slug": flow.slug}
|
2020-05-11 13:01:14 +00:00
|
|
|
)
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
self.assertEqual(response.url, expected_url)
|