Yann Leboulanger pushed to branch master at gajim / python-nbxmpp

Commits:
f4c0ef02 by Yann Leboulanger at 2017-08-12T14:17:51+02:00
improve comparing XML

- - - - -


2 changed files:

- test/lib/__init__.py
- test/unit/test_xmpp_dispatcher_nb.py


Changes:

=====================================
test/lib/__init__.py
=====================================
--- 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


=====================================
test/unit/test_xmpp_dispatcher_nb.py
=====================================
--- 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)
 



View it on GitLab: 
https://dev.gajim.org/gajim/python-nbxmpp/commit/f4c0ef02eea1091d483aa486222e2477931f64d9

---
View it on GitLab: 
https://dev.gajim.org/gajim/python-nbxmpp/commit/f4c0ef02eea1091d483aa486222e2477931f64d9
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list
Commits@gajim.org
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to