Skip to content
This repository has been archived by the owner on Jan 30, 2018. It is now read-only.

Commit

Permalink
Updated SleekTest to implement the checkPresence method.
Browse files Browse the repository at this point in the history
Also, removed unnecessary TestStream class and shortened timeout during stream connection.
  • Loading branch information
legastero committed Jul 20, 2010
1 parent 278a8bb commit 14f1c3b
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions tests/sleektest.py
Expand Up @@ -77,12 +77,6 @@ def read(self, size=4096, block=True, timeout=None):
except:
return None

class TestStream(object):
"""Dummy class to pass a stream object to created stanzas"""

def __init__(self):
self.default_ns = 'jabber:client'


class SleekTest(unittest.TestCase):
"""
Expand Down Expand Up @@ -186,7 +180,34 @@ def checkPresence(self, pres, xml_string, use_values=True):
If use_values is False, the test using getValues() and
setValues() will not be used.
"""
pass
self.fix_namespaces(pres.xml, 'jabber:client')
debug = "Given Stanza:\n%s\n" % ET.tostring(pres.xml)

xml = ET.fromstring(xml_string)
self.fix_namespaces(xml, 'jabber:client')
debug += "XML String:\n%s\n" % ET.tostring(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
# sure it is set
pres['priority'] = pres['priority']
pres2['priority'] = pres2['priority']

if use_values:
values = pres.getStanzaValues()
pres3 = self.Presence()
pres3.setStanzaValues(values)

debug += "Second Constructed Stanza:\n%s\n" % ET.tostring(pres3.xml)
debug = "Three methods for creating stanza do not match:\n" + debug
self.failUnless(self.compare([xml, pres.xml, pres2.xml, pres3.xml]),
debug)
else:
debug = "Two methods for creating stanza do not match:\n" + debug
self.failUnless(self.compare([xml, pres.xml, pres2.xml]), debug)


# ------------------------------------------------------------------
# Methods for simulating stanza streams.
Expand All @@ -208,7 +229,7 @@ def streamStart(self, mode='client', skip=True):
self.xmpp.process(threaded=True)
if skip:
# Clear startup stanzas
self.xmpp.socket.nextSent(timeout=1)
self.xmpp.socket.nextSent(timeout=0.1)

def streamRecv(self, data):
data = str(data)
Expand Down

0 comments on commit 14f1c3b

Please sign in to comment.