mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-27 11:09:56 +00:00
XEP-0009: Updated tests to work in python 3
This commit is contained in:
parent
6c58b8cc4b
commit
e928b9c434
2 changed files with 22 additions and 22 deletions
|
@ -111,10 +111,10 @@ def _xml2py(value):
|
||||||
if value.find('{%s}double' % namespace) is not None:
|
if value.find('{%s}double' % namespace) is not None:
|
||||||
return float(value.find('{%s}double' % namespace).text)
|
return float(value.find('{%s}double' % namespace).text)
|
||||||
if value.find('{%s}base64' % namespace) is not None:
|
if value.find('{%s}base64' % namespace) is not None:
|
||||||
return rpcbase64(value.find('{%s}base64' % namespace).text)
|
return rpcbase64(value.find('{%s}base64' % namespace).text.encode())
|
||||||
if value.find('{%s}Base64' % namespace) is not None:
|
if value.find('{%s}Base64' % namespace) is not None:
|
||||||
# Older versions of XEP-0009 used Base64
|
# Older versions of XEP-0009 used Base64
|
||||||
return rpcbase64(value.find('{%s}Base64' % namespace).text)
|
return rpcbase64(value.find('{%s}Base64' % namespace).text.encode())
|
||||||
if value.find('{%s}dateTime.iso8601' % namespace) is not None:
|
if value.find('{%s}dateTime.iso8601' % namespace) is not None:
|
||||||
return rpctime(value.find('{%s}dateTime.iso8601' % namespace).text)
|
return rpctime(value.find('{%s}dateTime.iso8601' % namespace).text)
|
||||||
if value.find('{%s}struct' % namespace) is not None:
|
if value.find('{%s}struct' % namespace) is not None:
|
||||||
|
@ -138,13 +138,13 @@ class rpcbase64(object):
|
||||||
self.data = data
|
self.data = data
|
||||||
|
|
||||||
def decode(self):
|
def decode(self):
|
||||||
return base64.decodestring(self.data)
|
return base64.b64decode(self.data)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.decode()
|
return self.decode().decode()
|
||||||
|
|
||||||
def encoded(self):
|
def encoded(self):
|
||||||
return self.data
|
return self.data.decode()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ class TestJabberRPC(SleekTest):
|
||||||
</param>
|
</param>
|
||||||
</params>
|
</params>
|
||||||
""")
|
""")
|
||||||
self.failUnless(self.compare(expected_xml, params_xml),
|
self.assertTrue(self.compare(expected_xml, params_xml),
|
||||||
"Nil to XML conversion\nExpected: %s\nGot: %s" % (
|
"Nil to XML conversion\nExpected: %s\nGot: %s" % (
|
||||||
tostring(expected_xml), tostring(params_xml)))
|
tostring(expected_xml), tostring(params_xml)))
|
||||||
self.assertEqual(params, xml2py(expected_xml),
|
self.assertEqual(params, xml2py(expected_xml),
|
||||||
|
@ -90,7 +90,7 @@ class TestJabberRPC(SleekTest):
|
||||||
</param>
|
</param>
|
||||||
</params>
|
</params>
|
||||||
""")
|
""")
|
||||||
self.failUnless(self.compare(expected_xml, params_xml),
|
self.assertTrue(self.compare(expected_xml, params_xml),
|
||||||
"Boolean to XML conversion\nExpected: %s\nGot: %s" % (
|
"Boolean to XML conversion\nExpected: %s\nGot: %s" % (
|
||||||
tostring(expected_xml), tostring(params_xml)))
|
tostring(expected_xml), tostring(params_xml)))
|
||||||
self.assertEqual(params, xml2py(expected_xml),
|
self.assertEqual(params, xml2py(expected_xml),
|
||||||
|
@ -108,7 +108,7 @@ class TestJabberRPC(SleekTest):
|
||||||
</param>
|
</param>
|
||||||
</params>
|
</params>
|
||||||
""")
|
""")
|
||||||
self.failUnless(self.compare(expected_xml, params_xml),
|
self.assertTrue(self.compare(expected_xml, params_xml),
|
||||||
"String to XML conversion\nExpected: %s\nGot: %s" % (
|
"String to XML conversion\nExpected: %s\nGot: %s" % (
|
||||||
tostring(expected_xml), tostring(params_xml)))
|
tostring(expected_xml), tostring(params_xml)))
|
||||||
self.assertEqual(params, xml2py(expected_xml),
|
self.assertEqual(params, xml2py(expected_xml),
|
||||||
|
@ -145,7 +145,7 @@ class TestJabberRPC(SleekTest):
|
||||||
</param>
|
</param>
|
||||||
</params>
|
</params>
|
||||||
""")
|
""")
|
||||||
self.failUnless(self.compare(expected_xml, params_xml),
|
self.assertTrue(self.compare(expected_xml, params_xml),
|
||||||
"Integer to XML conversion\nExpected: %s\nGot: %s" % (
|
"Integer to XML conversion\nExpected: %s\nGot: %s" % (
|
||||||
tostring(expected_xml), tostring(params_xml)))
|
tostring(expected_xml), tostring(params_xml)))
|
||||||
self.assertEqual(params, xml2py(expected_xml),
|
self.assertEqual(params, xml2py(expected_xml),
|
||||||
|
@ -166,14 +166,14 @@ class TestJabberRPC(SleekTest):
|
||||||
</param>
|
</param>
|
||||||
</params>
|
</params>
|
||||||
""")
|
""")
|
||||||
self.failUnless(self.compare(expected_xml, params_xml),
|
self.assertTrue(self.compare(expected_xml, params_xml),
|
||||||
"Double to XML conversion\nExpected: %s\nGot: %s" % (
|
"Double to XML conversion\nExpected: %s\nGot: %s" % (
|
||||||
tostring(expected_xml), tostring(params_xml)))
|
tostring(expected_xml), tostring(params_xml)))
|
||||||
self.assertEqual(params, xml2py(expected_xml),
|
self.assertEqual(params, xml2py(expected_xml),
|
||||||
"XML to double conversion")
|
"XML to double conversion")
|
||||||
|
|
||||||
def testConvertBase64(self):
|
def testConvertBase64(self):
|
||||||
params = [rpcbase64(base64.encodestring("Hello, world!"))]
|
params = [rpcbase64(base64.b64encode(b"Hello, world!"))]
|
||||||
params_xml = py2xml(*params)
|
params_xml = py2xml(*params)
|
||||||
expected_xml = self.parse_xml("""
|
expected_xml = self.parse_xml("""
|
||||||
<params xmlns="jabber:iq:rpc">
|
<params xmlns="jabber:iq:rpc">
|
||||||
|
@ -193,14 +193,14 @@ class TestJabberRPC(SleekTest):
|
||||||
</param>
|
</param>
|
||||||
</params>
|
</params>
|
||||||
""")
|
""")
|
||||||
self.failUnless(self.compare(expected_xml, params_xml),
|
self.assertTrue(self.compare(expected_xml, params_xml),
|
||||||
"Base64 to XML conversion\nExpected: %s\nGot: %s" % (
|
"Base64 to XML conversion\nExpected: %s\nGot: %s" % (
|
||||||
tostring(expected_xml), tostring(params_xml)))
|
tostring(expected_xml), tostring(params_xml)))
|
||||||
self.assertEqual(map(lambda x: x.decode(), params),
|
self.assertEqual(list(map(lambda x: x.decode(), params)),
|
||||||
map(lambda x: x.decode(), xml2py(expected_xml)),
|
list(map(lambda x: x.decode(), xml2py(expected_xml))),
|
||||||
"XML to base64 conversion")
|
"XML to base64 conversion")
|
||||||
self.assertEqual(map(lambda x: x.decode(), params),
|
self.assertEqual(list(map(lambda x: x.decode(), params)),
|
||||||
map(lambda x: x.decode(), xml2py(alternate_xml)),
|
list(map(lambda x: x.decode(), xml2py(alternate_xml))),
|
||||||
"Alternate XML to base64 conversion")
|
"Alternate XML to base64 conversion")
|
||||||
|
|
||||||
def testConvertDateTime(self):
|
def testConvertDateTime(self):
|
||||||
|
@ -215,11 +215,11 @@ class TestJabberRPC(SleekTest):
|
||||||
</param>
|
</param>
|
||||||
</params>
|
</params>
|
||||||
""")
|
""")
|
||||||
self.failUnless(self.compare(expected_xml, params_xml),
|
self.assertTrue(self.compare(expected_xml, params_xml),
|
||||||
"DateTime to XML conversion\nExpected: %s\nGot: %s" % (
|
"DateTime to XML conversion\nExpected: %s\nGot: %s" % (
|
||||||
tostring(expected_xml), tostring(params_xml)))
|
tostring(expected_xml), tostring(params_xml)))
|
||||||
self.assertEqual(map(lambda x: x.iso8601(), params),
|
self.assertEqual(list(map(lambda x: x.iso8601(), params)),
|
||||||
map(lambda x: x.iso8601(), xml2py(expected_xml)),
|
list(map(lambda x: x.iso8601(), xml2py(expected_xml))),
|
||||||
None)
|
None)
|
||||||
|
|
||||||
def testConvertArray(self):
|
def testConvertArray(self):
|
||||||
|
@ -251,10 +251,10 @@ class TestJabberRPC(SleekTest):
|
||||||
</param>
|
</param>
|
||||||
</params>
|
</params>
|
||||||
""")
|
""")
|
||||||
self.failUnless(self.compare(expected_xml, params_xml),
|
self.assertTrue(self.compare(expected_xml, params_xml),
|
||||||
"Array to XML conversion\nExpected: %s\nGot: %s" % (
|
"Array to XML conversion\nExpected: %s\nGot: %s" % (
|
||||||
tostring(expected_xml), tostring(params_xml)))
|
tostring(expected_xml), tostring(params_xml)))
|
||||||
self.assertEqual(map(list, params), xml2py(expected_xml),
|
self.assertEqual(list(map(list, params)), xml2py(expected_xml),
|
||||||
"XML to array conversion")
|
"XML to array conversion")
|
||||||
|
|
||||||
def testConvertStruct(self):
|
def testConvertStruct(self):
|
||||||
|
@ -278,7 +278,7 @@ class TestJabberRPC(SleekTest):
|
||||||
</param>
|
</param>
|
||||||
</params>
|
</params>
|
||||||
""")
|
""")
|
||||||
self.failUnless(self.compare(expected_xml, params_xml),
|
self.assertTrue(self.compare(expected_xml, params_xml),
|
||||||
"Struct to XML conversion\nExpected: %s\nGot: %s" % (
|
"Struct to XML conversion\nExpected: %s\nGot: %s" % (
|
||||||
tostring(expected_xml), tostring(params_xml)))
|
tostring(expected_xml), tostring(params_xml)))
|
||||||
self.assertEqual(params, xml2py(expected_xml),
|
self.assertEqual(params, xml2py(expected_xml),
|
||||||
|
|
Loading…
Reference in a new issue