Test Failed
Push — master ( 21460f...e380d0 )
by Tomaz
01:48
created

mistral_v2/tests/unit/test_mistral_querier_v2.py (30 issues)

1
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
2
# contributor license agreements.  See the NOTICE file distributed with
3
# this work for additional information regarding copyright ownership.
4
# The ASF licenses this file to You under the Apache License, Version 2.0
5
# (the "License"); you may not use this file except in compliance with
6
# the License.  You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
16
from __future__ import absolute_import
17
import copy
18
import datetime
19
import json
20
import requests
21
import time
22
import uuid
23
24
import mock
25
from mock import call
26
27
from mistralclient.api import base as mistralclient_base
28
from mistralclient.api.v2 import executions
29
from mistralclient.api.v2 import tasks
30
from oslo_config import cfg
31
32
import st2tests.config as tests_config
33
from six.moves import range
34
tests_config.parse_args()
35
36
from st2common.constants import action as action_constants
37
from st2common.exceptions import db as db_exc
38
from st2common.models.db.execution import ActionExecutionDB
39
from st2common.models.db.liveaction import LiveActionDB
40
from st2common.persistence.execution import ActionExecution
41
from st2common.util import action_db as action_utils
42
from st2common.util import loader
43
from st2tests import DbTestCase
44
45
46
MOCK_WF_TASKS_SUCCEEDED = [
47
    {'name': 'task1', 'state': 'SUCCESS'},
48
    {'name': 'task2', 'state': 'SUCCESS'}
49
]
50
51
MOCK_WF_TASKS_ERRORED = [
52
    {'name': 'task1', 'state': 'SUCCESS'},
53
    {'name': 'task2', 'state': 'ERROR'}
54
]
55
56
MOCK_WF_TASKS_RUNNING = [
57
    {'name': 'task1', 'state': 'SUCCESS'},
58
    {'name': 'task2', 'state': 'RUNNING'}
59
]
60
61
MOCK_WF_TASKS_WAITING = [
62
    {'name': 'task1', 'state': 'SUCCESS'},
63
    {'name': 'task2', 'state': 'WAITING'}
64
]
65
66
MOCK_WF_TASKS_PAUSED = [
67
    {'name': 'task1', 'state': 'SUCCESS'},
68
    {'name': 'task2', 'state': 'PAUSED'}
69
]
70
71
MOCK_WF_EX_DATA = {
72
    'id': uuid.uuid4().hex,
73
    'name': 'main',
74
    'output': '{"k1": "v1"}',
75
    'state': 'SUCCESS',
76
    'state_info': None
77
}
78
79
MOCK_WF_EX = executions.Execution(None, MOCK_WF_EX_DATA)
80
81
MOCK_WF_EX_TASKS_DATA = [
82
    {
83
        'id': uuid.uuid4().hex,
84
        'name': 'task1',
85
        'workflow_execution_id': MOCK_WF_EX_DATA['id'],
86
        'workflow_name': MOCK_WF_EX_DATA['name'],
87
        'created_at': str(datetime.datetime.utcnow()),
88
        'updated_at': str(datetime.datetime.utcnow()),
89
        'state': 'SUCCESS',
90
        'state_info': None,
91
        'input': '{"a": "b"}',
92
        'result': '{"c": "d"}',
93
        'published': '{"c": "d"}'
94
    },
95
    {
96
        'id': uuid.uuid4().hex,
97
        'name': 'task2',
98
        'workflow_execution_id': MOCK_WF_EX_DATA['id'],
99
        'workflow_name': MOCK_WF_EX_DATA['name'],
100
        'created_at': str(datetime.datetime.utcnow()),
101
        'updated_at': str(datetime.datetime.utcnow()),
102
        'state': 'SUCCESS',
103
        'state_info': None,
104
        'input': '{"e": "f", "g": "h"}',
105
        'result': '{"i": "j", "k": "l"}',
106
        'published': '{"k": "l"}'
107
    }
108
]
109
110
MOCK_WF_EX_TASKS = [
111
    tasks.Task(None, MOCK_WF_EX_TASKS_DATA[0]),
112
    tasks.Task(None, MOCK_WF_EX_TASKS_DATA[1])
113
]
114
115
MOCK_QRY_CONTEXT = {
116
    'mistral': {
117
        'execution_id': uuid.uuid4().hex
118
    }
119
}
120
121
MOCK_LIVEACTION_RESULT = {
122
    'tasks': [
123
        {
124
            'id': MOCK_WF_EX_TASKS_DATA[0]['id'],
125
            'name': MOCK_WF_EX_TASKS_DATA[0]['name'],
126
            'workflow_execution_id': MOCK_WF_EX_TASKS_DATA[0]['workflow_execution_id'],
127
            'workflow_name': MOCK_WF_EX_TASKS_DATA[0]['workflow_name'],
128
            'created_at': MOCK_WF_EX_TASKS_DATA[0]['created_at'],
129
            'updated_at': MOCK_WF_EX_TASKS_DATA[0]['updated_at'],
130
            'state': MOCK_WF_EX_TASKS_DATA[0]['state'],
131
            'state_info': MOCK_WF_EX_TASKS_DATA[0]['state_info'],
132
            'input': json.loads(MOCK_WF_EX_TASKS_DATA[0]['input']),
133
            'result': json.loads(MOCK_WF_EX_TASKS_DATA[0]['result']),
134
            'published': json.loads(MOCK_WF_EX_TASKS_DATA[0]['published'])
135
        }
136
    ]
137
}
138
139
MOCK_WF_EX_INCOMPLETE_TASKS_DATA = [
140
    {
141
        'id': uuid.uuid4().hex,
142
        'name': 'task1',
143
        'workflow_execution_id': MOCK_WF_EX_DATA['id'],
144
        'workflow_name': MOCK_WF_EX_DATA['name'],
145
        'created_at': str(datetime.datetime.utcnow() - datetime.timedelta(seconds=180)),
146
        'updated_at': str(datetime.datetime.utcnow()),
147
        'state': 'RUNNING',
148
        'state_info': None,
149
        'input': '{"a": "b"}',
150
        'result': '{"c": "d"}',
151
        'published': '{"c": "d"}'
152
    },
153
    {
154
        'id': uuid.uuid4().hex,
155
        'name': 'task2',
156
        'workflow_execution_id': MOCK_WF_EX_DATA['id'],
157
        'workflow_name': MOCK_WF_EX_DATA['name'],
158
        'created_at': str(datetime.datetime.utcnow() - datetime.timedelta(seconds=180)),
159
        'updated_at': str(datetime.datetime.utcnow()),
160
        'state': 'RUNNING',
161
        'state_info': None,
162
        'input': '{"e": "f", "g": "h"}',
163
        'result': '{"i": "j", "k": "l"}',
164
        'published': '{"k": "l"}'
165
    }
166
]
167
168
MOCK_WF_EX_INCOMPLETE_TASKS = [
169
    tasks.Task(None, MOCK_WF_EX_INCOMPLETE_TASKS_DATA[0]),
170
    tasks.Task(None, MOCK_WF_EX_INCOMPLETE_TASKS_DATA[1])
171
]
172
173
MOCK_LIVEACTION_OUTDATED_INCOMPLETE_TASKS_RESULT = {
174
    'tasks': [
175
        {
176
            'id': MOCK_WF_EX_INCOMPLETE_TASKS_DATA[0]['id'],
177
            'name': MOCK_WF_EX_INCOMPLETE_TASKS_DATA[0]['name'],
178
            'workflow_execution_id': MOCK_WF_EX_INCOMPLETE_TASKS_DATA[0]['workflow_execution_id'],
179
            'workflow_name': MOCK_WF_EX_INCOMPLETE_TASKS_DATA[0]['workflow_name'],
180
            'created_at': MOCK_WF_EX_INCOMPLETE_TASKS_DATA[0]['created_at'],
181
            'updated_at': str(datetime.datetime.utcnow() - datetime.timedelta(seconds=120)),
182
            'state': MOCK_WF_EX_INCOMPLETE_TASKS_DATA[0]['state'],
183
            'state_info': MOCK_WF_EX_INCOMPLETE_TASKS_DATA[0]['state_info'],
184
            'input': json.loads(MOCK_WF_EX_INCOMPLETE_TASKS_DATA[0]['input']),
185
            'result': json.loads(MOCK_WF_EX_INCOMPLETE_TASKS_DATA[0]['result']),
186
            'published': json.loads(MOCK_WF_EX_INCOMPLETE_TASKS_DATA[0]['published'])
187
        }
188
    ]
189
}
190
191
MOCK_LIVEACTION_UP_TO_DATE_INCOMPLETE_TASKS_RESULT = {
192
    'tasks': [
193
        {
194
            'id': MOCK_WF_EX_INCOMPLETE_TASKS_DATA[0]['id'],
195
            'name': MOCK_WF_EX_INCOMPLETE_TASKS_DATA[0]['name'],
196
            'workflow_execution_id': MOCK_WF_EX_INCOMPLETE_TASKS_DATA[0]['workflow_execution_id'],
197
            'workflow_name': MOCK_WF_EX_INCOMPLETE_TASKS_DATA[0]['workflow_name'],
198
            'created_at': MOCK_WF_EX_INCOMPLETE_TASKS_DATA[0]['created_at'],
199
            'updated_at': MOCK_WF_EX_INCOMPLETE_TASKS_DATA[0]['updated_at'],
200
            'state': MOCK_WF_EX_INCOMPLETE_TASKS_DATA[0]['state'],
201
            'state_info': MOCK_WF_EX_INCOMPLETE_TASKS_DATA[0]['state_info'],
202
            'input': json.loads(MOCK_WF_EX_INCOMPLETE_TASKS_DATA[0]['input']),
203
            'result': json.loads(MOCK_WF_EX_INCOMPLETE_TASKS_DATA[0]['result']),
204
            'published': json.loads(MOCK_WF_EX_INCOMPLETE_TASKS_DATA[0]['published'])
205
        }
206
    ]
207
}
208
209
MOCK_CHILD_ACTIONEXECUTION_REQUESTED = ActionExecutionDB(
210
    action={'ref': 'mock.task'},
211
    runner={'name': 'local_runner'},
212
    liveaction={'id': uuid.uuid4().hex},
213
    status=action_constants.LIVEACTION_STATUS_REQUESTED,
214
    children=[]
215
)
216
217
MOCK_CHILD_ACTIONEXECUTION_RUNNING = ActionExecutionDB(
218
    action={'ref': 'mock.task'},
219
    runner={'name': 'local_runner'},
220
    liveaction={'id': uuid.uuid4().hex},
221
    status=action_constants.LIVEACTION_STATUS_RUNNING,
222
    children=[]
223
)
224
225
MOCK_CHILD_ACTIONEXECUTION_SUCCEEDED = ActionExecutionDB(
226
    action={'ref': 'mock.task'},
227
    runner={'name': 'local_runner'},
228
    liveaction={'id': uuid.uuid4().hex},
229
    status=action_constants.LIVEACTION_STATUS_SUCCEEDED,
230
    children=[]
231
)
232
233
MOCK_CHILD_ACTIONEXECUTION_PAUSED = ActionExecutionDB(
234
    action={'ref': 'mock.task'},
235
    runner={'name': 'mistral_v2'},
236
    liveaction={'id': uuid.uuid4().hex},
237
    status=action_constants.LIVEACTION_STATUS_PAUSED,
238
    children=[]
239
)
240
241
MOCK_LIVEACTION_RUNNING = LiveActionDB(
242
    action='mock.workflow',
243
    status=action_constants.LIVEACTION_STATUS_RUNNING
244
)
245
246
MOCK_ACTIONEXECUTION_RUNNING_CHILD_REQUESTED = ActionExecutionDB(
247
    action={'ref': 'mock.workflow'},
248
    runner={'name': 'mistral_v2'},
249
    liveaction={'id': MOCK_LIVEACTION_RUNNING.id},
250
    status=action_constants.LIVEACTION_STATUS_RUNNING,
251
    children=[MOCK_CHILD_ACTIONEXECUTION_REQUESTED.id]
252
)
253
254
MOCK_ACTIONEXECUTION_RUNNING_CHILD_RUNNING = ActionExecutionDB(
255
    action={'ref': 'mock.workflow'},
256
    runner={'name': 'mistral_v2'},
257
    liveaction={'id': MOCK_LIVEACTION_RUNNING.id},
258
    status=action_constants.LIVEACTION_STATUS_RUNNING,
259
    children=[MOCK_CHILD_ACTIONEXECUTION_RUNNING.id]
260
)
261
262
MOCK_ACTIONEXECUTION_RUNNING_CHILD_SUCCEEDED = ActionExecutionDB(
263
    action={'ref': 'mock.workflow'},
264
    runner={'name': 'mistral_v2'},
265
    liveaction={'id': MOCK_LIVEACTION_RUNNING.id},
266
    status=action_constants.LIVEACTION_STATUS_RUNNING,
267
    children=[MOCK_CHILD_ACTIONEXECUTION_SUCCEEDED.id]
268
)
269
270
MOCK_LIVEACTION_RUNNING_WITH_STREAMING_RESULT = LiveActionDB(
271
    action='mock.workflow',
272
    status=action_constants.LIVEACTION_STATUS_RUNNING,
273
    result=MOCK_LIVEACTION_RESULT
274
)
275
276
MOCK_LIVEACTION_RUNNING_WITH_OUTDATED_INCOMPLETE_TASKS_STREAMING_RESULT = LiveActionDB(
277
    action='mock.workflow',
278
    status=action_constants.LIVEACTION_STATUS_RUNNING,
279
    result=MOCK_LIVEACTION_OUTDATED_INCOMPLETE_TASKS_RESULT
280
)
281
282
MOCK_LIVEACTION_RUNNING_WITH_UP_TO_DATE_INCOMPLETE_TASKS_STREAMING_RESULT = LiveActionDB(
283
    action='mock.workflow',
284
    status=action_constants.LIVEACTION_STATUS_RUNNING,
285
    result=MOCK_LIVEACTION_UP_TO_DATE_INCOMPLETE_TASKS_RESULT
286
)
287
288
MOCK_LIVEACTION_CANCELING = LiveActionDB(
289
    action='mock.workflow',
290
    status=action_constants.LIVEACTION_STATUS_CANCELING
291
)
292
293
MOCK_ACTIONEXECUTION_CANCELING_CHILD_RUNNING = ActionExecutionDB(
294
    action={'ref': 'mock.workflow'},
295
    runner={'name': 'mistral_v2'},
296
    liveaction={'id': MOCK_LIVEACTION_CANCELING.id},
297
    status=action_constants.LIVEACTION_STATUS_CANCELING,
298
    children=[MOCK_CHILD_ACTIONEXECUTION_RUNNING.id]
299
)
300
301
MOCK_ACTIONEXECUTION_CANCELING_CHILD_SUCCEEDED = ActionExecutionDB(
302
    action={'ref': 'mock.workflow'},
303
    runner={'name': 'mistral_v2'},
304
    liveaction={'id': MOCK_LIVEACTION_CANCELING.id},
305
    status=action_constants.LIVEACTION_STATUS_CANCELING,
306
    children=[MOCK_CHILD_ACTIONEXECUTION_SUCCEEDED.id]
307
)
308
309
MOCK_ACTIONEXECUTION_CANCELING_CHILD_PAUSED = ActionExecutionDB(
310
    action={'ref': 'mock.workflow'},
311
    runner={'name': 'mistral_v2'},
312
    liveaction={'id': MOCK_LIVEACTION_CANCELING.id},
313
    status=action_constants.LIVEACTION_STATUS_CANCELING,
314
    children=[MOCK_CHILD_ACTIONEXECUTION_PAUSED.id]
315
)
316
317
MOCK_LIVEACTION_PAUSING = LiveActionDB(
318
    action='mock.workflow',
319
    status=action_constants.LIVEACTION_STATUS_PAUSING
320
)
321
322
MOCK_ACTIONEXECUTION_PAUSING = ActionExecutionDB(
323
    action={'ref': 'mock.workflow'},
324
    runner={'name': 'mistral_v2'},
325
    liveaction={'id': MOCK_LIVEACTION_PAUSING.id},
326
    status=action_constants.LIVEACTION_STATUS_PAUSING,
327
    children=[]
328
)
329
330
MOCK_ACTIONEXECUTION_PAUSING_CHILD_RUNNING = ActionExecutionDB(
331
    action={'ref': 'mock.workflow'},
332
    runner={'name': 'mistral_v2'},
333
    liveaction={'id': MOCK_LIVEACTION_PAUSING.id},
334
    status=action_constants.LIVEACTION_STATUS_PAUSING,
335
    children=[MOCK_CHILD_ACTIONEXECUTION_RUNNING.id]
336
)
337
338
MOCK_ACTIONEXECUTION_PAUSING_CHILD_PAUSED = ActionExecutionDB(
339
    action={'ref': 'mock.workflow'},
340
    runner={'name': 'mistral_v2'},
341
    liveaction={'id': MOCK_LIVEACTION_PAUSING.id},
342
    status=action_constants.LIVEACTION_STATUS_PAUSING,
343
    children=[MOCK_CHILD_ACTIONEXECUTION_PAUSED.id]
344
)
345
346
MOCK_LIVEACTION_RESUMING = LiveActionDB(
347
    action='mock.workflow',
348
    status=action_constants.LIVEACTION_STATUS_RESUMING
349
)
350
351
MOCK_ACTIONEXECUTION_RESUMING_CHILD_RUNNING = ActionExecutionDB(
352
    action={'ref': 'mock.workflow'},
353
    runner={'name': 'mistral_v2'},
354
    liveaction={'id': MOCK_LIVEACTION_RESUMING.id},
355
    status=action_constants.LIVEACTION_STATUS_RESUMING,
356
    children=[MOCK_CHILD_ACTIONEXECUTION_RUNNING.id]
357
)
358
359
MOCK_ACTIONEXECUTION_RESUMING_CHILD_SUCCEEDED = ActionExecutionDB(
360
    action={'ref': 'mock.workflow'},
361
    runner={'name': 'mistral_v2'},
362
    liveaction={'id': MOCK_LIVEACTION_RESUMING.id},
363
    status=action_constants.LIVEACTION_STATUS_RESUMING,
364
    children=[MOCK_CHILD_ACTIONEXECUTION_SUCCEEDED.id]
365
)
366
367
368
class MistralQuerierTest(DbTestCase):
369
370
    @classmethod
