Update the test suite.

- monkey-patch our own monkey-patched idle_call to run events immediatly
  rather than adding them to the event queue, and add a fake transport
  with a fake socket.
- remove the test file related to xep_0059 as it relies on blocking
  behavior, and comment out one xep_0030 test uses xep_0059
- remove many instances of threading and sleep()s because they do
  nothing except waste time and introduce race conditions.
- keep exactly two sleep() in IoT xeps because they rely on timeouts
This commit is contained in:
mathieui
2015-02-12 12:23:47 +01:00
parent 4d063e287e
commit 1e2665df19
25 changed files with 211 additions and 684 deletions

View File

@@ -22,9 +22,6 @@ class TestEvents(SlixTest):
self.xmpp.event("test_event")
self.xmpp.event("test_event")
# Give the event queue time to process.
time.sleep(0.1)
msg = "Event was not triggered the correct number of times: %s"
self.failUnless(happened == [True, True], msg)
@@ -43,9 +40,6 @@ class TestEvents(SlixTest):
# Should not trigger because it was deleted
self.xmpp.event("test_event", {})
# Give the event queue time to process.
time.sleep(0.1)
msg = "Event was not triggered the correct number of times: %s"
self.failUnless(happened == [True], msg % happened)
@@ -66,9 +60,6 @@ class TestEvents(SlixTest):
self.xmpp.add_event_handler("test_event", handletestevent)
self.xmpp.event("test_event", {})
# Give the event queue time to process.
time.sleep(0.1)
msg = "Event was not triggered the correct number of times: %s"
self.failUnless(happened == [True, True], msg % happened)
@@ -86,9 +77,6 @@ class TestEvents(SlixTest):
# Should not trigger because it was deleted
self.xmpp.event("test_event", {})
# Give the event queue time to process.
time.sleep(0.1)
msg = "Event was not triggered the correct number of times: %s"
self.failUnless(happened == [True], msg % happened)

View File

@@ -61,7 +61,7 @@ class TestStanzaBase(SlixTest):
stanza['from'] = "sender@example.com"
stanza['payload'] = ET.Element("{foo}foo")
stanza.reply()
stanza = stanza.reply()
self.failUnless(str(stanza['to'] == "sender@example.com"),
"Stanza reply did not change 'to' attribute.")

View File

