1
|
|
|
import json |
2
|
|
|
import mock |
3
|
|
|
|
4
|
|
|
from st2tests.base import BaseActionTestCase |
5
|
|
|
|
6
|
|
|
from format_execution_result import FormatResultAction |
7
|
|
|
|
8
|
|
|
__all__ = [ |
9
|
|
|
'FormatResultActionTestCase' |
10
|
|
|
] |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class FormatResultActionTestCase(BaseActionTestCase): |
14
|
|
|
action_cls = FormatResultAction |
15
|
|
|
|
16
|
|
|
def test_rendering_works_remote_shell_cmd(self): |
17
|
|
|
remote_shell_cmd_execution_model = json.loads( |
18
|
|
|
self.get_fixture_content('remote_cmd_execution.json') |
19
|
|
|
) |
20
|
|
|
|
21
|
|
|
action = self.get_action_instance() |
22
|
|
|
action._get_execution = mock.MagicMock( |
|
|
|
|
23
|
|
|
return_value=remote_shell_cmd_execution_model |
24
|
|
|
) |
25
|
|
|
self.assertTrue(action.run(execution_id='57967f9355fc8c19a96d9e4f')) |
26
|
|
|
|
27
|
|
|
def test_rendering_local_shell_cmd(self): |
28
|
|
|
local_shell_cmd_execution_model = json.loads( |
29
|
|
|
self.get_fixture_content('local_cmd_execution.json') |
30
|
|
|
) |
31
|
|
|
|
32
|
|
|
action = self.get_action_instance() |
33
|
|
|
action._get_execution = mock.MagicMock( |
|
|
|
|
34
|
|
|
return_value=local_shell_cmd_execution_model |
35
|
|
|
) |
36
|
|
|
self.assertTrue(action.run(execution_id='5799522f55fc8c2d33ac03e0')) |
37
|
|
|
|
38
|
|
|
def test_rendering_http_request(self): |
39
|
|
|
http_execution_model = json.loads( |
40
|
|
|
self.get_fixture_content('http_execution.json') |
41
|
|
|
) |
42
|
|
|
|
43
|
|
|
action = self.get_action_instance() |
44
|
|
|
action._get_execution = mock.MagicMock( |
|
|
|
|
45
|
|
|
return_value=http_execution_model |
46
|
|
|
) |
47
|
|
|
self.assertTrue(action.run(execution_id='579955f055fc8c2d33ac03e3')) |
48
|
|
|
|
49
|
|
|
def test_rendering_python_action(self): |
50
|
|
|
python_action_execution_model = json.loads( |
51
|
|
|
self.get_fixture_content('python_action_execution.json') |
52
|
|
|
) |
53
|
|
|
|
54
|
|
|
action = self.get_action_instance() |
55
|
|
|
action._get_execution = mock.MagicMock( |
|
|
|
|
56
|
|
|
return_value=python_action_execution_model |
57
|
|
|
) |
58
|
|
|
self.assertTrue(action.run(execution_id='5799572a55fc8c2d33ac03ec')) |
59
|
|
|
|
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: