mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-24 03:00:15 +00:00
Fix whitespace issues, and make some debugging statements clearer.
This commit is contained in:
parent
183a3f1b87
commit
956fdf6970
1 changed files with 26 additions and 25 deletions
|
@ -21,7 +21,7 @@ from sleekxmpp.xmlstream.stanzabase import registerStanzaPlugin
|
||||||
|
|
||||||
|
|
||||||
class TestSocket(object):
|
class TestSocket(object):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.socket = socket.socket(*args, **kwargs)
|
self.socket = socket.socket(*args, **kwargs)
|
||||||
self.recv_queue = queue.Queue()
|
self.recv_queue = queue.Queue()
|
||||||
|
@ -104,10 +104,10 @@ class SleekTest(unittest.TestCase):
|
||||||
|
|
||||||
def checkMessage(self, msg, xml_string, use_values=True):
|
def checkMessage(self, msg, xml_string, use_values=True):
|
||||||
"""
|
"""
|
||||||
Create and compare several message stanza objects to a
|
Create and compare several message stanza objects to a
|
||||||
correct XML string.
|
correct XML string.
|
||||||
|
|
||||||
If use_values is False, the test using getValues() and
|
If use_values is False, the test using getValues() and
|
||||||
setValues() will not be used.
|
setValues() will not be used.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -118,10 +118,10 @@ class SleekTest(unittest.TestCase):
|
||||||
self.fix_namespaces(xml, 'jabber:client')
|
self.fix_namespaces(xml, 'jabber:client')
|
||||||
|
|
||||||
debug += "XML String:\n%s\n" % ET.tostring(xml)
|
debug += "XML String:\n%s\n" % ET.tostring(xml)
|
||||||
|
|
||||||
msg2 = self.Message(xml)
|
msg2 = self.Message(xml)
|
||||||
debug += "Constructed Stanza:\n%s\n" % ET.tostring(msg2.xml)
|
debug += "Constructed Stanza:\n%s\n" % ET.tostring(msg2.xml)
|
||||||
|
|
||||||
if use_values:
|
if use_values:
|
||||||
# Ugly, but need to make sure the type attribute is set.
|
# Ugly, but need to make sure the type attribute is set.
|
||||||
msg['type'] = msg['type']
|
msg['type'] = msg['type']
|
||||||
|
@ -133,10 +133,10 @@ class SleekTest(unittest.TestCase):
|
||||||
values = msg2.getStanzaValues()
|
values = msg2.getStanzaValues()
|
||||||
msg3 = self.Message()
|
msg3 = self.Message()
|
||||||
msg3.setStanzaValues(values)
|
msg3.setStanzaValues(values)
|
||||||
|
|
||||||
debug += "Second Constructed Stanza:\n%s\n" % ET.tostring(msg3.xml)
|
debug += "Second Constructed Stanza:\n%s\n" % ET.tostring(msg3.xml)
|
||||||
debug = "Three methods for creating stanza do not match:\n" + debug
|
debug = "Three methods for creating stanza do not match:\n" + debug
|
||||||
self.failUnless(self.compare([xml, msg.xml, msg2.xml, msg3.xml]),
|
self.failUnless(self.compare([xml, msg.xml, msg2.xml, msg3.xml]),
|
||||||
debug)
|
debug)
|
||||||
else:
|
else:
|
||||||
debug = "Two methods for creating stanza do not match:\n" + debug
|
debug = "Two methods for creating stanza do not match:\n" + debug
|
||||||
|
@ -144,10 +144,10 @@ class SleekTest(unittest.TestCase):
|
||||||
|
|
||||||
def checkIq(self, iq, xml_string, use_values=True):
|
def checkIq(self, iq, xml_string, use_values=True):
|
||||||
"""
|
"""
|
||||||
Create and compare several iq stanza objects to a
|
Create and compare several iq stanza objects to a
|
||||||
correct XML string.
|
correct XML string.
|
||||||
|
|
||||||
If use_values is False, the test using getValues() and
|
If use_values is False, the test using getValues() and
|
||||||
setValues() will not be used.
|
setValues() will not be used.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -157,10 +157,10 @@ class SleekTest(unittest.TestCase):
|
||||||
xml = ET.fromstring(xml_string)
|
xml = ET.fromstring(xml_string)
|
||||||
self.fix_namespaces(xml, 'jabber:client')
|
self.fix_namespaces(xml, 'jabber:client')
|
||||||
debug += "XML String:\n%s\n" % ET.tostring(xml)
|
debug += "XML String:\n%s\n" % ET.tostring(xml)
|
||||||
|
|
||||||
iq2 = self.Iq(xml)
|
iq2 = self.Iq(xml)
|
||||||
debug += "Constructed Stanza:\n%s\n" % ET.tostring(iq2.xml)
|
debug += "Constructed Stanza:\n%s\n" % ET.tostring(iq2.xml)
|
||||||
|
|
||||||
if use_values:
|
if use_values:
|
||||||
values = iq.getStanzaValues()
|
values = iq.getStanzaValues()
|
||||||
iq3 = self.Iq()
|
iq3 = self.Iq()
|
||||||
|
@ -168,7 +168,7 @@ class SleekTest(unittest.TestCase):
|
||||||
|
|
||||||
debug += "Second Constructed Stanza:\n%s\n" % ET.tostring(iq3.xml)
|
debug += "Second Constructed Stanza:\n%s\n" % ET.tostring(iq3.xml)
|
||||||
debug = "Three methods for creating stanza do not match:\n" + debug
|
debug = "Three methods for creating stanza do not match:\n" + debug
|
||||||
self.failUnless(self.compare([xml, iq.xml, iq2.xml, iq3.xml]),
|
self.failUnless(self.compare([xml, iq.xml, iq2.xml, iq3.xml]),
|
||||||
debug)
|
debug)
|
||||||
else:
|
else:
|
||||||
debug = "Two methods for creating stanza do not match:\n" + debug
|
debug = "Two methods for creating stanza do not match:\n" + debug
|
||||||
|
@ -176,27 +176,28 @@ class SleekTest(unittest.TestCase):
|
||||||
|
|
||||||
def checkPresence(self, pres, xml_string, use_values=True):
|
def checkPresence(self, pres, xml_string, use_values=True):
|
||||||
"""
|
"""
|
||||||
Create and compare several presence stanza objects to a
|
Create and compare several presence stanza objects to a
|
||||||
correct XML string.
|
correct XML string.
|
||||||
|
|
||||||
If use_values is False, the test using getValues() and
|
If use_values is False, the test using getValues() and
|
||||||
setValues() will not be used.
|
setValues() will not be used.
|
||||||
"""
|
"""
|
||||||
self.fix_namespaces(pres.xml, 'jabber:client')
|
self.fix_namespaces(pres.xml, 'jabber:client')
|
||||||
debug = "Given Stanza:\n%s\n" % ET.tostring(pres.xml)
|
|
||||||
|
|
||||||
xml = ET.fromstring(xml_string)
|
xml = ET.fromstring(xml_string)
|
||||||
self.fix_namespaces(xml, 'jabber:client')
|
self.fix_namespaces(xml, 'jabber:client')
|
||||||
debug += "XML String:\n%s\n" % ET.tostring(xml)
|
|
||||||
|
|
||||||
pres2 = self.Presence(xml)
|
pres2 = self.Presence(xml)
|
||||||
debug += "Constructed Stanza:\n%s\n" % ET.tostring(pres2.xml)
|
|
||||||
|
|
||||||
# Ugly, but 'priority' has a default value and need to make
|
# Ugly, but 'priority' has a default value and need to make
|
||||||
# sure it is set
|
# sure it is set
|
||||||
pres['priority'] = pres['priority']
|
pres['priority'] = pres['priority']
|
||||||
pres2['priority'] = pres2['priority']
|
pres2['priority'] = pres2['priority']
|
||||||
|
|
||||||
|
debug = "Given Stanza:\n%s\n" % ET.tostring(pres.xml)
|
||||||
|
debug += "XML String:\n%s\n" % ET.tostring(xml)
|
||||||
|
debug += "Constructed Stanza:\n%s\n" % ET.tostring(pres2.xml)
|
||||||
|
|
||||||
if use_values:
|
if use_values:
|
||||||
values = pres.getStanzaValues()
|
values = pres.getStanzaValues()
|
||||||
pres3 = self.Presence()
|
pres3 = self.Presence()
|
||||||
|
@ -204,7 +205,7 @@ class SleekTest(unittest.TestCase):
|
||||||
|
|
||||||
debug += "Second Constructed Stanza:\n%s\n" % ET.tostring(pres3.xml)
|
debug += "Second Constructed Stanza:\n%s\n" % ET.tostring(pres3.xml)
|
||||||
debug = "Three methods for creating stanza do not match:\n" + debug
|
debug = "Three methods for creating stanza do not match:\n" + debug
|
||||||
self.failUnless(self.compare([xml, pres.xml, pres2.xml, pres3.xml]),
|
self.failUnless(self.compare([xml, pres.xml, pres2.xml, pres3.xml]),
|
||||||
debug)
|
debug)
|
||||||
else:
|
else:
|
||||||
debug = "Two methods for creating stanza do not match:\n" + debug
|
debug = "Two methods for creating stanza do not match:\n" + debug
|
||||||
|
@ -229,7 +230,7 @@ class SleekTest(unittest.TestCase):
|
||||||
self.xmpp.connectTCP = lambda a, b, c, d: True
|
self.xmpp.connectTCP = lambda a, b, c, d: True
|
||||||
self.xmpp.startTLS = lambda: True
|
self.xmpp.startTLS = lambda: True
|
||||||
self.xmpp.process(threaded=True)
|
self.xmpp.process(threaded=True)
|
||||||
if skip:
|
if skip:
|
||||||
# Clear startup stanzas
|
# Clear startup stanzas
|
||||||
self.xmpp.socket.nextSent(timeout=0.01)
|
self.xmpp.socket.nextSent(timeout=0.01)
|
||||||
|
|
||||||
|
@ -242,7 +243,7 @@ class SleekTest(unittest.TestCase):
|
||||||
data = self.Message(xml=ET.fromstring(data))
|
data = self.Message(xml=ET.fromstring(data))
|
||||||
sent = self.xmpp.socket.nextSent(timeout)
|
sent = self.xmpp.socket.nextSent(timeout)
|
||||||
self.checkMessage(data, sent, use_values)
|
self.checkMessage(data, sent, use_values)
|
||||||
|
|
||||||
def streamSendIq(self, data, use_values=True, timeout=.1):
|
def streamSendIq(self, data, use_values=True, timeout=.1):
|
||||||
if isinstance(data, str):
|
if isinstance(data, str):
|
||||||
data = self.Iq(xml=ET.fromstring(data))
|
data = self.Iq(xml=ET.fromstring(data))
|
||||||
|
@ -265,7 +266,7 @@ class SleekTest(unittest.TestCase):
|
||||||
|
|
||||||
def fix_namespaces(self, xml, ns):
|
def fix_namespaces(self, xml, ns):
|
||||||
"""
|
"""
|
||||||
Assign a namespace to an element and any children that
|
Assign a namespace to an element and any children that
|
||||||
don't have a namespace.
|
don't have a namespace.
|
||||||
"""
|
"""
|
||||||
if xml.tag.startswith('{'):
|
if xml.tag.startswith('{'):
|
||||||
|
|
Loading…
Reference in a new issue