@@ -82,7 +82,7 @@ class TestIqStanzas(SlixTest):
iq = self.Iq()
iq['to'] = 'user@localhost'
iq['type'] = 'get'
iq.reply()
iq = iq.reply()
self.check(iq, """
<iq id="0" type="result" />

View File

@@ -17,7 +17,7 @@ class TestMessageStanzas(SlixTest):
msg['from'] = 'room@someservice.someserver.tld/somenick'
msg['type'] = 'groupchat'
msg['body'] = "this is a message"
msg.reply()
msg = msg.reply()
self.failUnless(str(msg['to']) == 'room@someservice.someserver.tld')
def testAttribProperty(self):

View File

@@ -86,7 +86,7 @@ class TestIBB(SlixTest):
self.check(iq, """
<iq type="set">
<data xmlns="http://jabber.org/protocol/ibb" seq="0">c2xlZWt4bXBw</data>
<data xmlns="http://jabber.org/protocol/ibb" seq="0">c2xpeG1wcA==</data>
</iq>
""")

View File

@@ -16,7 +16,7 @@ class TestStreamTester(SlixTest):
self.stream_start(mode='client')
def echo(msg):
msg.reply('Thanks for sending: %(body)s' % msg).send()
msg.reply('Thanks for sending: %s' % msg['body']).send()
self.xmpp.add_event_handler('message', echo)
@@ -58,23 +58,4 @@ class TestStreamTester(SlixTest):
self.stream_start(mode='client', skip=False)
self.send_header(sto='localhost')
def testStreamDisconnect(self):
"""Test that the test socket can simulate disconnections."""
self.stream_start()
events = set()
def stream_error(event):
events.add('socket_error')
self.xmpp.add_event_handler('socket_error', stream_error)
self.stream_disconnect()
self.xmpp.send_raw(' ')
time.sleep(.1)
self.failUnless('socket_error' in events,
"Stream error event not raised: %s" % events)
suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamTester)

View File

@@ -13,40 +13,11 @@ class TestStreamExceptions(SlixTest):
def tearDown(self):
self.stream_close()
def testExceptionReply(self):
"""Test that raising an exception replies with the original stanza."""
def message(msg):
msg.reply()
msg['body'] = 'Body changed'
raise XMPPError(clear=False)
self.stream_start()
self.xmpp.add_event_handler('message', message)
self.recv("""
<message>
<body>This is going to cause an error.</body>
</message>
""")
self.send("""
<message type="error">
<body>This is going to cause an error.</body>
<error type="cancel" code="500">
<undefined-condition
xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
</error>
</message>
""")
def testExceptionContinueWorking(self):
"""Test that Slixmpp continues to respond after an XMPPError is raised."""
def message(msg):
msg.reply()
msg['body'] = 'Body changed'
raise XMPPError(clear=False)
raise XMPPError(clear=True)
self.stream_start()
self.xmpp.add_event_handler('message', message)
@@ -59,7 +30,6 @@ class TestStreamExceptions(SlixTest):
self.send("""
<message type="error">
<body>This is going to cause an error.</body>
<error type="cancel" code="500">
<undefined-condition
xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
@@ -75,7 +45,6 @@ class TestStreamExceptions(SlixTest):
self.send("""
<message type="error">
<body>This is going to cause an error.</body>
<error type="cancel" code="500">
<undefined-condition
xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
@@ -151,38 +120,8 @@ class TestStreamExceptions(SlixTest):
</iq>
""", use_values=False)
def testThreadedXMPPErrorException(self):
"""Test raising an XMPPError exception in a threaded handler."""
def message(msg):
raise XMPPError(condition='feature-not-implemented',
text="We don't do things that way here.",
etype='cancel')
self.stream_start()
self.xmpp.add_event_handler('message', message,
threaded=True)
self.recv("""
<message>
<body>This is going to cause an error.</body>
</message>
""")
self.send("""
<message type="error">
<error type="cancel" code="501">
<feature-not-implemented
xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
<text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">
We don&apos;t do things that way here.
</text>
</error>
</message>
""")
def testUnknownException(self):
"""Test raising an generic exception in a threaded handler."""
"""Test raising an generic exception in a handler."""
raised_errors = []

View File

@@ -47,8 +47,6 @@ class TestFilters(SlixTest):
</message>
""")
time.sleep(0.5)
self.assertEqual(data, ['', 'testing filter'],
'Incoming filter did not apply %s' % data)

View File

@@ -48,15 +48,15 @@ class TestHandlers(SlixTest):
iq['id'] = 'test'
iq['type'] = 'set'
iq['query'] = 'test'
reply = iq.send(block=True)
if reply:
def callback_waiter(result):
self.xmpp.send_raw("""
<message>
<body>Successful: %s</body>
</message>
""" % reply['query'])
""" % result['query'])
iq.send(callback=callback_waiter)
self.xmpp.add_event_handler('message', waiter_handler, threaded=True)
self.xmpp.add_event_handler('message', waiter_handler)
# Send message to trigger waiter_handler
self.recv("""
@@ -93,11 +93,11 @@ class TestHandlers(SlixTest):
iq['type'] = 'set'
iq['query'] = 'test2'
try:
reply = iq.send(block=True, timeout=0)
reply = iq.send(timeout=0)
except IqTimeout:
pass
self.xmpp.add_event_handler('message', waiter_handler, threaded=True)
self.xmpp.add_event_handler('message', waiter_handler)
# Start test by triggerig waiter_handler
self.recv("""<message><body>Start Test</body></message>""")
@@ -109,9 +109,6 @@ class TestHandlers(SlixTest):
iq['query'] = 'test2'
self.send(iq)
# Give the event queue time to process.
time.sleep(0.1)
# Check that the waiter is no longer registered
waiter_exists = self.xmpp.remove_handler('IqWait_test2')
@@ -148,41 +145,9 @@ class TestHandlers(SlixTest):
</iq>
""")
# Give event queue time to process
time.sleep(0.1)
self.failUnless(events == ['foo'],
"Iq callback was not executed: %s" % events)
def testIqTimeoutCallback(self):
"""Test that iq.send(tcallback=handle_foo, timeout_callback=handle_timeout) works."""
events = []
def handle_foo(iq):
events.append('foo')
def handle_timeout(iq):
events.append('timeout')
iq = self.Iq()
iq['type'] = 'get'
iq['id'] = 'test-foo'
iq['to'] = 'user@localhost'
iq['query'] = 'foo'
iq.send(callback=handle_foo, timeout_callback=handle_timeout, timeout=0.05)
self.send("""
<iq type="get" id="test-foo" to="user@localhost">
<query xmlns="foo" />
</iq>
""")
# Give event queue time to process
time.sleep(1)
self.failUnless(events == ['timeout'],
"Iq timeout was not executed: %s" % events)
def testMultipleHandlersForStanza(self):
"""
Test that multiple handlers for a single stanza work
@@ -235,18 +200,15 @@ class TestHandlers(SlixTest):
events = []
def run_test():
# Check that Iq was sent by waiter_handler
iq = self.Iq()
iq['id'] = 'test'
iq['to'] = 'tester@slixmpp.com/test'
iq['type'] = 'set'
iq['query'] = 'test'
result = iq.send()
def callback(result):
events.append(result['from'].full)
t = threading.Thread(name="sender_test", target=run_test)
t.start()
iq = self.Iq()
iq['id'] = 'test'
iq['to'] = 'tester@slixmpp.com/test'
iq['type'] = 'set'
iq['query'] = 'test'
iq.send(callback=callback)
self.recv("""
<iq id="test" from="evil@slixmpp.com/bad" type="result">
@@ -271,13 +233,7 @@ class TestHandlers(SlixTest):
</iq>
""")
t.join()
time.sleep(0.1)
self.assertEqual(events, ['tester@slixmpp.com/test'], "Did not timeout on bad sender")
suite = unittest.TestLoader().loadTestsFromTestCase(TestHandlers)

View File

@@ -38,9 +38,6 @@ class TestStreamPresence(SlixTest):
to="tester@localhost"/>
""")
# Give event queue time to process.
time.sleep(0.1)
self.assertEqual(events, set(('unavailable',)),
"Got offline incorrectly triggered: %s." % events)
@@ -83,9 +80,6 @@ class TestStreamPresence(SlixTest):
type="unavailable" />
""")
# Give event queue time to process.
time.sleep(0.1)
self.assertEqual(events, ['got_offline'],
"Got offline incorrectly triggered: %s" % events)
@@ -108,9 +102,6 @@ class TestStreamPresence(SlixTest):
to="tester@localhost" />
""")
# Give event queue time to process.
time.sleep(0.1)
expected = set(('presence_available', 'got_online'))
self.assertEqual(events, expected,
"Incorrect events triggered: %s" % events)
@@ -242,8 +233,6 @@ class TestStreamPresence(SlixTest):
<presence type="unsubscribed" />
""")
time.sleep(.5)
self.assertEqual(events, ptypes,
"Not all events raised: %s" % events)
@@ -364,8 +353,6 @@ class TestStreamPresence(SlixTest):
</presence>
""")
time.sleep(0.3)
self.assertEqual(events, ['available', 'away', 'dnd', 'chat',
'xa', 'unavailable', 'available',
'available', 'dnd'],

View File

@@ -24,9 +24,7 @@ class TestStreamRoster(SlixTest):
self.xmpp.add_event_handler('roster_update', roster_updates.append)
# Since get_roster blocks, we need to run it in a thread.
t = threading.Thread(name='get_roster', target=self.xmpp.get_roster)
t.start()
self.xmpp.get_roster()
self.send("""
<iq type="get" id="1">
@@ -47,12 +45,6 @@ class TestStreamRoster(SlixTest):
</iq>
""")
# Wait for get_roster to return.
t.join()
# Give the event queue time to process.
time.sleep(.1)
self.check_roster('tester@localhost', 'user@localhost',
name='User',
subscription='from',
@@ -96,8 +88,6 @@ class TestStreamRoster(SlixTest):
subscription='both',
groups=['Friends', 'Examples'])
# Give the event queue time to process.
time.sleep(.1)
self.failUnless('roster_update' in events,
"Roster updated event not triggered: %s" % events)
@@ -170,16 +160,6 @@ class TestStreamRoster(SlixTest):
</iq>
""")
def testRosterTimeout(self):
"""Test handling a timed out roster request."""
self.stream_start()
def do_test():
self.xmpp.get_roster(timeout=0)
time.sleep(.1)
self.assertRaises(IqTimeout, do_test)
def testRosterCallback(self):
"""Test handling a roster request callback."""
self.stream_start()
@@ -188,12 +168,7 @@ class TestStreamRoster(SlixTest):
def roster_callback(iq):
events.append('roster_callback')
# Since get_roster blocks, we need to run it in a thread.
t = threading.Thread(name='get_roster',
target=self.xmpp.get_roster,
kwargs={str('block'): False,
str('callback'): roster_callback})
t.start()
self.xmpp.get_roster(callback=roster_callback)
self.send("""
<iq type="get" id="1">
@@ -213,12 +188,6 @@ class TestStreamRoster(SlixTest):
</iq>
""")
# Wait for get_roster to return.
t.join()
# Give the event queue time to process.
time.sleep(.1)
self.failUnless(events == ['roster_callback'],
"Roster timeout event not triggered: %s." % events)
@@ -235,9 +204,6 @@ class TestStreamRoster(SlixTest):
</iq>
""")
# Give the event queue time to process.
time.sleep(.1)
self.check_roster('tester@localhost', 'andré@foo',
subscription='both',
groups=['Unicode'])
@@ -253,9 +219,6 @@ class TestStreamRoster(SlixTest):
</presence>
""")
# Give the event queue time to process.
time.sleep(.1)
result = self.xmpp.client_roster['andré@foo'].resources
expected = {'bar': {'status':'Testing',
'show':'away',
@@ -298,8 +261,8 @@ class TestStreamRoster(SlixTest):
self.stream_start()
self.assertTrue('rosterver' not in self.xmpp.features)
t = threading.Thread(name='get_roster', target=self.xmpp.get_roster)
t.start()
self.xmpp.get_roster()
self.send("""
<iq type="get" id="1">
<query xmlns="jabber:iq:roster" />
@@ -309,16 +272,14 @@ class TestStreamRoster(SlixTest):
<iq to="tester@localhost" type="result" id="1" />
""")
t.join()
def testBootstrapRosterVer(self):
"""Test bootstrapping with roster versioning."""
self.stream_start()
self.xmpp.features.add('rosterver')
self.xmpp.client_roster.version = ''
t = threading.Thread(name='get_roster', target=self.xmpp.get_roster)
t.start()
self.xmpp.get_roster()
self.send("""
<iq type="get" id="1">
<query xmlns="jabber:iq:roster" ver="" />
@@ -328,8 +289,6 @@ class TestStreamRoster(SlixTest):
<iq to="tester@localhost" type="result" id="1" />
""")
t.join()
def testExistingRosterVer(self):
"""Test using a stored roster version."""
@@ -337,8 +296,8 @@ class TestStreamRoster(SlixTest):
self.xmpp.features.add('rosterver')
self.xmpp.client_roster.version = '42'
t = threading.Thread(name='get_roster', target=self.xmpp.get_roster)
t.start()
self.xmpp.get_roster()
self.send("""
<iq type="get" id="1">
<query xmlns="jabber:iq:roster" ver="42" />
@@ -348,7 +307,5 @@ class TestStreamRoster(SlixTest):
<iq to="tester@localhost" type="result" id="1" />
""")
t.join()
suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamRoster)

View File

@@ -288,10 +288,7 @@ class TestStreamDisco(SlixTest):
self.xmpp.add_event_handler('disco_info', handle_disco_info)
t = threading.Thread(name="get_info",
target=self.xmpp['xep_0030'].get_info,
args=('user@localhost', 'foo'))
t.start()
self.xmpp['xep_0030'].get_info('user@localhost', 'foo')
self.send("""
<iq type="get" to="user@localhost" id="1">
@@ -310,11 +307,6 @@ class TestStreamDisco(SlixTest):
</iq>
""")
# Wait for disco#info request to be received.
t.join()
time.sleep(0.1)
self.assertEqual(events, set(('disco_info',)),
"Disco info event was not triggered: %s" % events)
@@ -491,10 +483,7 @@ class TestStreamDisco(SlixTest):
self.xmpp.add_event_handler('disco_items', handle_disco_items)
t = threading.Thread(name="get_items",
target=self.xmpp['xep_0030'].get_items,
args=('user@localhost', 'foo'))
t.start()
self.xmpp['xep_0030'].get_items('user@localhost', 'foo')
self.send("""
<iq type="get" to="user@localhost" id="1">
@@ -513,11 +502,6 @@ class TestStreamDisco(SlixTest):
</iq>
""")
# Wait for disco#items request to be received.
t.join()
time.sleep(0.1)
items = set([('user@localhost', 'bar', 'Test'),
('user@localhost', 'baz', 'Test 2')])
self.assertEqual(events, set(('disco_items',)),
@@ -525,6 +509,7 @@ class TestStreamDisco(SlixTest):
self.assertEqual(results, items,
"Unexpected items: %s" % results)
'''
def testGetItemsIterator(self):
"""Test interaction between XEP-0030 and XEP-0059 plugins."""
@@ -571,6 +556,7 @@ class TestStreamDisco(SlixTest):
self.assertEqual(raised_exceptions, [True],
"StopIteration was not raised: %s" % raised_exceptions)
'''
suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamDisco)

View File

@@ -24,11 +24,8 @@ class TestInBandByteStreams(SlixTest):
self.xmpp.add_event_handler('ibb_stream_start', on_stream_start)
t = threading.Thread(name='open_stream',
target=self.xmpp['xep_0047'].open_stream,
args=('tester@localhost/receiver',),
kwargs={'sid': 'testing'})
t.start()
self.xmpp['xep_0047'].open_stream('tester@localhost/receiver',
sid='testing')
self.send("""
<iq type="set" to="tester@localhost/receiver" id="1">
@@ -45,10 +42,6 @@ class TestInBandByteStreams(SlixTest):
from="tester@localhost/receiver" />
""")
t.join()
time.sleep(0.2)
self.assertEqual(events, ['ibb_stream_start'])
def testAysncOpenStream(self):
@@ -64,13 +57,9 @@ class TestInBandByteStreams(SlixTest):
self.xmpp.add_event_handler('ibb_stream_start', on_stream_start)
t = threading.Thread(name='open_stream',
target=self.xmpp['xep_0047'].open_stream,
args=('tester@localhost/receiver',),
kwargs={'sid': 'testing',
'block': False,
'callback': stream_callback})
t.start()
self.xmpp['xep_0047'].open_stream('tester@localhost/receiver',
sid='testing',
callback=stream_callback)
self.send("""
<iq type="set" to="tester@localhost/receiver" id="1">
@@ -87,10 +76,6 @@ class TestInBandByteStreams(SlixTest):
from="tester@localhost/receiver" />
""")
t.join()
time.sleep(0.2)
self.assertEqual(events, set(['ibb_stream_start', 'callback']))
def testSendData(self):
@@ -108,11 +93,8 @@ class TestInBandByteStreams(SlixTest):
self.xmpp.add_event_handler('ibb_stream_start', on_stream_start)
self.xmpp.add_event_handler('ibb_stream_data', on_stream_data)
t = threading.Thread(name='open_stream',
target=self.xmpp['xep_0047'].open_stream,
args=('tester@localhost/receiver',),
kwargs={'sid': 'testing'})
t.start()
self.xmpp['xep_0047'].open_stream('tester@localhost/receiver',
sid='testing')
self.send("""
<iq type="set" to="tester@localhost/receiver" id="1">
@@ -129,10 +111,6 @@ class TestInBandByteStreams(SlixTest):
from="tester@localhost/receiver" />
""")
t.join()
time.sleep(0.2)
stream = streams[0]

View File

@@ -623,9 +623,6 @@ class TestAdHocCommands(SlixTest):
</iq>
""")
# Give the event queue time to process
time.sleep(0.3)
self.failUnless(results == ['foo', 'bar', 'baz'],
'Incomplete command workflow: %s' % results)
@@ -689,9 +686,6 @@ class TestAdHocCommands(SlixTest):
</iq>
""")
# Give the event queue time to process
time.sleep(0.3)
self.failUnless(results == ['foo', 'bar'],
'Incomplete command workflow: %s' % results)
@@ -730,9 +724,6 @@ class TestAdHocCommands(SlixTest):
</iq>
""")
# Give the event queue time to process
time.sleep(0.3)
self.failUnless(results == ['foo'],
'Incomplete command workflow: %s' % results)
@@ -768,14 +759,8 @@ class TestAdHocCommands(SlixTest):
</iq>
""")
# Give the event queue time to process
time.sleep(0.3)
self.failUnless(results == ['foo'],
'Incomplete command workflow: %s' % results)
suite = unittest.TestLoader().loadTestsFromTestCase(TestAdHocCommands)

View File

@@ -1,163 +0,0 @@
import threading
import unittest
from slixmpp.test import SlixTest
from slixmpp.xmlstream import register_stanza_plugin
from slixmpp.plugins.xep_0030 import DiscoItems
from slixmpp.plugins.xep_0059 import ResultIterator, Set
class TestStreamSet(SlixTest):
def setUp(self):
register_stanza_plugin(DiscoItems, Set)
def tearDown(self):
self.stream_close()
def iter(self, rev=False):
q = self.xmpp.Iq()
q['type'] = 'get'
it = ResultIterator(q, 'disco_items', amount='1', reverse=rev)
for i in it:
for j in i['disco_items']['items']:
self.items.append(j[0])
def testResultIterator(self):
self.items = []
self.stream_start(mode='client')
t = threading.Thread(target=self.iter)
t.start()
self.send("""
<iq type="get" id="2">
<query xmlns="http://jabber.org/protocol/disco#items">
<set xmlns="http://jabber.org/protocol/rsm">
<max>1</max>
</set>
</query>
</iq>
""")
self.recv("""
<iq type="result" id="2">
<query xmlns="http://jabber.org/protocol/disco#items">
<item jid="item1" />
<set xmlns="http://jabber.org/protocol/rsm">
<last>item1</last>
</set>
</query>
</iq>
""")
self.send("""
<iq type="get" id="3">
<query xmlns="http://jabber.org/protocol/disco#items">
<set xmlns="http://jabber.org/protocol/rsm">
<max>1</max>
<after>item1</after>
</set>
</query>
</iq>
""")
self.recv("""
<iq type="result" id="3">
<query xmlns="http://jabber.org/protocol/disco#items">
<item jid="item2" />
<set xmlns="http://jabber.org/protocol/rsm">
<last>item2</last>
</set>
</query>
</iq>
""")
self.send("""
<iq type="get" id="4">
<query xmlns="http://jabber.org/protocol/disco#items">
<set xmlns="http://jabber.org/protocol/rsm">
<max>1</max>
<after>item2</after>
</set>
</query>
</iq>
""")
self.recv("""
<iq type="result" id="4">
<query xmlns="http://jabber.org/protocol/disco#items">
<item jid="item2" />
<set xmlns="http://jabber.org/protocol/rsm">
</set>
</query>
</iq>
""")
t.join()
self.failUnless(self.items == ['item1', 'item2'])
def testResultIteratorReverse(self):
self.items = []
self.stream_start(mode='client')
t = threading.Thread(target=self.iter, args=(True,))
t.start()
self.send("""
<iq type="get" id="2">
<query xmlns="http://jabber.org/protocol/disco#items">
<set xmlns="http://jabber.org/protocol/rsm">
<max>1</max>
<before />
</set>
</query>
</iq>
""")
self.recv("""
<iq type="result" id="2">
<query xmlns="http://jabber.org/protocol/disco#items">
<item jid="item2" />
<set xmlns="http://jabber.org/protocol/rsm">
<first>item2</first>
</set>
</query>
</iq>
""")
self.send("""
<iq type="get" id="3">
<query xmlns="http://jabber.org/protocol/disco#items">
<set xmlns="http://jabber.org/protocol/rsm">
<max>1</max>
<before>item2</before>
</set>
</query>
</iq>
""")
self.recv("""
<iq type="result" id="3">
<query xmlns="http://jabber.org/protocol/disco#items">
<item jid="item1" />
<set xmlns="http://jabber.org/protocol/rsm">
<first>item1</first>
</set>
</query>
</iq>
""")
self.send("""
<iq type="get" id="4">
<query xmlns="http://jabber.org/protocol/disco#items">
<set xmlns="http://jabber.org/protocol/rsm">
<max>1</max>
<before>item1</before>
</set>
</query>
</iq>
""")
self.recv("""
<iq type="result" id="4">
<query xmlns="http://jabber.org/protocol/disco#items">
<item jid="item1" />
<set xmlns="http://jabber.org/protocol/rsm">
</set>
</query>
</iq>
""")
t.join()
self.failUnless(self.items == ['item2', 'item1'])
suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamSet)

View File

@@ -20,10 +20,7 @@ class TestStreamPubsub(SlixTest):
def testCreateInstantNode(self):
"""Test creating an instant node"""
t = threading.Thread(name='create_node',
target=self.xmpp['xep_0060'].create_node,
args=('pubsub.example.com', None))
t.start()
self.xmpp['xep_0060'].create_node('pubsub.example.com', None)
self.send("""
<iq type="set" id="1" to="pubsub.example.com">
@@ -42,14 +39,11 @@ class TestStreamPubsub(SlixTest):
</iq>
""")
t.join()
def testCreateNodeNoConfig(self):
"""Test creating a node without a config"""
self.xmpp['xep_0060'].create_node(
'pubsub.example.com',
'princely_musings',
block=False)
'princely_musings')
self.send("""
<iq type="set" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
@@ -67,7 +61,7 @@ class TestStreamPubsub(SlixTest):
self.xmpp['xep_0060'].create_node(
'pubsub.example.com',
'princely_musings',
config=form, block=False)
config=form)
self.send("""
<iq type="set" id="1" to="pubsub.example.com">
@@ -91,8 +85,7 @@ class TestStreamPubsub(SlixTest):
"""Test deleting a node"""
self.xmpp['xep_0060'].delete_node(
'pubsub.example.com',
'some_node',
block=False)
'some_node')
self.send("""
<iq type="set" to="pubsub.example.com" id="1">
<pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
@@ -108,8 +101,7 @@ class TestStreamPubsub(SlixTest):
"""
self.xmpp['xep_0060'].subscribe(
'pubsub.example.com',
'somenode',
block=False)
'somenode')
self.send("""
<iq type="set" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
@@ -126,8 +118,7 @@ class TestStreamPubsub(SlixTest):
self.xmpp['xep_0060'].subscribe(
'pubsub.example.com',
'somenode',
ifrom='foo@comp.example.com/bar',
block=False)
ifrom='foo@comp.example.com/bar')
self.send("""
<iq type="set" id="1"
to="pubsub.example.com" from="foo@comp.example.com/bar">
@@ -146,8 +137,7 @@ class TestStreamPubsub(SlixTest):
'pubsub.example.com',
'somenode',
ifrom='foo@comp.example.com/bar',
bare=False,
block=False)
bare=False)
self.send("""
<iq type="set" id="1"
to="pubsub.example.com" from="foo@comp.example.com/bar">
@@ -168,8 +158,7 @@ class TestStreamPubsub(SlixTest):
self.xmpp['xep_0060'].subscribe(
'pubsub.example.com',
'somenode',
bare=False,
block=False)
bare=False)
self.send("""
<iq type="set" id="1"
to="pubsub.example.com">
@@ -188,8 +177,7 @@ class TestStreamPubsub(SlixTest):
'pubsub.example.com',
'somenode',
subscribee='user@example.com/foo',
ifrom='foo@comp.example.com/bar',
block=False)
ifrom='foo@comp.example.com/bar')
self.send("""
<iq type="set" id="1"
to="pubsub.example.com" from="foo@comp.example.com/bar">
@@ -215,8 +203,7 @@ class TestStreamPubsub(SlixTest):
self.xmpp['xep_0060'].subscribe(
'pubsub.example.com',
'somenode',
options=opts,
block=False)
options=opts)
self.send("""
<iq type="set" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
@@ -242,8 +229,7 @@ class TestStreamPubsub(SlixTest):
"""
self.xmpp['xep_0060'].unsubscribe(
'pubsub.example.com',
'somenode',
block=False)
'somenode')
self.send("""
<iq type="set" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
@@ -260,8 +246,7 @@ class TestStreamPubsub(SlixTest):
self.xmpp['xep_0060'].unsubscribe(
'pubsub.example.com',
'somenode',
ifrom='foo@comp.example.com/bar',
block=False)
ifrom='foo@comp.example.com/bar')
self.send("""
<iq type="set" id="1"
to="pubsub.example.com" from="foo@comp.example.com/bar">
@@ -280,8 +265,7 @@ class TestStreamPubsub(SlixTest):
'pubsub.example.com',
'somenode',
ifrom='foo@comp.example.com/bar',
bare=False,
block=False)
bare=False)
self.send("""
<iq type="set" id="1"
to="pubsub.example.com" from="foo@comp.example.com/bar">
@@ -302,8 +286,7 @@ class TestStreamPubsub(SlixTest):
self.xmpp['xep_0060'].unsubscribe(
'pubsub.example.com',
'somenode',
bare=False,
block=False)
bare=False)
self.send("""
<iq type="set" id="1"
to="pubsub.example.com">
@@ -322,8 +305,7 @@ class TestStreamPubsub(SlixTest):
'pubsub.example.com',
'somenode',
subscribee='user@example.com/foo',
ifrom='foo@comp.example.com/bar',
block=False)
ifrom='foo@comp.example.com/bar')
self.send("""
<iq type="set" id="1"
to="pubsub.example.com" from="foo@comp.example.com/bar">
@@ -336,8 +318,7 @@ class TestStreamPubsub(SlixTest):
def testGetDefaultNodeConfig(self):
"""Test retrieving the default node config for a pubsub service."""
self.xmpp['xep_0060'].get_node_config(
'pubsub.example.com',
block=False)
'pubsub.example.com')
self.send("""
<iq type="get" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
@@ -350,8 +331,7 @@ class TestStreamPubsub(SlixTest):
"""Test getting the config for a given node."""
self.xmpp['xep_0060'].get_node_config(
'pubsub.example.com',
'somenode',
block=False)
'somenode')
self.send("""
<iq type="get" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
@@ -372,8 +352,7 @@ class TestStreamPubsub(SlixTest):
self.xmpp['xep_0060'].set_node_config(
'pubsub.example.com',
'somenode',
form,
block=False)
form)
self.send("""
<iq type="set" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
@@ -395,8 +374,7 @@ class TestStreamPubsub(SlixTest):
"""Test publishing no items (in order to generate events)"""
self.xmpp['xep_0060'].publish(
'pubsub.example.com',
'somenode',
block=False)
'somenode')
self.send("""
<iq type="set" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
@@ -416,8 +394,7 @@ class TestStreamPubsub(SlixTest):
'pubsub.example.com',
'somenode',
id='id42',
payload=payload,
block=False)
payload=payload)
self.send("""
<iq type="set" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
@@ -451,8 +428,7 @@ class TestStreamPubsub(SlixTest):
'somenode',
id='ID42',
payload=payload,
options=options,
block=False)
options=options)
self.send("""
<iq type="set" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
@@ -483,8 +459,7 @@ class TestStreamPubsub(SlixTest):
'pubsub.example.com',
'somenode',
'ID1',
notify=True,
block=False)
notify=True)
self.send("""
<iq type="set" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
@@ -500,8 +475,7 @@ class TestStreamPubsub(SlixTest):
self.xmpp['xep_0060'].retract(
'pubsub.example.com',
'somenode',
'ID1',
block=False)
'ID1')
self.send("""
<iq type="set" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
@@ -516,8 +490,7 @@ class TestStreamPubsub(SlixTest):
"""Test removing all items from a node."""
self.xmpp['xep_0060'].purge(
'pubsub.example.com',
'somenode',
block=False)
'somenode')
self.send("""
<iq type="set" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
@@ -531,8 +504,7 @@ class TestStreamPubsub(SlixTest):
self.xmpp['xep_0060'].get_item(
'pubsub.example.com',
'somenode',
'id42',
block=False)
'id42')
self.send("""
<iq type="get" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
@@ -548,8 +520,7 @@ class TestStreamPubsub(SlixTest):
self.xmpp['xep_0060'].get_items(
'pubsub.example.com',
'somenode',
max_items=3,
block=False)
max_items=3)
self.send("""
<iq type="get" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
@@ -562,8 +533,7 @@ class TestStreamPubsub(SlixTest):
"""Test retrieving all items."""
self.xmpp['xep_0060'].get_items(
'pubsub.example.com',
'somenode',
block=False)
'somenode')
self.send("""
<iq type="get" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
@@ -577,8 +547,7 @@ class TestStreamPubsub(SlixTest):
self.xmpp['xep_0060'].get_items(
'pubsub.example.com',
'somenode',
item_ids=['A', 'B', 'C'],
block=False)
item_ids=['A', 'B', 'C'])
self.send("""
<iq type="get" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
@@ -594,8 +563,7 @@ class TestStreamPubsub(SlixTest):
def testGetSubscriptionGlobalDefaultOptions(self):
"""Test getting the subscription options for a node/JID."""
self.xmpp['xep_0060'].get_subscription_options(
'pubsub.example.com',
block=False)
'pubsub.example.com')
self.send("""
<iq type="get" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
@@ -608,8 +576,7 @@ class TestStreamPubsub(SlixTest):
"""Test getting the subscription options for a node/JID."""
self.xmpp['xep_0060'].get_subscription_options(
'pubsub.example.com',
node='somenode',
block=False)
node='somenode')
self.send("""
<iq type="get" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
@@ -623,8 +590,7 @@ class TestStreamPubsub(SlixTest):
self.xmpp['xep_0060'].get_subscription_options(
'pubsub.example.com',
'somenode',
'tester@localhost',
block=False)
'tester@localhost')
self.send("""
<iq type="get" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
@@ -650,8 +616,7 @@ class TestStreamPubsub(SlixTest):
'pubsub.example.com',
'somenode',
'tester@localhost',
opts,
block=False)
opts)
self.send("""
<iq type="get" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
@@ -673,8 +638,7 @@ class TestStreamPubsub(SlixTest):
"""Test retrieving all subscriptions for a node."""
self.xmpp['xep_0060'].get_node_subscriptions(
'pubsub.example.com',
'somenode',
block=False)
'somenode')
self.send("""
<iq type="get" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
@@ -686,8 +650,7 @@ class TestStreamPubsub(SlixTest):
def testGetSubscriptions(self):
"""Test retrieving a users's subscriptions."""
self.xmpp['xep_0060'].get_subscriptions(
'pubsub.example.com',
block=False)
'pubsub.example.com')
self.send("""
<iq type="get" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
@@ -700,8 +663,7 @@ class TestStreamPubsub(SlixTest):
"""Test retrieving a users's subscriptions for a given node."""
self.xmpp['xep_0060'].get_subscriptions(
'pubsub.example.com',
node='somenode',
block=False)
node='somenode')
self.send("""
<iq type="get" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
@@ -713,8 +675,7 @@ class TestStreamPubsub(SlixTest):
def testGetAffiliations(self):
"""Test retrieving a users's affiliations."""
self.xmpp['xep_0060'].get_affiliations(
'pubsub.example.com',
block=False)
'pubsub.example.com')
self.send("""
<iq type="get" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
@@ -727,8 +688,7 @@ class TestStreamPubsub(SlixTest):
"""Test retrieving a users's affiliations for a given node."""
self.xmpp['xep_0060'].get_affiliations(
'pubsub.example.com',
node='somenode',
block=False)
node='somenode')
self.send("""
<iq type="get" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
@@ -741,8 +701,7 @@ class TestStreamPubsub(SlixTest):
"""Test getting the affiliations for a node."""
self.xmpp['xep_0060'].get_node_affiliations(
'pubsub.example.com',
'somenode',
block=False)
'somenode')
self.send("""
<iq type="get" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
@@ -757,8 +716,7 @@ class TestStreamPubsub(SlixTest):
'pubsub.example.com',
'somenode',
subscriptions=[('user@example.com', 'subscribed'),
('foo@example.net', 'none')],
block=False)
('foo@example.net', 'none')])
self.send("""
<iq type="set" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
@@ -776,8 +734,7 @@ class TestStreamPubsub(SlixTest):
'pubsub.example.com',
'somenode',
affiliations=[('user@example.com', 'publisher'),
('foo@example.net', 'none')],
block=False)
('foo@example.net', 'none')])
self.send("""
<iq type="set" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub#owner">

View File

@@ -15,13 +15,8 @@ class TestOOB(SlixTest):
url = 'http://github.com/fritzy/Slixmpp/blob/master/README'
t = threading.Thread(
name='send_oob',
target=self.xmpp['xep_0066'].send_oob,
args=('user@example.com', url),
kwargs={'desc': 'Slixmpp README'})
t.start()
self.xmpp['xep_0066'].send_oob('user@example.com', url,
desc='Slixmpp README')
self.send("""
<iq to="user@example.com" type="set" id="1">
@@ -38,7 +33,5 @@ class TestOOB(SlixTest):
from="user@example.com" />
""")
t.join()
suite = unittest.TestLoader().loadTestsFromTestCase(TestOOB)

View File

@@ -49,8 +49,6 @@ class TestStreamChatStates(SlixTest):
</message>
""")
# Give event queue time to process
time.sleep(0.3)
expected = ['active', 'inactive', 'paused', 'composing', 'gone']
self.failUnless(results == expected,
"Chat state event not handled: %s" % results)

View File

@@ -35,16 +35,14 @@ class TestStreamSet(SlixTest):
def testMakeSoftwareVersionRequest(self):
results = []
def query():
r = self.xmpp['xep_0092'].get_version('foo@bar')
results.append((r['software_version']['name'],
r['software_version']['version'],
r['software_version']['os']))
def callback(result):
results.append((result['software_version']['name'],
result['software_version']['version'],
result['software_version']['os']))
self.stream_start(mode='client', plugins=['xep_0030', 'xep_0092'])
t = threading.Thread(target=query)
t.start()
self.xmpp['xep_0092'].get_version('foo@bar', callback=callback)
self.send("""
<iq type="get" id="1" to="foo@bar">
@@ -62,8 +60,6 @@ class TestStreamSet(SlixTest):
</iq>
""")
t.join()
expected = [('Foo', '1.0', 'Linux')]
self.assertEqual(results, expected,
"Did not receive expected results: %s" % results)

View File

@@ -35,8 +35,6 @@ class TestStreamDirectInvite(SlixTest):
</message>
""")
time.sleep(.5)
self.failUnless(events == [True],
"Event not raised: %s" % events)

