NOTE: some tests are skipped.

the classes 'vrrpv2' and 'vrrpv3' do not have __init__(), so the tests use 
__init__() of 'vrrp'.

at vrrpv2, 'auth_data' is represented as a tuple, but json.loads() cannot 
create a tuple.

the class 'vrrpv3' have a public member which do not relate to arguments of 
__init__().

a json used for creation of the object does not need 'indication',
but a json which the object generated include them.


Signed-off-by: itoyuichi <[email protected]>
---
 ryu/tests/unit/packet/test_vrrp.py |  138 ++++++++++++++++++++++++++++++++++++
 1 file changed, 138 insertions(+)

diff --git a/ryu/tests/unit/packet/test_vrrp.py 
b/ryu/tests/unit/packet/test_vrrp.py
index a26bc90..db53304 100644
--- a/ryu/tests/unit/packet/test_vrrp.py
+++ b/ryu/tests/unit/packet/test_vrrp.py
@@ -17,10 +17,12 @@
 # vim: tabstop=4 shiftwidth=4 softtabstop=4

 import unittest
+import json
 import logging
 import struct
 import inspect

+from nose.plugins.skip import SkipTest
 from nose.tools import eq_, ok_
 from nose.tools import raises

@@ -58,6 +60,26 @@ class Test_vrrpv2(unittest.TestCase):
                       addrconv.ipv4.text_to_bin(ip_address),
                       auth_data[0], auth_data[1])

+    jsonstr = '''
+    {
+        "vrrpv2": {
+            "version": 2,
+            "type": 1,
+            "vrid": 128,
+            "priority": 100,
+            "count_ip": 1,
+            "max_adver_int": 100,
+            "checksum": 0,
+            "ip_addresses": [
+                "192.168.0.1"
+            ],
+            "auth_type": 0,
+            "auth_data": [0, 0]
+        }
+    }
+    '''
+    jsondict = json.loads(jsonstr)
+
     def setUp(self):
         pass

@@ -204,6 +226,36 @@ class Test_vrrpv2(unittest.TestCase):
         eq_(str(self.vrrpv2), vrrpv2_str)
         eq_(repr(self.vrrpv2), vrrpv2_str)

+    def test_to_jsondict(self):
+        vrrpv2 = vrrp.vrrpv2(
+            vrrp.VRRP_VERSION_V2, self.type_, self.vrid, self.priority,
+            1, self.max_adver_int, self.checksum, [self.ip_address],
+            auth_type=vrrp.VRRP_AUTH_NO_AUTH, auth_data=vrrp.VRRP_AUTH_DATA)
+        # to_jsondict() outputs a tuple which json.loads() cannot
+        # create.
+        LOG.info("SKIP [Test_vrrpv2.test_to_jsondict]")
+        LOG.debug("self.jsondict:")
+        LOG.debug(self.jsondict)
+        LOG.debug("self.vrrpv2.to_jsondict():")
+        LOG.debug(vrrpv2.to_jsondict())
+        raise SkipTest("TODO: make reversible vrrpv2.")
+        eq_(self.jsondict, vrrpv2.to_jsondict())
+
+    def test_from_jsondict(self):
+        msg1 = vrrp.vrrpv2.from_jsondict(self.jsondict['vrrpv2'])
+        msg2 = vrrp.vrrpv2(
+            vrrp.VRRP_VERSION_V2, self.type_, self.vrid, self.priority,
+            1, self.max_adver_int, self.checksum, [self.ip_address],
+            auth_type=vrrp.VRRP_AUTH_NO_AUTH, auth_data=vrrp.VRRP_AUTH_DATA)
+        # json.loads() cannot create a tuple.
+        LOG.info("SKIP [Test_vrrpv2.test_from_jsondict]")
+        LOG.debug("vrrp2.from_jsondict(self.jsondict['vrrpv2']):")
+        LOG.debug(str(msg1))
+        LOG.debug("self.vrrpv2:")
+        LOG.debug(str(msg2))
+        raise SkipTest("TODO: make reversible vrrpv2.")
+        eq_(str(msg1), str(msg2))
+

 class Test_vrrpv3_ipv4(unittest.TestCase):
     """ Test case for vrrp v3 IPv4
@@ -224,6 +276,26 @@ class Test_vrrpv3_ipv4(unittest.TestCase):
                       max_adver_int, checksum,
                       addrconv.ipv4.text_to_bin(ip_address))

+    jsonstr = '''
+    {
+        "vrrpv3": {
+            "version": 3,
+            "type": 1,
+            "vrid": 128,
+            "priority": 99,
+            "count_ip": 1,
+            "max_adver_int": 111,
+            "checksum": 0,
+            "ip_addresses": [
+                "192.168.0.1"
+            ],
+            "auth_type": null,
+            "auth_data": null
+        }
+    }
+    '''
+    jsondict = json.loads(jsonstr)
+
     def setUp(self):
         pass

@@ -369,6 +441,29 @@ class Test_vrrpv3_ipv4(unittest.TestCase):
         eq_(str(self.vrrpv3), vrrpv3_str)
         eq_(repr(self.vrrpv3), vrrpv3_str)

+    def test_to_jsondict(self):
+        vrrpv3 = vrrp.vrrpv3(
+            vrrp.VRRP_VERSION_V3, self.type_, self.vrid, self.priority,
+            1, self.max_adver_int, self.checksum, [self.ip_address],
+            auth_type=None, auth_data=None)
+        # vrrp has 'identification' as public members which do not
+        # relate to arguments of __init__().
+        LOG.info("SKIP [Test_vrrpv3_ipv4.test_to_jsondict]")
+        LOG.debug("self.jsondict:")
+        LOG.debug(self.jsondict)
+        LOG.debug("self.vrrpv3.to_jsondict():")
+        LOG.debug(self.vrrpv3.to_jsondict())
+        raise SkipTest("TODO: make reversible vrrpv3.")
+        eq_(self.jsondict, self.vrrpv3.to_jsondict())
+
+    def test_from_jsondict(self):
+        msg1 = vrrp.vrrpv3.from_jsondict(self.jsondict['vrrpv3'])
+        msg2 = vrrp.vrrpv3(
+            vrrp.VRRP_VERSION_V3, self.type_, self.vrid, self.priority,
+            1, self.max_adver_int, self.checksum, [self.ip_address],
+            auth_type=None, auth_data=None)
+        eq_(str(msg1), str(msg2))
+

 class Test_vrrpv3_ipv6(unittest.TestCase):
     """ Test case for vrrp v3 IPv6
