Completed
Pull Request — master (#470)
by
unknown
02:20
created

test_generic_action_multiple_args()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
1
from st2tests.base import BaseActionTestCase
2
3
from local import SaltLocal
4
import requests_mock
5
from requests_mock.contrib import fixture
6
import testtools
7
8
__all__ = [
9
    'SaltLocalActionTestCase'
10
]
11
12
no_args = {
13
    'module': 'this.something',
14
    'target': '*',
15
    'expr_form': 'glob',
16
    'args': []
17
}
18
19
one_arg = {
20
    'module': 'this.something',
21
    'target': '*',
22
    'expr_form': 'glob',
23
    'args': ['os'],
24
}
25
26
multiple_args = {
27
    'module': 'this.something',
28
    'target': '*',
29
    'expr_form': 'glob',
30
    'args': ['this', 'that', 'home'],
31
}
32
33
CONFIG_DATA = {
34
    'api_url': 'https://example.com',
35
    'username': 'this',
36
    'password': 'that'
37
}
38
requests_mock.Mocker.TEST_PREFIX = 'test'
39
40
41
class SaltLocalActionTestCase(testtools.TestCase, BaseActionTestCase):
42
    action_cls = SaltLocal
43
44
    def setUp(self):
45
        super(SaltLocalActionTestCase, self).setUp()
46
        self.m = self.useFixture(fixture.Fixture())
47
        self.action = self.get_action_instance(config=CONFIG_DATA)
48
        self.m.register_uri('POST',
49
                            "{}/run".format(CONFIG_DATA['api_url']),
50
                            json={})
51
52
    def test_generic_action_no_args(self):
53
        self.action.run(**no_args)
54
        self.assertNotIn('arg', self.action.data)
55
56
    def test_generic_action_one_arg(self):
57
        self.action.run(**one_arg)
58
        self.assertIn('arg', self.action.data)
59
        self.assertIsInstance(self.action.data['arg'], list)
60
61
    def test_generic_action_multiple_args(self):
62
        self.action.run(**multiple_args)
63
        self.assertIn('arg', self.action.data)
64
        self.assertIsInstance(self.action.data['arg'], list)
65