Lab as a Service 2.0
[laas.git] / src / workflow / tests / test_workflows.py
1 ##############################################################################
2 # Copyright (c) 2018 Parker Berberian, Sawyer Bergeron, and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 from django.test import TestCase, client
10 from workflow.workflow_factory import WorkflowFactory
11 from dashboard.populate_db import Populator
12 from resource_inventory.models import *
13
14
15 """
16 To start a workflow:
17     POST to /wf/workflow {"add": <wf_type_int>
18
19     types:
20         0 - Booking
21         1 - Resource
22         2 - Config
23
24 To remove a workflow:
25     POST to /wf/workflow {"cancel": ""}
26 """
27
28 class WorkflowTestCase(TestCase):
29
30     @classmethod
31     def setUpTestData(cls):
32         Populator().populate()
33
34     def setUp(self):
35         self.clear_workflow()
36         self.create_workflow(self.wf_type)
37
38     def create_workflow(self, wf_type):
39         self.clear_workflow()
40
41         # creates workflow on backend
42         self.client.post("/", {"create": int(wf_type)})  # TODO: verify content type, etc
43
44     def clear_workflow(self):
45         session = self.client.session
46         for k in session.keys():
47             del session[k]
48         session.save()
49
50     def render_steps(self):
51         """
52         retrieves each step individually at /wf/workflow/step=<index>
53         """
54         for i in range(self.step_count):
55             #  renders the step itself, not in an iframe
56             exception = None
57             try:
58                 response = self.client.get("/wf/workflow/", {"step": str(i)})
59                 self.assertLess(response.status_code, 300)
60             except Exception as e:
61                 exception = e
62
63             self.assertIsNone(exception)
64
65 class BookingWorkflowTestCase(WorkflowTestCase):
66
67     @classmethod
68     def setUpClass(cls):
69         super(BookingWorkflowTestCase, cls).setUpClass()
70         cls.step_count = len(WorkflowFactory.booking_steps)
71         cls.wf_type = 0
72
73     def test_steps_render(self):
74         super(BookingWorkflowTestCase, self).render_steps()
75
76 class ResourceWorkflowTestCase(WorkflowTestCase):
77
78     @classmethod
79     def setUpClass(cls):
80         super(ResourceWorkflowTestCase, cls).setUpClass()
81         cls.step_count = len(WorkflowFactory.resource_steps)
82         cls.wf_type = 1
83
84     def test_steps_render(self):
85         super(ResourceWorkflowTestCase, self).render_steps()
86
87 class ConfigWorkflowTestCase(WorkflowTestCase):
88
89     @classmethod
90     def setUpClass(cls):
91         super(ConfigWorkflowTestCase, cls).setUpClass()
92         cls.step_count = len(WorkflowFactory.config_steps)
93         cls.wf_type = 2
94
95     def test_steps_render(self):
96         super(ConfigWorkflowTestCase, self).render_steps()