371
    def setUpClass(cls):
372
        super(MistralQuerierTest, cls).setUpClass()
373
374
        # Override the retry configuration here otherwise st2tests.config.parse_args
375
        # in DbTestCase.setUpClass will reset these overrides.
376
        cfg.CONF.set_override('retry_exp_msec', 100, group='mistral')
377
        cfg.CONF.set_override('retry_exp_max_msec', 200, group='mistral')
378
        cfg.CONF.set_override('retry_stop_max_msec', 200, group='mistral')
379
380
        # Register query module.
381
        cls.query_module = loader.register_query_module('mistral_v2')
382
383
    def setUp(self):
384
        super(MistralQuerierTest, self).setUp()
385
        self.querier = self.query_module.get_instance()
386
387
    @mock.patch.object(
388
        ActionExecution, 'get',
389
        mock.MagicMock(side_effect=[
390
            MOCK_ACTIONEXECUTION_RUNNING_CHILD_RUNNING,
391
            MOCK_CHILD_ACTIONEXECUTION_RUNNING]))
392
    def test_determine_status_wf_running_exec_running_tasks_running(self):
393
        status = self.querier._determine_execution_status(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _determine_execution_status was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
394
            MOCK_LIVEACTION_RUNNING,
395
            'RUNNING',
396
            MOCK_WF_TASKS_RUNNING
397
        )
