Imported Debian patch 4.0.5-6~numeezy
This commit is contained in:
committed by
Mario Fetka
parent
c44de33144
commit
10dfc9587b
@@ -20,13 +20,10 @@
|
||||
"""
|
||||
Test the `ipalib.rpc` module.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
from six.moves.xmlrpc_client import Binary, Fault, dumps, loads
|
||||
from xmlrpclib import Binary, Fault, dumps, loads
|
||||
|
||||
import nose
|
||||
import six
|
||||
|
||||
from ipatests.util import raises, assert_equal, PluginTester, DummyClass
|
||||
from ipatests.data import binary_bytes, utf8_bytes, unicode_str
|
||||
from ipalib.frontend import Command
|
||||
@@ -34,9 +31,6 @@ from ipalib.request import context, Connection
|
||||
from ipalib import rpc, errors, api, request
|
||||
from ipapython.version import API_VERSION
|
||||
|
||||
if six.PY3:
|
||||
unicode = str
|
||||
|
||||
|
||||
std_compound = (binary_bytes, utf8_bytes, unicode_str)
|
||||
|
||||
@@ -58,39 +52,32 @@ def test_round_trip():
|
||||
"""
|
||||
Test `ipalib.rpc.xml_wrap` and `ipalib.rpc.xml_unwrap`.
|
||||
|
||||
This tests the two functions together with ``xmlrpc.client.dumps()`` and
|
||||
``xmlrpc.client.loads()`` in a full wrap/dumps/loads/unwrap round trip.
|
||||
This tests the two functions together with ``xmlrpclib.dumps()`` and
|
||||
``xmlrpclib.loads()`` in a full wrap/dumps/loads/unwrap round trip.
|
||||
"""
|
||||
# We first test that our assumptions about xmlrpc.client module in the Python
|
||||
# We first test that our assumptions about xmlrpclib module in the Python
|
||||
# standard library are correct:
|
||||
if six.PY2:
|
||||
output_binary_type = bytes
|
||||
else:
|
||||
output_binary_type = Binary
|
||||
|
||||
if six.PY2:
|
||||
assert_equal(dump_n_load(utf8_bytes), unicode_str)
|
||||
assert_equal(dump_n_load(utf8_bytes), unicode_str)
|
||||
assert_equal(dump_n_load(unicode_str), unicode_str)
|
||||
# "Binary" is not "str". pylint: disable=no-member
|
||||
assert_equal(dump_n_load(Binary(binary_bytes)).data, binary_bytes)
|
||||
assert isinstance(dump_n_load(Binary(binary_bytes)), Binary)
|
||||
assert type(dump_n_load(b'hello')) is output_binary_type
|
||||
assert type(dump_n_load('hello')) is str
|
||||
assert type(dump_n_load(u'hello')) is str
|
||||
assert_equal(dump_n_load(b''), output_binary_type(b''))
|
||||
assert_equal(dump_n_load(u''), str())
|
||||
assert_equal(dump_n_load(''), '')
|
||||
assert_equal(dump_n_load(u''), '')
|
||||
assert dump_n_load(None) is None
|
||||
|
||||
# Now we test our wrap and unwrap methods in combination with dumps, loads:
|
||||
# All bytes should come back bytes (because they get wrapped in
|
||||
# xmlrpc.client.Binary(). All unicode should come back unicode because str
|
||||
# All str should come back str (because they get wrapped in
|
||||
# xmlrpclib.Binary(). All unicode should come back unicode because str
|
||||
# explicity get decoded by rpc.xml_unwrap() if they weren't already
|
||||
# decoded by xmlrpc.client.loads().
|
||||
# decoded by xmlrpclib.loads().
|
||||
assert_equal(round_trip(utf8_bytes), utf8_bytes)
|
||||
assert_equal(round_trip(unicode_str), unicode_str)
|
||||
assert_equal(round_trip(binary_bytes), binary_bytes)
|
||||
assert type(round_trip(b'hello')) is bytes
|
||||
assert type(round_trip('hello')) is str
|
||||
assert type(round_trip(u'hello')) is unicode
|
||||
assert_equal(round_trip(b''), b'')
|
||||
assert_equal(round_trip(''), '')
|
||||
assert_equal(round_trip(u''), u'')
|
||||
assert round_trip(None) is None
|
||||
compound = [utf8_bytes, None, binary_bytes, (None, unicode_str),
|
||||
@@ -106,14 +93,13 @@ def test_xml_wrap():
|
||||
f = rpc.xml_wrap
|
||||
assert f([], API_VERSION) == tuple()
|
||||
assert f({}, API_VERSION) == dict()
|
||||
b = f(b'hello', API_VERSION)
|
||||
b = f('hello', API_VERSION)
|
||||
assert isinstance(b, Binary)
|
||||
# "Binary" is not "dict" or "tuple". pylint: disable=no-member
|
||||
assert b.data == b'hello'
|
||||
assert b.data == 'hello'
|
||||
u = f(u'hello', API_VERSION)
|
||||
assert type(u) is unicode
|
||||
assert u == u'hello'
|
||||
value = f([dict(one=False, two=u'hello'), None, b'hello'], API_VERSION)
|
||||
value = f([dict(one=False, two=u'hello'), None, 'hello'], API_VERSION)
|
||||
|
||||
|
||||
def test_xml_unwrap():
|
||||
@@ -124,13 +110,13 @@ def test_xml_unwrap():
|
||||
assert f([]) == tuple()
|
||||
assert f({}) == dict()
|
||||
value = f(Binary(utf8_bytes))
|
||||
assert type(value) is bytes
|
||||
assert type(value) is str
|
||||
assert value == utf8_bytes
|
||||
assert f(utf8_bytes) == unicode_str
|
||||
assert f(unicode_str) == unicode_str
|
||||
value = f([True, Binary(b'hello'), dict(one=1, two=utf8_bytes, three=None)])
|
||||
assert value == (True, b'hello', dict(one=1, two=unicode_str, three=None))
|
||||
assert type(value[1]) is bytes
|
||||
value = f([True, Binary('hello'), dict(one=1, two=utf8_bytes, three=None)])
|
||||
assert value == (True, 'hello', dict(one=1, two=unicode_str, three=None))
|
||||
assert type(value[1]) is str
|
||||
assert type(value[2]['two']) is unicode
|
||||
|
||||
|
||||
@@ -243,9 +229,6 @@ class test_xmlclient(PluginTester):
|
||||
),
|
||||
|
||||
)
|
||||
|
||||
# Create connection for the current thread
|
||||
setattr(context, o.id, Connection(conn, lambda: None))
|
||||
context.xmlclient = Connection(conn, lambda: None)
|
||||
|
||||
# Test with a successful return value:
|
||||
@@ -265,7 +248,7 @@ class test_xmlclient(PluginTester):
|
||||
|
||||
class test_xml_introspection(object):
|
||||
@classmethod
|
||||
def setup_class(self):
|
||||
def setUpClass(self):
|
||||
try:
|
||||
api.Backend.xmlclient.connect(fallback=False)
|
||||
except (errors.NetworkError, IOError):
|
||||
@@ -273,7 +256,7 @@ class test_xml_introspection(object):
|
||||
(__name__, api.env.xmlrpc_uri))
|
||||
|
||||
@classmethod
|
||||
def teardown_class(self):
|
||||
def tearDownClass(self):
|
||||
request.destroy_context()
|
||||
|
||||
def test_list_methods(self):
|
||||
@@ -288,8 +271,8 @@ class test_xml_introspection(object):
|
||||
def test_list_methods_many_params(self):
|
||||
try:
|
||||
result = api.Backend.xmlclient.conn.system.listMethods('foo')
|
||||
except Fault as f:
|
||||
print(f)
|
||||
except Fault, f:
|
||||
print f
|
||||
assert f.faultCode == 3003
|
||||
assert f.faultString == (
|
||||
"command 'system.listMethods' takes no arguments")
|
||||
@@ -308,8 +291,8 @@ class test_xml_introspection(object):
|
||||
def test_signature_no_params(self):
|
||||
try:
|
||||
result = api.Backend.xmlclient.conn.system.methodSignature()
|
||||
except Fault as f:
|
||||
print(f)
|
||||
except Fault, f:
|
||||
print f
|
||||
assert f.faultCode == 3007
|
||||
assert f.faultString == "'method name' is required"
|
||||
else:
|
||||
@@ -318,8 +301,8 @@ class test_xml_introspection(object):
|
||||
def test_signature_many_params(self):
|
||||
try:
|
||||
result = api.Backend.xmlclient.conn.system.methodSignature('a', 'b')
|
||||
except Fault as f:
|
||||
print(f)
|
||||
except Fault, f:
|
||||
print f
|
||||
assert f.faultCode == 3004
|
||||
assert f.faultString == (
|
||||
"command 'system.methodSignature' takes at most 1 argument")
|
||||
@@ -329,8 +312,8 @@ class test_xml_introspection(object):
|
||||
def test_help_no_params(self):
|
||||
try:
|
||||
result = api.Backend.xmlclient.conn.system.methodHelp()
|
||||
except Fault as f:
|
||||
print(f)
|
||||
except Fault, f:
|
||||
print f
|
||||
assert f.faultCode == 3007
|
||||
assert f.faultString == "'method name' is required"
|
||||
else:
|
||||
@@ -339,8 +322,8 @@ class test_xml_introspection(object):
|
||||
def test_help_many_params(self):
|
||||
try:
|
||||
result = api.Backend.xmlclient.conn.system.methodHelp('a', 'b')
|
||||
except Fault as f:
|
||||
print(f)
|
||||
except Fault, f:
|
||||
print f
|
||||
assert f.faultCode == 3004
|
||||
assert f.faultString == (
|
||||
"command 'system.methodHelp' takes at most 1 argument")
|
||||
|
||||
Reference in New Issue
Block a user