From 7b7566bac8e2df14e17631980a7fbf2df68cf116 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Tue, 25 Jun 2013 10:19:42 -0700 Subject: Add netaddr.IPAddress support to to_primitive() This enlightens jsonutils.to_primitive() about how to serialize netaddr.IPAddress objects. Since these types are serializable in their native form with just string coercion, just do that here. Fixes bug 1195097 Change-Id: I358b0731e4d3774e5b36aefb5384fdfb75fd31b6 --- tests/unit/test_jsonutils.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests') diff --git a/tests/unit/test_jsonutils.py b/tests/unit/test_jsonutils.py index 758455b..28d588e 100644 --- a/tests/unit/test_jsonutils.py +++ b/tests/unit/test_jsonutils.py @@ -18,6 +18,7 @@ import datetime import xmlrpclib +import netaddr from six import StringIO from openstack.common import jsonutils @@ -170,3 +171,8 @@ class ToPrimitiveTestCase(utils.BaseTestCase): ret = jsonutils.to_primitive(l4_obj, max_depth=4) self.assertEquals(ret, json_l4) + + def test_ipaddr(self): + thing = {'ip_addr': netaddr.IPAddress('1.2.3.4')} + ret = jsonutils.to_primitive(thing) + self.assertEquals({'ip_addr': '1.2.3.4'}, ret) -- cgit