398
399
        self.assertEqual(action_constants.LIVEACTION_STATUS_RUNNING, status)
400
401
    @mock.patch.object(
402
        ActionExecution, 'get',
403
        mock.MagicMock(side_effect=[
404
            MOCK_ACTIONEXECUTION_RUNNING_CHILD_SUCCEEDED,
405
            MOCK_CHILD_ACTIONEXECUTION_SUCCEEDED]))
406
    def test_determine_status_wf_running_exec_running_tasks_completed(self):
407
        status = self.querier._determine_execution_status(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _determine_execution_status was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
408
            MOCK_LIVEACTION_RUNNING,
409
            'RUNNING',
410
            MOCK_WF_TASKS_SUCCEEDED
411
        )
412
413
        self.assertEqual(action_constants.LIVEACTION_STATUS_RUNNING, status)
414
415
    @mock.patch.object(
416
        ActionExecution, 'get',
417
        mock.MagicMock(side_effect=[
418
            MOCK_ACTIONEXECUTION_RUNNING_CHILD_SUCCEEDED,
419
            MOCK_CHILD_ACTIONEXECUTION_SUCCEEDED]))
420
    def test_determine_status_wf_running_exec_succeeded_tasks_completed(self):
421
        status = self.querier._determine_execution_status(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _determine_execution_status was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
422
            MOCK_LIVEACTION_RUNNING,
423
            'SUCCESS',
424
            MOCK_WF_TASKS_SUCCEEDED
425
        )
426
427
        self.assertEqual(action_constants.LIVEACTION_STATUS_SUCCEEDED, status)
428
429
    @mock.patch.object(
430
        ActionExecution, 'get',
431
        mock.MagicMock(side_effect=[
432
            MOCK_ACTIONEXECUTION_RUNNING_CHILD_RUNNING,
433
            MOCK_CHILD_ACTIONEXECUTION_RUNNING]))
434
    def test_determine_status_wf_running_exec_succeeded_tasks_running(self):
435
        status = self.querier._determine_execution_status(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _determine_execution_status was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
436
            MOCK_LIVEACTION_RUNNING,
437
            'SUCCESS',
438
            MOCK_WF_TASKS_RUNNING
439
        )
440
441
        self.assertEqual(action_constants.LIVEACTION_STATUS_RUNNING, status)
442
443
    @mock.patch.object(
444
        ActionExecution, 'get',
445
        mock.MagicMock(side_effect=[
446
            MOCK_ACTIONEXECUTION_RUNNING_CHILD_RUNNING,
447
            MOCK_CHILD_ACTIONEXECUTION_RUNNING]))
448
    def test_determine_status_wf_running_exec_succeeded_tasks_completed_child_running(self):
449
        status = self.querier._determine_execution_status(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _determine_execution_status was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
450
            MOCK_LIVEACTION_RUNNING,
451
            'SUCCESS',
452
            MOCK_WF_TASKS_SUCCEEDED
453
        )
454
455
        self.assertEqual(action_constants.LIVEACTION_STATUS_RUNNING, status)
456
457
    @mock.patch.object(
458
        ActionExecution, 'get',
459
        mock.MagicMock(side_effect=[
460
            MOCK_ACTIONEXECUTION_RUNNING_CHILD_SUCCEEDED,
461
            MOCK_CHILD_ACTIONEXECUTION_SUCCEEDED]))
462
    def test_determine_status_wf_running_exec_failed_tasks_completed(self):
463
        status = self.querier._determine_execution_status(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _determine_execution_status was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
464
            MOCK_LIVEACTION_RUNNING,
465
            'ERROR',
466
            MOCK_WF_TASKS_SUCCEEDED
467
        )
