Passed
Push — master ( b50e97...feedcb )
by Humberto
01:28 queued 14s
created

tests.unit.v0x04.test_controller2switch.test_multipart_request   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 45
dl 0
loc 64
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A TestMultipartRequest.setUpClass() 0 10 1
A TestMultipartRequest.test_pack_unpack_port_desc() 0 5 1
A TestMultipartRequest.test_pack_unpack_table() 0 5 1
A TestMultipartRequest.get_attributes() 0 7 1
A TestMultipartRequest.test_pack_unpack__port_stats_request() 0 6 1
A TestMultipartRequest.test_pack_unpack_desc() 0 5 1
A TestMultipartRequest.test_pack_unpack_table_features() 0 9 1
1
"""MultipartRequest message test."""
2
from pyof.v0x04.controller2switch.multipart_request import (
3
    MultipartRequest, MultipartRequestFlags, MultipartType, PortStatsRequest,
4
    TableFeatures)
5
from tests.unit.v0x04.test_struct import TestStruct
6
7
8
class TestMultipartRequest(TestStruct):
9
    """Test the MultipartRequest message."""
10
11
    @classmethod
12
    def setUpClass(cls):
13
        """Configure raw file and its object in parent class (TestDump)."""
14
        super().setUpClass()
15
16
        super().set_message(MultipartRequest, xid=16,
17
                            multipart_type=MultipartType.OFPMP_TABLE_FEATURES,
18
                            flags=MultipartRequestFlags.OFPMPF_REQ_MORE,
19
                            body=b'')
20
        super().set_minimum_size(16)
21
22
    @staticmethod
23
    def get_attributes(multipart_type=MultipartType.OFPMP_DESC,
24
                       flags=MultipartRequestFlags.OFPMPF_REQ_MORE,
25
                       body=b''):
26
        """Method used to return a dict with instance paramenters."""
27
        return {'xid': 32, 'multipart_type': multipart_type, 'flags': flags,
28
                'body': body}
29
30
    def test_pack_unpack_desc(self):
31
        """Testing multipart_type with OFPMP_DESC."""
32
        options = TestMultipartRequest.get_attributes(
33
            multipart_type=MultipartType.OFPMP_DESC)
34
        self._test_pack_unpack(**options)
35
36
    def test_pack_unpack_table(self):
37
        """Testing multipart_type with OFPMP_TABLE."""
38
        options = TestMultipartRequest.get_attributes(
39
            multipart_type=MultipartType.OFPMP_TABLE)
40
        self._test_pack_unpack(**options)
41
42
    def test_pack_unpack__port_stats_request(self):
43
        """Testing multipart_type with OFPMP_PORT_STATS."""
44
        options = TestMultipartRequest.get_attributes(
45
            multipart_type=MultipartType.OFPMP_PORT_STATS,
46
            body=PortStatsRequest(port_no=33))
47
        self._test_pack_unpack(**options)
48
49
    def test_pack_unpack_port_desc(self):
50
        """Testing multipart_type with OFPMP_PORT_DESC."""
51
        options = TestMultipartRequest.get_attributes(
52
            multipart_type=MultipartType.OFPMP_PORT_DESC)
53
        self._test_pack_unpack(**options)
54
55
    def test_pack_unpack_table_features(self):
56
        """Testing multipart_type with OFPMP_TABLE_FEATURES."""
57
        instance = [TableFeatures(table_id=2),
58
                    TableFeatures(table_id=6),
59
                    TableFeatures(table_id=4)]
60
        options = TestMultipartRequest.get_attributes(
61
            multipart_type=MultipartType.OFPMP_TABLE_FEATURES,
62
            body=instance)
63
        self._test_pack_unpack(**options)
64