summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDan Smith <danms@us.ibm.com>2013-06-25 10:19:42 -0700
committerDan Smith <danms@us.ibm.com>2013-06-27 06:38:16 -0700
commit7b7566bac8e2df14e17631980a7fbf2df68cf116 (patch)
tree1871bf93bbecc3876bd283aad32651a7f9098fb4 /tests
parent42931aaee80a18c855a4b350342f7aa376eb024c (diff)
downloadoslo-7b7566bac8e2df14e17631980a7fbf2df68cf116.tar.gz
oslo-7b7566bac8e2df14e17631980a7fbf2df68cf116.tar.xz
oslo-7b7566bac8e2df14e17631980a7fbf2df68cf116.zip
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
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/test_jsonutils.py6
1 files changed, 6 insertions, 0 deletions
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)