View File

@@ -455,8 +455,6 @@ class TestStreamSensorData(SlixTest):
</iq>
""")
time.sleep(.1)
self.failUnless(results == ["rejected"],
"Rejected callback was not properly executed");
@@ -494,8 +492,6 @@ class TestStreamSensorData(SlixTest):
</iq>
""")
time.sleep(.1)
self.failUnless(results == ["accepted"],
"Accepted callback was not properly executed");
@@ -517,13 +513,10 @@ class TestStreamSensorData(SlixTest):
for f in fields:
callback_data["field_" + f['name']] = f;
t1= threading.Thread(name="request_data",
target=self.xmpp['xep_0323'].request_data,
kwargs={"from_jid": "tester@localhost",
"to_jid": "you@google.com",
"nodeIds": ['Device33'],
"callback": my_callback});
t1.start();
self.xmpp['xep_0323'].request_data(from_jid="tester@localhost",
to_jid="you@google.com",
nodeIds=['Device33'],
callback=my_callback)
#self.xmpp['xep_0323'].request_data(from_jid="tester@localhost", to_jid="you@google.com", nodeIds=['Device33'], callback=my_callback);
self.send("""
@@ -567,9 +560,6 @@ class TestStreamSensorData(SlixTest):
</message>
""")
t1.join();
time.sleep(.5)
self.failUnlessEqual(results, ["accepted","fields","done"]);
# self.assertIn("nodeId", callback_data);
self.assertTrue("nodeId" in callback_data)
@@ -651,13 +641,10 @@ class TestStreamSensorData(SlixTest):
callback_data["timestamp"] = timestamp;
callback_data["error_msg"] = error_msg;
t1= threading.Thread(name="request_data",
target=self.xmpp['xep_0323'].request_data,
kwargs={"from_jid": "tester@localhost",
"to_jid": "you@google.com",
"nodeIds": ['Device33'],
"callback": my_callback});
t1.start();
self.xmpp['xep_0323'].request_data(from_jid="tester@localhost",
to_jid="you@google.com",
nodeIds=['Device33'],
callback=my_callback)
self.send("""
<iq type='get'
@@ -688,9 +675,6 @@ class TestStreamSensorData(SlixTest):
</message>
""")
t1.join();
time.sleep(.5)
self.failUnlessEqual(results, ["accepted","failure"]);
# self.assertIn("nodeId", callback_data);
self.assertTrue("nodeId" in callback_data);
@@ -737,7 +721,7 @@ class TestStreamSensorData(SlixTest):
</iq>
""")
time.sleep(2)
time.sleep(1)
self.send("""
<message from='device@clayster.com'
@@ -1033,13 +1017,10 @@ class TestStreamSensorData(SlixTest):
for f in fields:
callback_data["field_" + f['name']] = f;
t1= threading.Thread(name="request_data",
target=self.xmpp['xep_0323'].request_data,
kwargs={"from_jid": "tester@localhost",
"to_jid": "you@google.com",
"nodeIds": ['Device33'],
"callback": my_callback});
t1.start();
self.xmpp['xep_0323'].request_data(from_jid="tester@localhost",
to_jid="you@google.com",
nodeIds=['Device33'],
callback=my_callback)
#self.xmpp['xep_0323'].request_data(from_jid="tester@localhost", to_jid="you@google.com", nodeIds=['Device33'], callback=my_callback);
self.send("""
@@ -1090,9 +1071,6 @@ class TestStreamSensorData(SlixTest):
</message>
""")
t1.join();
time.sleep(.5)
self.failUnlessEqual(results, ["queued","started","fields","done"]);
# self.assertIn("nodeId", callback_data);
self.assertTrue("nodeId" in callback_data);
@@ -1161,8 +1139,6 @@ class TestStreamSensorData(SlixTest):
</iq>
""")
time.sleep(.5)
self.failUnlessEqual(results, ["accepted","cancelled"]);
def testDelayedRequestCancel(self):
@@ -1239,8 +1215,6 @@ class TestStreamSensorData(SlixTest):
</iq>
""")
time.sleep(2)
# Ensure we don't get anything after cancellation
self.send(None)

View File

@@ -189,7 +189,7 @@ class TestStreamControl(SlixTest):
</message>
""")
time.sleep(.5)
time.sleep(0.5)
self.assertEqual(myDevice._get_field_value("Temperature"), "17");
@@ -213,8 +213,6 @@ class TestStreamControl(SlixTest):
</message>
""")
time.sleep(.5)
self.assertEqual(myDevice._get_field_value("Temperature"), "15");
self.assertFalse(myDevice.has_control_field("Voltage", "int"));
@@ -259,8 +257,6 @@ class TestStreamControl(SlixTest):
</iq>
""")
time.sleep(.5)
self.assertEqual(results, ["OK"]);
def testRequestSetErrorAPI(self):
@@ -305,8 +301,6 @@ class TestStreamControl(SlixTest):
</iq>
""")
time.sleep(.5)
self.assertEqual(results, ["OtherError"]);
def testServiceDiscoveryClient(self):