Passed
Pull Request — master (#444)
by macartur
05:47
created

TestUtils.test_unpack_v0x04_packet()   A

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
c 1
b 1
f 1
dl 0
loc 5
rs 9.4285
cc 1
1
"""Automate utils tests."""
2
import unittest
3
4
from pyof.utils import UnpackException, unpack, validate_packet
5
from pyof.v0x01.symmetric.hello import Hello as Hello_v0x01
6
from pyof.v0x04.symmetric.hello import Hello as Hello_v0x04
7
8
9
class TestUtils(unittest.TestCase):
10
    """Run tests to verify unpack independent of version."""
11
12
    def test_unpack_v0x01_packet(self):
13
        """Test if the package in version v0x01 is properly unpacked."""
14
        data = Hello_v0x01().pack()
15
        expected = unpack(data)
16
        self.assertEqual(expected.pack(), data)
17
18
    def test_unpack_v0x04_packet(self):
19
        """Test if the package in version v0x04 is properly unpacked."""
20
        data = Hello_v0x04().pack()
21
        expected = unpack(data)
22
        self.assertEqual(expected.pack(), data)
23
24
    def test_invalid_packet_with_version_more_then_128(self):
25
        """Test validate a invalid packet with version more than 128."""
26
        hello = Hello_v0x04()
27
        hello.header.version = 129
28
29
        self.assertRaises(UnpackException, validate_packet, hello.pack())
30
31
    def test_validate_packet_with_invalid_packets(self):
32
        """Test validate a invalid packet with invalid packets."""
33
        hello = Hello_v0x04()
34
35
        hello.header.version = 128
36
        self.assertRaises(UnpackException, validate_packet, hello.pack())
37
38
        hello.header.version = 0
39
        self.assertRaises(UnpackException, validate_packet, hello.pack())
40