Test Failed
Push — master ( e380d0...f5671d )
by W
02:58
created

contrib/chatops/tests/test_format_result.py (4 issues)

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(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _get_execution 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...
23
            return_value=remote_shell_cmd_execution_model
24
        )
25
        result = action.run(execution_id='57967f9355fc8c19a96d9e4f')
26
        self.assertTrue(result)
27
        self.assertTrue('web_url' in result['message'], result['message'])
28
        self.assertTrue('Took 2s to complete' in result['message'], result['message'])
29
30
    def test_rendering_local_shell_cmd(self):
31
        local_shell_cmd_execution_model = json.loads(
32
            self.get_fixture_content('local_cmd_execution.json')
33
        )
34
35
        action = self.get_action_instance()
36
        action._get_execution = mock.MagicMock(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _get_execution 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...
37
            return_value=local_shell_cmd_execution_model
38
        )
39
        self.assertTrue(action.run(execution_id='5799522f55fc8c2d33ac03e0'))
40
41
    def test_rendering_http_request(self):
42
        http_execution_model = json.loads(
43
            self.get_fixture_content('http_execution.json')
44
        )
45
46
        action = self.get_action_instance()
47
        action._get_execution = mock.MagicMock(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _get_execution 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...
48
            return_value=http_execution_model
49
        )
50
        self.assertTrue(action.run(execution_id='579955f055fc8c2d33ac03e3'))
51
52
    def test_rendering_python_action(self):
53
        python_action_execution_model = json.loads(
54
            self.get_fixture_content('python_action_execution.json')
55
        )
56
57
        action = self.get_action_instance()
58
        action._get_execution = mock.MagicMock(
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _get_execution 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...
59
            return_value=python_action_execution_model
60
        )
61
        self.assertTrue(action.run(execution_id='5799572a55fc8c2d33ac03ec'))
62