468
469
        self.assertEqual(action_constants.LIVEACTION_STATUS_FAILED, status)
470
471
    @mock.patch.object(
472
        ActionExecution, 'get',
473
        mock.MagicMock(side_effect=[
474
            MOCK_ACTIONEXECUTION_RUNNING_CHILD_RUNNING,
475
            MOCK_CHILD_ACTIONEXECUTION_RUNNING]))
476
    def test_determine_status_wf_running_exec_failed_tasks_running(self):
477
        status = self.querier._determine_execution_status(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _determine_execution_status was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
478
            MOCK_LIVEACTION_RUNNING,
479
            'ERROR',
480
            MOCK_WF_TASKS_RUNNING
481
        )
482
483
        self.assertEqual(action_constants.LIVEACTION_STATUS_RUNNING, status)
484
485
    @mock.patch.object(
486
        ActionExecution, 'get',
487
        mock.MagicMock(side_effect=[
488
            MOCK_ACTIONEXECUTION_CANCELING_CHILD_SUCCEEDED,
489
            MOCK_CHILD_ACTIONEXECUTION_SUCCEEDED]))
490
    def test_determine_status_wf_canceling_exec_canceled_tasks_completed(self):
491
        status = self.querier._determine_execution_status(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _determine_execution_status was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
492
            MOCK_LIVEACTION_CANCELING,
493
            'CANCELLED',
494
            MOCK_WF_TASKS_SUCCEEDED
495
        )
496
497
        self.assertEqual(action_constants.LIVEACTION_STATUS_CANCELED, status)
498
499
    @mock.patch.object(
500
        ActionExecution, 'get',
501
        mock.MagicMock(side_effect=[
502
            MOCK_ACTIONEXECUTION_CANCELING_CHILD_RUNNING,
503
            MOCK_CHILD_ACTIONEXECUTION_RUNNING]))
504
    def test_determine_status_wf_canceling_exec_canceled_tasks_running(self):
505
        status = self.querier._determine_execution_status(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _determine_execution_status was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
506
            MOCK_LIVEACTION_CANCELING,
507
            'CANCELLED',
508
            MOCK_WF_TASKS_RUNNING
509
        )
510
511
        self.assertEqual(action_constants.LIVEACTION_STATUS_CANCELING, status)
512
513
    @mock.patch.object(
514
        ActionExecution, 'get',
515
        mock.MagicMock(side_effect=[
516
            MOCK_ACTIONEXECUTION_CANCELING_CHILD_SUCCEEDED,
517
            MOCK_CHILD_ACTIONEXECUTION_SUCCEEDED]))
518
    def test_determine_status_wf_canceling_exec_canceled_tasks_waiting(self):
519
        status = self.querier._determine_execution_status(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _determine_execution_status was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
520
            MOCK_LIVEACTION_CANCELING,
521
            'CANCELLED',
522
            MOCK_WF_TASKS_WAITING
523
        )
524
525
        self.assertEqual(action_constants.LIVEACTION_STATUS_CANCELED, status)
526
527
    @mock.patch.object(
528
        ActionExecution, 'get',
529
        mock.MagicMock(side_effect=[
530
            MOCK_ACTIONEXECUTION_CANCELING_CHILD_PAUSED,
531
            MOCK_CHILD_ACTIONEXECUTION_PAUSED]))
532
    def test_determine_status_wf_canceling_exec_canceled_tasks_paused(self):
533
        status = self.querier._determine_execution_status(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _determine_execution_status was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
534
            MOCK_LIVEACTION_CANCELING,
535
            'CANCELLED',
536
            MOCK_WF_TASKS_PAUSED
537
        )
538
539
        self.assertEqual(action_constants.LIVEACTION_STATUS_CANCELED, status)
540
541
    @mock.patch.object(
542
        ActionExecution, 'get',
543
        mock.MagicMock(side_effect=[
544
            MOCK_ACTIONEXECUTION_CANCELING_CHILD_SUCCEEDED,
545
            MOCK_CHILD_ACTIONEXECUTION_SUCCEEDED]))
546
    def test_determine_status_wf_canceling_exec_running_tasks_completed(self):
547
        status = self.querier._determine_execution_status(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _determine_execution_status was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
548
            MOCK_LIVEACTION_CANCELING,
549
            'RUNNING',
550
            MOCK_WF_TASKS_SUCCEEDED
551
        )
552
553
        self.assertEqual(action_constants.LIVEACTION_STATUS_CANCELING, status)
554
555
    @mock.patch.object(
556
        ActionExecution, 'get',
557
        mock.MagicMock(side_effect=[
558
            MOCK_ACTIONEXECUTION_CANCELING_CHILD_RUNNING,
559
            MOCK_CHILD_ACTIONEXECUTION_RUNNING]))
560
    def test_determine_status_wf_canceling_exec_running_tasks_running(self):
561
        status = self.querier._determine_execution_status(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _determine_execution_status was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
562
            MOCK_LIVEACTION_CANCELING,
563
            'RUNNING',
564
            MOCK_WF_TASKS_RUNNING
565
        )
566
567
        self.assertEqual(action_constants.LIVEACTION_STATUS_CANCELING, status)
568
569
    @mock.patch.object(
570
        ActionExecution, 'get',
571
        mock.MagicMock(side_effect=[
572
            MOCK_ACTIONEXECUTION_CANCELING_CHILD_SUCCEEDED,
573
            MOCK_CHILD_ACTIONEXECUTION_SUCCEEDED]))
574
    def test_determine_status_wf_canceling_exec_running_tasks_waiting(self):
575
        status = self.querier._determine_execution_status(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _determine_execution_status was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
576
            MOCK_LIVEACTION_CANCELING,
577
            'RUNNING',
578
            MOCK_WF_TASKS_WAITING
579
        )
580
581
        self.assertEqual(action_constants.LIVEACTION_STATUS_CANCELING, status)
582
583
    @mock.patch.object(
584
        ActionExecution, 'get',
585
        mock.MagicMock(side_effect=[
586
            MOCK_ACTIONEXECUTION_RUNNING_CHILD_RUNNING,
587
            MOCK_CHILD_ACTIONEXECUTION_RUNNING]))
588
    def test_determine_status_wf_running_exec_cancelled_tasks_running(self):
589
        status = self.querier._determine_execution_status(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _determine_execution_status was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
590
            MOCK_LIVEACTION_RUNNING,
591
            'CANCELLED',
592
            MOCK_WF_TASKS_RUNNING
593
        )
594
595
        self.assertEqual(action_constants.LIVEACTION_STATUS_CANCELING, status)
596
597
    @mock.patch.object(
598
        ActionExecution, 'get',
599
        mock.MagicMock(side_effect=[
600
            MOCK_ACTIONEXECUTION_PAUSING_CHILD_PAUSED,
601
            MOCK_CHILD_ACTIONEXECUTION_PAUSED]))
602
    def test_determine_status_wf_pausing_exec_paused_tasks_completed(self):
603
        status = self.querier._determine_execution_status(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _determine_execution_status was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
604
            MOCK_LIVEACTION_PAUSING,
605
            'PAUSED',
606
            MOCK_WF_TASKS_SUCCEEDED
607
        )
608
609
        self.assertEqual(action_constants.LIVEACTION_STATUS_PAUSED, status)
610
611
    @mock.patch.object(
612
        ActionExecution, 'get',
613
        mock.MagicMock(side_effect=[
614
            MOCK_ACTIONEXECUTION_PAUSING_CHILD_RUNNING,
615
            MOCK_CHILD_ACTIONEXECUTION_RUNNING]))
616
    def test_determine_status_wf_pausing_exec_paused_tasks_completed_child_running(self):
617
        status = self.querier._determine_execution_status(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _determine_execution_status was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
618
            MOCK_LIVEACTION_PAUSING,
619
            'PAUSED',
620
            MOCK_WF_TASKS_SUCCEEDED
621
        )
622
623
        self.assertEqual(action_constants.LIVEACTION_STATUS_PAUSING, status)
