Debian Codegraph @

mistralclient/tests/unit/v2/test_action_executions.py

raw symbols SCIP
1 # Copyright 2014 - Mirantis, Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 from mistralclient.api.v2 import action_executions
16 from mistralclient.tests.unit.v2 import base
17
18 # TODO(everyone): later we need additional tests verifying all the errors etc.
19
20 ACTION_EXEC = {
21 'id': "1",
22 'name': 'my_action_execution',
23 'workflow_name': 'my_wf',
24 'state': 'RUNNING',
25 }
26
27 URL_TEMPLATE = '/action_executions'
28 URL_TEMPLATE_ID = '/action_executions/%s'
29
30
31 class TestActionExecutions(base.BaseClientV2Test):
32 def test_create(self):
33 self.requests_mock.post(self.TEST_URL + URL_TEMPLATE,
34 json=ACTION_EXEC,
35 status_code=201)
36
37 body = {
38 'name': ACTION_EXEC['name']
39 }
40
41 action_execution = self.action_executions.create(
42 'my_action_execution',
43 {}
44 )
45
46 self.assertIsNotNone(action_execution)
47 self.assertEqual(action_executions.ActionExecution(
48 self.action_executions, ACTION_EXEC
49 ).to_dict(), action_execution.to_dict())
50
51 self.assertEqual(body, self.requests_mock.last_request.json())
52
53 def test_update(self):
54 url = self.TEST_URL + URL_TEMPLATE_ID % ACTION_EXEC['id']
55 self.requests_mock.put(url, json=ACTION_EXEC)
56
57 body = {
58 'state': ACTION_EXEC['state']
59 }
60
61 action_execution = self.action_executions.update(
62 ACTION_EXEC['id'],
63 ACTION_EXEC['state']
64 )
65
66 self.assertIsNotNone(action_execution)
67
68 expected = action_executions.ActionExecution(
69 self.action_executions,
70 ACTION_EXEC
71 ).to_dict()
72
73 self.assertEqual(
74 expected,
75 action_execution.to_dict()
76 )
77
78 self.assertEqual(body, self.requests_mock.last_request.json())
79
80 def test_list(self):
81 self.requests_mock.get(self.TEST_URL + URL_TEMPLATE,
82 json={'action_executions': [ACTION_EXEC]})
83
84 action_execution_list = self.action_executions.list()
85
86 self.assertEqual(1, len(action_execution_list))
87 action_execution = action_execution_list[0]
88
89 expected = action_executions.ActionExecution(
90 self.action_executions,
91 ACTION_EXEC
92 ).to_dict()
93
94 self.assertEqual(expected, action_execution.to_dict())
95
96 def test_list_with_limit(self):
97 self.requests_mock.get(
98 self.TEST_URL + URL_TEMPLATE,
99 json={'action_executions': [ACTION_EXEC]}
100 )
101
102 action_execution_list = self.action_executions.list(limit=1)
103
104 self.assertEqual(1, len(action_execution_list))
105
106 last_request = self.requests_mock.last_request
107
108 # Make sure that limit is passed to the server correctly.
109 self.assertEqual(['1'], last_request.qs['limit'])
110
111 def test_list_with_no_limit(self):
112 self.requests_mock.get(
113 self.TEST_URL + URL_TEMPLATE,
114 json={'action_executions': [ACTION_EXEC]}
115 )
116
117 action_execution_list = self.action_executions.list(limit=-1)
118
119 self.assertEqual(1, len(action_execution_list))
120
121 last_request = self.requests_mock.last_request
122
123 self.assertNotIn('limit', last_request.qs)
124
125 def test_get(self):
126 url = self.TEST_URL + URL_TEMPLATE_ID % ACTION_EXEC['id']
127 self.requests_mock.get(url, json=ACTION_EXEC)
128
129 action_execution = self.action_executions.get(ACTION_EXEC['id'])
130
131 expected = action_executions.ActionExecution(
132 self.action_executions,
133 ACTION_EXEC
134 ).to_dict()
135
136 self.assertEqual(expected, action_execution.to_dict())
137
138 def test_delete(self):
139 url = self.TEST_URL + URL_TEMPLATE_ID % ACTION_EXEC['id']
140 self.requests_mock.delete(url, status_code=204)
141
142 self.action_executions.delete(ACTION_EXEC['id'])