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