624
625
    @mock.patch.object(
626
        ActionExecution, 'get',
627
        mock.MagicMock(side_effect=[
628
            MOCK_ACTIONEXECUTION_PAUSING_CHILD_RUNNING,
629
            MOCK_CHILD_ACTIONEXECUTION_RUNNING]))
630
    def test_determine_status_wf_pausing_exec_paused_tasks_running(self):
631
        status = self.querier._determine_execution_status(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _determine_execution_status was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
632
            MOCK_LIVEACTION_PAUSING,
633
            'PAUSED',
634
            MOCK_WF_TASKS_RUNNING
635
        )
636
637
        self.assertEqual(action_constants.LIVEACTION_STATUS_PAUSING, status)
638
639
    @mock.patch.object(
640
        ActionExecution, 'get',
641
        mock.MagicMock(side_effect=[
642
            MOCK_ACTIONEXECUTION_PAUSING_CHILD_PAUSED,
643
            MOCK_CHILD_ACTIONEXECUTION_PAUSED]))
644
    def test_determine_status_wf_pausing_exec_paused_tasks_paused(self):
645
        status = self.querier._determine_execution_status(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _determine_execution_status was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
646
            MOCK_LIVEACTION_PAUSING,
647
            'PAUSED',
648
            MOCK_WF_TASKS_PAUSED
649
        )
650
651
        self.assertEqual(action_constants.LIVEACTION_STATUS_PAUSED, status)
652
653
    @mock.patch.object(
654
        ActionExecution, 'get',
655
        mock.MagicMock(side_effect=[
656
            MOCK_ACTIONEXECUTION_PAUSING_CHILD_RUNNING,
657
            MOCK_CHILD_ACTIONEXECUTION_RUNNING]))
658
    def test_determine_status_wf_pausing_exec_running_tasks_running(self):
659
        status = self.querier._determine_execution_status(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _determine_execution_status was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
660
            MOCK_LIVEACTION_PAUSING,
661
            'RUNNING',
662
            MOCK_WF_TASKS_RUNNING
663
        )
664
665
        self.assertEqual(action_constants.LIVEACTION_STATUS_PAUSING, status)
666
667
    @mock.patch.object(
668
        ActionExecution, 'get',
669
        mock.MagicMock(side_effect=[
670
            MOCK_ACTIONEXECUTION_RUNNING_CHILD_SUCCEEDED,
671
            MOCK_CHILD_ACTIONEXECUTION_SUCCEEDED]))
672
    def test_determine_status_wf_running_exec_paused_tasks_completed(self):
673
        status = self.querier._determine_execution_status(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _determine_execution_status was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
674
            MOCK_LIVEACTION_RUNNING,
675
            'PAUSED',
676
            MOCK_WF_TASKS_SUCCEEDED
677
        )
678
679
        self.assertEqual(action_constants.LIVEACTION_STATUS_PAUSED, status)
680
681
    @mock.patch.object(
682
        ActionExecution, 'get',
683
        mock.MagicMock(side_effect=[
684
            MOCK_ACTIONEXECUTION_RUNNING_CHILD_RUNNING,
685
            MOCK_CHILD_ACTIONEXECUTION_RUNNING]))
686
    def test_determine_status_wf_running_exec_paused_tasks_running(self):
687
        status = self.querier._determine_execution_status(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _determine_execution_status was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
688
            MOCK_LIVEACTION_RUNNING,
689
            'PAUSED',
690
            MOCK_WF_TASKS_RUNNING
691
        )
692
693
        self.assertEqual(action_constants.LIVEACTION_STATUS_PAUSING, status)
694
695
    @mock.patch.object(
696
        ActionExecution, 'get',
697
        mock.MagicMock(side_effect=[
698
            MOCK_ACTIONEXECUTION_RESUMING_CHILD_SUCCEEDED,
699
            MOCK_CHILD_ACTIONEXECUTION_SUCCEEDED]))
700
    def test_determine_status_wf_resuming_exec_paused_tasks_completed(self):
701
        status = self.querier._determine_execution_status(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _determine_execution_status was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
702
            MOCK_LIVEACTION_RESUMING,
703
            'PAUSED',
704
            MOCK_WF_TASKS_SUCCEEDED
705
        )
706
707
        self.assertEqual(action_constants.LIVEACTION_STATUS_RESUMING, status)
708
709
    @mock.patch.object(
710
        ActionExecution, 'get',
711
        mock.MagicMock(side_effect=[
712
            MOCK_ACTIONEXECUTION_RESUMING_CHILD_SUCCEEDED,
713
            MOCK_CHILD_ACTIONEXECUTION_SUCCEEDED]))
714
    def test_determine_status_wf_resuming_exec_running_tasks_completed(self):
715
        status = self.querier._determine_execution_status(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _determine_execution_status was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
716
            MOCK_LIVEACTION_RESUMING,
717
            'RUNNING',
718
            MOCK_WF_TASKS_SUCCEEDED
719
        )
720
721
        self.assertEqual(action_constants.LIVEACTION_STATUS_RUNNING, status)
722
723
    @mock.patch.object(
724
        ActionExecution, 'get',
725
        mock.MagicMock(side_effect=[
726
            MOCK_ACTIONEXECUTION_RESUMING_CHILD_RUNNING,
727
            MOCK_CHILD_ACTIONEXECUTION_RUNNING]))
728
    def test_determine_status_wf_resuming_exec_running_tasks_running(self):
729
        status = self.querier._determine_execution_status(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _determine_execution_status was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
730
            MOCK_LIVEACTION_RESUMING,
731
            'RUNNING',
732
            MOCK_WF_TASKS_RUNNING
733
        )
734
735
        self.assertEqual(action_constants.LIVEACTION_STATUS_RUNNING, status)
736
737
    @mock.patch.object(
738
        ActionExecution, 'get',
739
        mock.MagicMock(side_effect=[
740
            MOCK_ACTIONEXECUTION_RESUMING_CHILD_RUNNING,
741
            MOCK_CHILD_ACTIONEXECUTION_RUNNING]))
742
    def test_determine_status_wf_resuming_exec_paused_tasks_running(self):
743
        status = self.querier._determine_execution_status(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _determine_execution_status was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
744
            MOCK_LIVEACTION_RESUMING,
745
            'PAUSED',
746
            MOCK_WF_TASKS_RUNNING
747
        )
748
749
        self.assertEqual(action_constants.LIVEACTION_STATUS_PAUSING, status)
750
751
    @mock.patch.object(
752
        ActionExecution, 'get',
753
        mock.MagicMock(side_effect=[
754
            MOCK_ACTIONEXECUTION_RESUMING_CHILD_RUNNING,
755
            MOCK_CHILD_ACTIONEXECUTION_RUNNING]))
756
    def test_determine_status_wf_resuming_exec_canceled_tasks_running(self):
757
        status = self.querier._determine_execution_status(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _determine_execution_status was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
758
            MOCK_LIVEACTION_RESUMING,
759
            'CANCELLED',
760
            MOCK_WF_TASKS_RUNNING
761
        )
762
763
        self.assertEqual(action_constants.LIVEACTION_STATUS_CANCELING, status)
764
765
    @mock.patch.object(
766
        executions.ExecutionManager, 'get',
767
        mock.MagicMock(return_value=MOCK_WF_EX))
768
    def test_get_workflow_result(self):
769
        result = self.querier._get_workflow_result(uuid.uuid4().hex, uuid.uuid4().hex)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _get_workflow_result was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
770
771
        expected = {
772
            'k1': 'v1',
773
            'extra': {
774
                'state': MOCK_WF_EX.state,
775
                'state_info': MOCK_WF_EX.state_info
776
            }
777
        }
778
779
        self.assertDictEqual(expected, result)
780
781
    @mock.patch.object(
782
        tasks.TaskManager, 'list',
783
        mock.MagicMock(return_value=MOCK_WF_EX_TASKS))
