From cfe4ec2175c42f208ae23401991febb8525bdd9b Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Wed, 19 Nov 2008 16:11:23 -0700 Subject: Added util.xmlrpc_wrap(), util.xmlrpc_unwrap() functions an corresponding unit tests --- tests/test_ipalib/test_util.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'tests/test_ipalib/test_util.py') diff --git a/tests/test_ipalib/test_util.py b/tests/test_ipalib/test_util.py index 6729fcda..b75d6dc7 100644 --- a/tests/test_ipalib/test_util.py +++ b/tests/test_ipalib/test_util.py @@ -21,6 +21,7 @@ Test the `ipalib.util` module. """ +from xmlrpclib import Binary from tests.util import raises from ipalib import util @@ -49,6 +50,43 @@ def test_xmlrpc_unmarshal(): (('one', 'two'), dict(three=3, four=4)) +def test_xmlrpc_wrap(): + """ + Test the `ipalib.util.xmlrpc_wrap` function. + """ + f = util.xmlrpc_wrap + assert f([]) == tuple() + assert f({}) == dict() + b = f('hello') + assert isinstance(b, Binary) + assert b.data == 'hello' + u = f(u'hello') + assert type(u) is unicode + assert u == u'hello' + value = f([dict(one=False, two=u'hello'), None, 'hello']) + + +def test_xmlrpc_unwrap(): + """ + Test the `ipalib.util.xmlrpc_unwrap` function. + """ + f = util.xmlrpc_unwrap + assert f([]) == tuple() + assert f({}) == dict() + utf8_bytes = '\xd0\x9f\xd0\xb0\xd0\xb2\xd0\xb5\xd0\xbb' + unicode_chars = u'\u041f\u0430\u0432\u0435\u043b' + value = f(Binary(utf8_bytes)) + assert type(value) is str + assert value == utf8_bytes + value = f(utf8_bytes) + assert type(value) is unicode + assert value == unicode_chars + value = f([True, Binary('hello'), dict(one=1, two=utf8_bytes, three=None)]) + assert value == (True, 'hello', dict(one=1, two=unicode_chars, three=None)) + assert type(value[1]) is str + assert type(value[2]['two']) is unicode + + def test_make_repr(): """ Test the `ipalib.util.make_repr` function. -- cgit