@@ -389,6 +484,26 @@ class Test_vrrpv3_ipv6(unittest.TestCase):
                       max_adver_int, checksum,
                       addrconv.ipv6.text_to_bin(ip_address))

+    jsonstr = '''
+    {
+        "vrrpv3": {
+            "version": 3,
+            "type": 1,
+            "vrid": 128,
+            "priority": 99,
+            "count_ip": 1,
+            "max_adver_int": 111,
+            "checksum": 0,
+            "ip_addresses": [
+                "2001:db8:2000::1"
+            ],
+            "auth_type": null,
+            "auth_data": null
+        }
+    }
+    '''
+    jsondict = json.loads(jsonstr)
+
     def setUp(self):
         pass

@@ -491,3 +606,26 @@ class Test_vrrpv3_ipv6(unittest.TestCase):

         eq_(str(self.vrrpv3), vrrpv3_str)
         eq_(repr(self.vrrpv3), vrrpv3_str)
+
+    def test_to_jsondict(self):
+        vrrpv3 = vrrp.vrrpv3(
+            vrrp.VRRP_VERSION_V3, self.type_, self.vrid, self.priority,
+            1, self.max_adver_int, self.checksum, [self.ip_address],
+            auth_type=None, auth_data=None)
+        # vrrp has 'identification' as public members which do not
+        # relate to arguments of __init__().
+        LOG.info("SKIP [Test_vrrpv3_ipv4.test_to_jsondict]")
+        LOG.debug("self.jsondict:")
+        LOG.debug(self.jsondict)
+        LOG.debug("self.vrrpv3.to_jsondict():")
+        LOG.debug(self.vrrpv3.to_jsondict())
+        raise SkipTest("TODO: make reversible vrrpv3.")
+        eq_(self.jsondict, self.vrrpv3.to_jsondict())
+
+    def test_from_jsondict(self):
+        msg1 = vrrp.vrrpv3.from_jsondict(self.jsondict['vrrpv3'])
+        msg2 = vrrp.vrrpv3(
+            vrrp.VRRP_VERSION_V3, self.type_, self.vrid, self.priority,
+            1, self.max_adver_int, self.checksum, [self.ip_address],
+            auth_type=None, auth_data=None)
+        eq_(str(msg1), str(msg2))
-- 
1.7.10.4



------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to