784
    @mock.patch.object(
785
        tasks.TaskManager, 'get',
786
        mock.MagicMock(side_effect=[
787
            MOCK_WF_EX_TASKS[0],
788
            MOCK_WF_EX_TASKS[1]]))
789
    def test_get_workflow_tasks(self):
790
        tasks = self.querier._get_workflow_tasks(uuid.uuid4().hex, uuid.uuid4().hex)
0 ignored issues
show
Comprehensibility Bug introduced by
tasks is re-defining a name which is already available in the outer-scope (previously defined on line 29).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
Coding Style Best Practice introduced by
It seems like _get_workflow_tasks was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
791
792
        expected = copy.deepcopy(MOCK_WF_EX_TASKS_DATA)
793
        for task in expected:
794
            task['input'] = json.loads(task['input'])
795
            task['result'] = json.loads(task['result'])
796
            task['published'] = json.loads(task['published'])
797
798
        for i in range(0, len(tasks)):
799
            self.assertDictEqual(expected[i], tasks[i])
800
801
    @mock.patch.object(
802
        action_utils, 'get_liveaction_by_id',
803
        mock.MagicMock(return_value=MOCK_LIVEACTION_RUNNING))
804
    @mock.patch.object(
805
        executions.ExecutionManager, 'get',
806
        mock.MagicMock(return_value=MOCK_WF_EX))
807
    @mock.patch.object(
808
        tasks.TaskManager, 'list',
809
        mock.MagicMock(return_value=MOCK_WF_EX_TASKS))
810
    @mock.patch.object(
811
        tasks.TaskManager, 'get',
812
        mock.MagicMock(side_effect=[
813
            MOCK_WF_EX_TASKS[0],
814
            MOCK_WF_EX_TASKS[1]]))
815
    @mock.patch.object(
816
        ActionExecution, 'get',
817
        mock.MagicMock(side_effect=[
818
            MOCK_ACTIONEXECUTION_RUNNING_CHILD_SUCCEEDED,
819
            MOCK_CHILD_ACTIONEXECUTION_SUCCEEDED]))
820
    def test_query(self):
821
        (status, result) = self.querier.query(uuid.uuid4().hex, MOCK_QRY_CONTEXT)
822
823
        expected = {
824
            'k1': 'v1',
825
            'tasks': copy.deepcopy(MOCK_WF_EX_TASKS_DATA),
826
            'extra': {
827
                'state': MOCK_WF_EX.state,
828
                'state_info': MOCK_WF_EX.state_info
829
            }
830
        }
831
832
        for task in expected['tasks']:
833
            task['input'] = json.loads(task['input'])
834
            task['result'] = json.loads(task['result'])
835
            task['published'] = json.loads(task['published'])
836
837
        self.assertEqual(action_constants.LIVEACTION_STATUS_SUCCEEDED, status)
838
        self.assertDictEqual(expected, result)
839
840
    @mock.patch.object(
841
        action_utils, 'get_liveaction_by_id',
842
        mock.MagicMock(return_value=MOCK_LIVEACTION_RUNNING_WITH_STREAMING_RESULT))
843
    @mock.patch.object(
844
        executions.ExecutionManager, 'get',
845
        mock.MagicMock(return_value=MOCK_WF_EX))
846
    @mock.patch.object(
847
        tasks.TaskManager, 'list',
848
        mock.MagicMock(return_value=[MOCK_WF_EX_TASKS[1]]))
849
    @mock.patch.object(
850
        tasks.TaskManager, 'get',
851
        mock.MagicMock(return_value=MOCK_WF_EX_TASKS[1]))
852
    @mock.patch.object(
853
        ActionExecution, 'get',
854
        mock.MagicMock(side_effect=[
855
            MOCK_ACTIONEXECUTION_RUNNING_CHILD_SUCCEEDED,
856
            MOCK_CHILD_ACTIONEXECUTION_SUCCEEDED]))
857
    def test_query_with_last_query_time(self):
858
        last_query_time = time.time() - 3
859
860
        (status, result) = self.querier.query(
861
            uuid.uuid4().hex,
862
            MOCK_QRY_CONTEXT,
863
            last_query_time=last_query_time
864
        )
865
866
        expected = {
867
            'k1': 'v1',
868
            'tasks': copy.deepcopy(MOCK_WF_EX_TASKS_DATA),
869
            'extra': {
870
                'state': MOCK_WF_EX.state,
871
                'state_info': MOCK_WF_EX.state_info
872
            }
873
        }
874
875
        for task in expected['tasks']:
876
            task['input'] = json.loads(task['input'])
877
            task['result'] = json.loads(task['result'])
878
            task['published'] = json.loads(task['published'])
879
880
        self.assertEqual(action_constants.LIVEACTION_STATUS_SUCCEEDED, status)
881
        self.assertDictEqual(expected, result)
882
883
    @mock.patch.object(
884
        action_utils, 'get_liveaction_by_id',
885
        mock.MagicMock(side_effect=db_exc.StackStormDBObjectNotFoundError()))
886
    def test_query_liveaction_not_found(self):
887
        self.assertRaises(
888
            db_exc.StackStormDBObjectNotFoundError,
889
            self.querier.query,
890
            uuid.uuid4().hex,
891
            MOCK_QRY_CONTEXT
892
        )
893
894
    @mock.patch.object(
895
        action_utils, 'get_liveaction_by_id',
896
        mock.MagicMock(return_value=MOCK_LIVEACTION_RUNNING))
897
    @mock.patch.object(
898
        executions.ExecutionManager, 'get',
899
        mock.MagicMock(side_effect=[
900
            requests.exceptions.ConnectionError(),
901
            MOCK_WF_EX]))
902
    @mock.patch.object(
903
        tasks.TaskManager, 'list',
904
        mock.MagicMock(return_value=MOCK_WF_EX_TASKS))
905
    @mock.patch.object(
906
        tasks.TaskManager, 'get',
907
        mock.MagicMock(side_effect=[
908
            MOCK_WF_EX_TASKS[0],
909
            MOCK_WF_EX_TASKS[1]]))
910
    @mock.patch.object(
911
        ActionExecution, 'get',
912
        mock.MagicMock(side_effect=[
913
            MOCK_ACTIONEXECUTION_RUNNING_CHILD_SUCCEEDED,
914
            MOCK_CHILD_ACTIONEXECUTION_SUCCEEDED]))
915
    def test_query_get_workflow_retry(self):
916
        (status, result) = self.querier.query(uuid.uuid4().hex, MOCK_QRY_CONTEXT)
917
918
        expected = {
919
            'k1': 'v1',
920
            'tasks': copy.deepcopy(MOCK_WF_EX_TASKS_DATA),
921
            'extra': {
922
                'state': MOCK_WF_EX.state,
923
                'state_info': MOCK_WF_EX.state_info
924
            }
925
        }
926
927
        for task in expected['tasks']:
928
            task['input'] = json.loads(task['input'])
929
            task['result'] = json.loads(task['result'])
930
            task['published'] = json.loads(task['published'])
931
932
        self.assertEqual(action_constants.LIVEACTION_STATUS_SUCCEEDED, status)
933
        self.assertDictEqual(expected, result)
934
935
        calls = [call(MOCK_QRY_CONTEXT['mistral']['execution_id']) for i in range(0, 2)]
936
        executions.ExecutionManager.get.assert_has_calls(calls)
937
938
    @mock.patch.object(
939
        action_utils, 'get_liveaction_by_id',
940
        mock.MagicMock(return_value=MOCK_LIVEACTION_RUNNING))
941
    @mock.patch.object(
942
        executions.ExecutionManager, 'get',
943
        mock.MagicMock(side_effect=[requests.exceptions.ConnectionError()] * 4))
944
    def test_query_get_workflow_retry_exhausted(self):
945
        self.assertRaises(
946
            requests.exceptions.ConnectionError,
947
            self.querier.query,
948
            uuid.uuid4().hex,
949
            MOCK_QRY_CONTEXT)
