aboutsummaryrefslogtreecommitdiffstats
path: root/src/workflow/tests/test_workflows.py
blob: 995d69939d2d763e9d9c13dfa53c33127ce868ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
##############################################################################
# Copyright (c) 2018 Parker Berberian, Sawyer Bergeron, and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################

from unittest import SkipTest
from django.test import TestCase
from workflow.workflow_factory import WorkflowFactory


"""
To start a workflow:
    POST to /wf/workflow {"add": <wf_type_int>

    types:
        0 - Booking
        1 - Resource
        2 - Config

To remove a workflow:
    POST to /wf/workflow {"cancel": ""}
"""


class WorkflowTestCase(TestCase):

    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        raise SkipTest("These tests are no good")

    def setUp(self):
        self.clear_workflow()
        self.create_workflow(self.wf_type)

    def create_workflow(self, wf_type):
        self.clear_workflow()

        # creates workflow on backend
        self.client.post("/", {"create": int(wf_type)})  # TODO: verify content type, etc

    def clear_workflow(self):
        session = self.client.session
        for k in session.keys():
            del session[k]
        session.save()

    def render_steps(self):
        """Retrieve each step individually at /wf/workflow/step=<index>."""
        for i in range(self.step_count):
            #  renders the step itself, not in an iframe
            exception = None
            try:
                response = self.client.get("/wf/workflow/", {"step": str(i)})
                self.assertLess(response.status_code, 300)
            except Exception as e:
                exception = e

            self.assertIsNone(exception)


class BookingWorkflowTestCase(WorkflowTestCase):

    @classmethod
    def setUpClass(cls):
        super(BookingWorkflowTestCase, cls).setUpClass()
        cls.step_count = len(WorkflowFactory.booking_steps)
        cls.wf_type = 0

    def test_steps_render(self):
        super(BookingWorkflowTestCase, self).render_steps()


class ResourceWorkflowTestCase(WorkflowTestCase):

    @classmethod
    def setUpClass(cls):
        super(ResourceWorkflowTestCase, cls).setUpClass()
        cls.step_count = len(WorkflowFactory.resource_steps)
        cls.wf_type = 1

    def test_steps_render(self):
        super(ResourceWorkflowTestCase, self).render_steps()


class ConfigWorkflowTestCase(WorkflowTestCase):

    @classmethod
    def setUpClass(cls):
        super(ConfigWorkflowTestCase, cls).setUpClass()
        cls.step_count = len(WorkflowFactory.config_steps)
        cls.wf_type = 2

    def test_steps_render(self):
        super(ConfigWorkflowTestCase, self).render_steps()