Completed
Pull Request — master (#543)
by
unknown
03:05
created

TestBgpRecursion   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B test_action() 0 30 1
1
"""Generated test for checking pynos based actions
2
"""
3
import xml.etree.ElementTree as ET
4
from st2tests.base import BaseActionTestCase
5
from bgp_recursion import bgp_recursion
6
7
__all__ = [
8
    'TestBgpRecursion'
9
]
10
11
12
class MockCallback(object):  # pylint:disable=too-few-public-methods
13
    """Class to hold mock callback and result
14
    """
15
    returned_data = None
16
17
    def callback(self, call, **kwargs):  # pylint:disable=unused-argument
18
        """Mock callback method
19
        """
20
        xml_result = ET.tostring(call)
21
        self.returned_data = xml_result
22
23
24
class TestBgpRecursion(BaseActionTestCase):
25
    """Test holder class
26
    """
27
    action_cls = bgp_recursion
28
29
    def test_action(self):
30
        """Generated test to check action
31
        """
32
        action = self.get_action_instance()
33
        mock_callback = MockCallback()
34
        kwargs = {
35
            'username': '',
36
            'rbridge_id': '224',
37
            'get': False,
38
            'ip': '',
39
            'vrf': 'test',
40
            'password': '',
41
            'port': '22',
42
            'afi': 'ipv4',
43
            'test': True,
44
            'callback': mock_callback.callback
45
        }
46
47
        action.run(**kwargs)
48
49
        expected_xml = (
50
            '<config><rbridge-id xmlns="urn:brocade.com:mgmt:brocade-rbridge">'
51
            '<rbridge-id>224</rbridge-id><router><bgp xmlns="urn:brocade.com:m'
52
            'gmt:brocade-bgp"><vrf-name>test</vrf-name><router-bgp-cmds-holder'
53
            '><address-family><ipv4><ipv4-unicast><next-hop-recursion /></ipv4'
54
            '-unicast></ipv4></address-family></router-bgp-cmds-holder></bgp><'
55
            '/router></rbridge-id></config>'
56
        )
57
58
        self.assertTrue(expected_xml, mock_callback.returned_data)
59