950
951
        calls = [call(MOCK_QRY_CONTEXT['mistral']['execution_id']) for i in range(0, 2)]
952
        executions.ExecutionManager.get.assert_has_calls(calls)
953
954
    @mock.patch.object(
955
        action_utils, 'get_liveaction_by_id',
956
        mock.MagicMock(return_value=MOCK_LIVEACTION_RUNNING))
957
    @mock.patch.object(
958
        executions.ExecutionManager, 'get',
959
        mock.MagicMock(
960
            side_effect=mistralclient_base.APIException(
961
                error_code=404, error_message='Workflow not found.')))
962
    def test_query_get_workflow_not_found(self):
963
        (status, result) = self.querier.query(uuid.uuid4().hex, MOCK_QRY_CONTEXT)
964
965
        self.assertEqual(action_constants.LIVEACTION_STATUS_FAILED, status)
966
        self.assertEqual('Workflow not found.', result)
967
968
    @mock.patch.object(
969
        action_utils, 'get_liveaction_by_id',
970
        mock.MagicMock(return_value=MOCK_LIVEACTION_RUNNING))
971
    @mock.patch.object(
972
        executions.ExecutionManager, 'get',
973
        mock.MagicMock(return_value=MOCK_WF_EX))
974
    @mock.patch.object(
975
        tasks.TaskManager, 'list',
976
        mock.MagicMock(side_effect=[
977
            requests.exceptions.ConnectionError(),
978
            MOCK_WF_EX_TASKS]))
979
    @mock.patch.object(
980
        tasks.TaskManager, 'get',
981
        mock.MagicMock(side_effect=[
982
            MOCK_WF_EX_TASKS[0],
983
            MOCK_WF_EX_TASKS[1]]))
984
    @mock.patch.object(
985
        ActionExecution, 'get',
986
        mock.MagicMock(side_effect=[
987
            MOCK_ACTIONEXECUTION_RUNNING_CHILD_SUCCEEDED,
988
            MOCK_CHILD_ACTIONEXECUTION_SUCCEEDED]))
989
    def test_query_list_workflow_tasks_retry(self):
990
        (status, result) = self.querier.query(uuid.uuid4().hex, MOCK_QRY_CONTEXT)
991
992
        expected = {
993
            'k1': 'v1',
994
            'tasks': copy.deepcopy(MOCK_WF_EX_TASKS_DATA),
995
            'extra': {
996
                'state': MOCK_WF_EX.state,
997
                'state_info': MOCK_WF_EX.state_info
998
            }
999
        }
1000
1001
        for task in expected['tasks']:
1002
            task['input'] = json.loads(task['input'])
1003
            task['result'] = json.loads(task['result'])
1004
            task['published'] = json.loads(task['published'])
1005
1006
        self.assertEqual(action_constants.LIVEACTION_STATUS_SUCCEEDED, status)
1007
        self.assertDictEqual(expected, result)
1008
1009
        mock_call = call(workflow_execution_id=MOCK_QRY_CONTEXT['mistral']['execution_id'])
1010
        calls = [mock_call for i in range(0, 2)]
1011
        tasks.TaskManager.list.assert_has_calls(calls)
1012
1013
        calls = [call(MOCK_WF_EX_TASKS[0].id), call(MOCK_WF_EX_TASKS[1].id)]
1014
        tasks.TaskManager.get.assert_has_calls(calls)
1015
1016
    @mock.patch.object(
1017
        action_utils, 'get_liveaction_by_id',
1018
        mock.MagicMock(return_value=MOCK_LIVEACTION_RUNNING))
1019
    @mock.patch.object(
1020
        executions.ExecutionManager, 'get',
1021
        mock.MagicMock(return_value=MOCK_WF_EX))
1022
    @mock.patch.object(
1023
        tasks.TaskManager, 'list',
1024
        mock.MagicMock(return_value=MOCK_WF_EX_TASKS))
1025
    @mock.patch.object(
1026
        tasks.TaskManager, 'get',
1027
        mock.MagicMock(side_effect=[
1028
            requests.exceptions.ConnectionError(),
1029
            MOCK_WF_EX_TASKS[0],
1030
            MOCK_WF_EX_TASKS[1]]))
1031
    @mock.patch.object(
1032
        ActionExecution, 'get',
1033
        mock.MagicMock(side_effect=[
1034
            MOCK_ACTIONEXECUTION_RUNNING_CHILD_SUCCEEDED,
1035
            MOCK_CHILD_ACTIONEXECUTION_SUCCEEDED]))
1036
    def test_query_get_workflow_tasks_retry(self):
1037
        (status, result) = self.querier.query(uuid.uuid4().hex, MOCK_QRY_CONTEXT)
1038
1039
        expected = {
1040
            'k1': 'v1',
1041
            'tasks': copy.deepcopy(MOCK_WF_EX_TASKS_DATA),
1042
            'extra': {
1043
                'state': MOCK_WF_EX.state,
1044
                'state_info': MOCK_WF_EX.state_info
1045
            }
1046
        }
1047
1048
        for task in expected['tasks']:
1049
            task['input'] = json.loads(task['input'])
1050
            task['result'] = json.loads(task['result'])
1051
            task['published'] = json.loads(task['published'])
1052
1053
        self.assertEqual(action_constants.LIVEACTION_STATUS_SUCCEEDED, status)
1054
        self.assertDictEqual(expected, result)
1055
1056
        calls = [
1057
            call(MOCK_WF_EX_TASKS[0].id),
1058
            call(MOCK_WF_EX_TASKS[0].id),
1059
            call(MOCK_WF_EX_TASKS[1].id)
1060
        ]
1061
1062
        tasks.TaskManager.get.assert_has_calls(calls)
1063
1064
    @mock.patch.object(
1065
        action_utils, 'get_liveaction_by_id',
1066
        mock.MagicMock(return_value=MOCK_LIVEACTION_RUNNING))
1067
    @mock.patch.object(
1068
        executions.ExecutionManager, 'get',
1069
        mock.MagicMock(return_value=MOCK_WF_EX))
1070
    @mock.patch.object(
1071
        tasks.TaskManager, 'list',
1072
        mock.MagicMock(side_effect=[requests.exceptions.ConnectionError()] * 4))
1073
    def test_query_list_workflow_tasks_retry_exhausted(self):
1074
        self.assertRaises(
1075
            requests.exceptions.ConnectionError,
1076
            self.querier.query,
1077
            uuid.uuid4().hex,
1078
            MOCK_QRY_CONTEXT)
1079
1080
        mock_call = call(workflow_execution_id=MOCK_QRY_CONTEXT['mistral']['execution_id'])
1081
        calls = [mock_call for i in range(0, 2)]
1082
        tasks.TaskManager.list.assert_has_calls(calls)
1083
1084
    @mock.patch.object(
1085
        action_utils, 'get_liveaction_by_id',
1086
        mock.MagicMock(return_value=MOCK_LIVEACTION_RUNNING))
1087
    @mock.patch.object(
1088
        executions.ExecutionManager, 'get',
1089
        mock.MagicMock(return_value=MOCK_WF_EX))
1090
    @mock.patch.object(
1091
        tasks.TaskManager, 'list',
1092
        mock.MagicMock(return_value=MOCK_WF_EX_TASKS))
1093
    @mock.patch.object(
1094
        tasks.TaskManager, 'get',
1095
        mock.MagicMock(side_effect=[requests.exceptions.ConnectionError()] * 4))
1096
    def test_query_get_workflow_tasks_retry_exhausted(self):
1097
        self.assertRaises(
1098
            requests.exceptions.ConnectionError,
1099
            self.querier.query,
1100
            uuid.uuid4().hex,
1101
            MOCK_QRY_CONTEXT)
1102
1103
        calls = [
1104
            call(MOCK_WF_EX_TASKS[0].id),
1105
            call(MOCK_WF_EX_TASKS[0].id)
1106
        ]
