Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/python-nbxmpp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorYann Leboulanger <asterix@lagaule.org>2017-08-12 15:17:51 +0300
committerYann Leboulanger <asterix@lagaule.org>2017-08-12 15:17:51 +0300
commitf4c0ef02eea1091d483aa486222e2477931f64d9 (patch)
treea7a3deac833e60b50b0f6b536ff16504ebb559ac /test
parent99a2469e0368be5911d29911df4af3c916daa477 (diff)
improve comparing XML
Diffstat (limited to 'test')
-rw-r--r--test/lib/__init__.py30
-rw-r--r--test/unit/test_xmpp_dispatcher_nb.py3
2 files changed, 27 insertions, 6 deletions
diff --git a/test/lib/__init__.py b/test/lib/__init__.py
index 6118123..9a29dc5 100644
--- a/test/lib/__init__.py
+++ b/test/lib/__init__.py
@@ -9,12 +9,34 @@ root = os.path.join(os.path.abspath(os.path.dirname(__file__)), '../..')
sys.path.insert(1, root)
sys.path.insert(1, root + '/test/lib')
-def sortxml(data):
- sorted(data.attrs.keys())
+def xml2str_sorted(data):
+ s = "<" + data.name
+ if data.namespace:
+ if not data.parent or data.parent.namespace!=data.namespace:
+ if 'xmlns' not in data.attrs:
+ s += ' xmlns="%s"' % data.namespace
+ for key in sorted(data.attrs.keys()):
+ val = str(data.attrs[key])
+ s += ' %s="%s"' % (key, val)
+
+ s += ">"
+ cnt = 0
if data.kids:
for a in data.kids:
- if not isinstance(a, str):
- sortxml(a)
+ if (len(data.data)-1) >= cnt:
+ s += data.data[cnt]
+ if isinstance(a, str):
+ s += a.__str__()
+ else:
+ s += xml2str_sorted(a)
+ cnt += 1
+ if (len(data.data)-1) >= cnt:
+ s += data.data[cnt]
+ if not data.kids and s.endswith('>'):
+ s = s[:-1] + ' />'
+ else:
+ s += "</" + data.name + ">"
+ return s
def setup_env():
pass
diff --git a/test/unit/test_xmpp_dispatcher_nb.py b/test/unit/test_xmpp_dispatcher_nb.py
index 7a746de..8882884 100644
--- a/test/unit/test_xmpp_dispatcher_nb.py
+++ b/test/unit/test_xmpp_dispatcher_nb.py
@@ -88,8 +88,7 @@ class TestDispatcherNB(unittest.TestCase):
self._simulate_connect()
stanza = "<iq type='get' />"
def send(data):
- lib.sortxml(data)
- self.assertEqual(str(data), '<iq xmlns="jabber:client" type="error"><error code="501" type="cancel"><feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" /><text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">The feature requested is not implemented by the recipient or server and therefore cannot be processed.</text></error></iq>')
+ self.assertEqual(lib.xml2str_sorted(data), '<iq xmlns="jabber:client" type="error"><error code="501" type="cancel"><feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" /><text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">The feature requested is not implemented by the recipient or server and therefore cannot be processed.</text></error></iq>')
self.client.send = send
self.dispatcher.ProcessNonBlocking(stanza)