1107
1108
        tasks.TaskManager.get.assert_has_calls(calls)
1109
1110
    @mock.patch.object(
1111
        action_utils, 'get_liveaction_by_id',
1112
        mock.MagicMock(return_value=MOCK_LIVEACTION_RUNNING))
1113
    @mock.patch.object(
1114
        executions.ExecutionManager, 'get',
1115
        mock.MagicMock(return_value=MOCK_WF_EX))
1116
    @mock.patch.object(
1117
        tasks.TaskManager, 'list',
1118
        mock.MagicMock(return_value=MOCK_WF_EX_TASKS))
1119
    @mock.patch.object(
1120
        tasks.TaskManager, 'get',
1121
        mock.MagicMock(
1122
            side_effect=mistralclient_base.APIException(
1123
                error_code=404, error_message='Task not found.')))
1124
    def test_query_get_workflow_tasks_not_found(self):
1125
        (status, result) = self.querier.query(uuid.uuid4().hex, MOCK_QRY_CONTEXT)
1126
1127
        self.assertEqual(action_constants.LIVEACTION_STATUS_FAILED, status)
1128
        self.assertEqual('Task not found.', result)
1129
1130
    def test_query_missing_context(self):
1131
        self.assertRaises(Exception, self.querier.query, uuid.uuid4().hex, {})
1132
1133
    def test_query_missing_mistral_execution_id(self):
1134
        self.assertRaises(Exception, self.querier.query, uuid.uuid4().hex, {'mistral': {}})
1135
1136
    @mock.patch.object(
1137
        action_utils, 'get_liveaction_by_id',
1138
        mock.MagicMock(
1139
            return_value=MOCK_LIVEACTION_RUNNING_WITH_OUTDATED_INCOMPLETE_TASKS_STREAMING_RESULT))
1140
    @mock.patch.object(
1141
        executions.ExecutionManager, 'get',
1142
        mock.MagicMock(return_value=MOCK_WF_EX))
1143
    @mock.patch.object(
1144
        tasks.TaskManager, 'list',
1145
        mock.MagicMock(return_value=MOCK_WF_EX_INCOMPLETE_TASKS))
1146
    @mock.patch.object(
1147
        tasks.TaskManager, 'get',
1148
        mock.MagicMock(side_effect=MOCK_WF_EX_INCOMPLETE_TASKS))
1149
    @mock.patch.object(
1150
        ActionExecution, 'get',
1151
        mock.MagicMock(side_effect=[
1152
            MOCK_ACTIONEXECUTION_RUNNING_CHILD_SUCCEEDED,
1153
            MOCK_CHILD_ACTIONEXECUTION_SUCCEEDED]))
1154
    def test_query_with_outdated_tasks_in_liveaction_result(self):
1155
        last_query_time = time.time() + 3
1156
1157
        (status, result) = self.querier.query(
1158
            uuid.uuid4().hex,
1159
            MOCK_QRY_CONTEXT,
1160
            last_query_time=last_query_time
1161
        )
1162
1163
        expected = {
1164
            'k1': 'v1',
1165
            'tasks': copy.deepcopy(MOCK_WF_EX_INCOMPLETE_TASKS_DATA),
1166
            'extra': {
1167
                'state': MOCK_WF_EX.state,
1168
                'state_info': MOCK_WF_EX.state_info
1169
            }
1170
        }
1171
1172
        for task in expected['tasks']:
1173
            task['input'] = json.loads(task['input'])
1174
            task['result'] = json.loads(task['result'])
1175
            task['published'] = json.loads(task['published'])
1176
1177
        self.assertEqual(action_constants.LIVEACTION_STATUS_RUNNING, status)
1178
        self.assertDictEqual(expected, result)
1179
1180
    @mock.patch.object(
1181
        action_utils, 'get_liveaction_by_id',
1182
        mock.MagicMock(
1183
            return_value=MOCK_LIVEACTION_RUNNING_WITH_UP_TO_DATE_INCOMPLETE_TASKS_STREAMING_RESULT))
1184
    @mock.patch.object(
1185
        executions.ExecutionManager, 'get',
1186
        mock.MagicMock(return_value=MOCK_WF_EX))
1187
    @mock.patch.object(
1188
        tasks.TaskManager, 'list',
1189
        mock.MagicMock(return_value=MOCK_WF_EX_INCOMPLETE_TASKS))
1190
    @mock.patch.object(
1191
        tasks.TaskManager, 'get',
1192
        mock.MagicMock(return_value=MOCK_WF_EX_INCOMPLETE_TASKS[1]))
1193
    @mock.patch.object(
1194
        ActionExecution, 'get',
1195
        mock.MagicMock(side_effect=[
1196
            MOCK_ACTIONEXECUTION_RUNNING_CHILD_SUCCEEDED,
1197
            MOCK_CHILD_ACTIONEXECUTION_SUCCEEDED]))
1198
    def test_query_with_up_to_date_tasks_in_liveaction_result(self):
1199
        last_query_time = time.time() + 3
1200
1201
        (status, result) = self.querier.query(
1202
            uuid.uuid4().hex,
1203
            MOCK_QRY_CONTEXT,
1204
            last_query_time=last_query_time
1205
        )
1206
1207
        expected = {
1208
            'k1': 'v1',
1209
            'tasks': copy.deepcopy(MOCK_WF_EX_INCOMPLETE_TASKS_DATA),
1210
            'extra': {
1211
                'state': MOCK_WF_EX.state,
1212
                'state_info': MOCK_WF_EX.state_info
1213
            }
1214
        }
1215
1216
        for task in expected['tasks']:
1217
            task['input'] = json.loads(task['input'])
1218
            task['result'] = json.loads(task['result'])
1219
            task['published'] = json.loads(task['published'])
1220
1221
        self.assertEqual(action_constants.LIVEACTION_STATUS_RUNNING, status)
1222
        self.assertDictEqual(expected, result)
1223
1224
    @mock.patch.object(
1225
        action_utils, 'get_liveaction_by_id',
1226
        mock.MagicMock(return_value=MOCK_LIVEACTION_RUNNING))
1227
    @mock.patch.object(
1228
        executions.ExecutionManager, 'get',
1229
        mock.MagicMock(return_value=MOCK_WF_EX))
1230
    @mock.patch.object(
1231
        tasks.TaskManager, 'list',
1232
        mock.MagicMock(return_value=MOCK_WF_EX_TASKS))
1233
    @mock.patch.object(
1234
        tasks.TaskManager, 'get',
1235
        mock.MagicMock(side_effect=[
1236
            MOCK_WF_EX_TASKS[0],
1237
            MOCK_WF_EX_TASKS[1]]))
1238
    @mock.patch.object(
1239
        ActionExecution, 'get',
1240
        mock.MagicMock(side_effect=[
1241
            MOCK_ACTIONEXECUTION_RUNNING_CHILD_REQUESTED,
1242
            MOCK_CHILD_ACTIONEXECUTION_REQUESTED]))
1243
    def test_orphaned_execution_child_in_requested_state(self):
1244
        (status, result) = self.querier.query(uuid.uuid4().hex, MOCK_QRY_CONTEXT)
1245
1246
        expected = {
1247
            'k1': 'v1',
1248
            'tasks': copy.deepcopy(MOCK_WF_EX_TASKS_DATA),
1249
            'extra': {
1250
                'state': MOCK_WF_EX.state,
1251
                'state_info': MOCK_WF_EX.state_info
1252
            }
1253
        }
1254
1255
        for task in expected['tasks']:
1256
            task['input'] = json.loads(task['input'])
1257
            task['result'] = json.loads(task['result'])
1258
            task['published'] = json.loads(task['published'])
1259
1260
        self.assertEqual(action_constants.LIVEACTION_STATUS_SUCCEEDED, status)
1261
        self.assertDictEqual(expected, result)
1262