summaryrefslogtreecommitdiff
path: root/tests/test_stream_roster.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2015-02-12 12:23:47 +0100
committermathieui <mathieui@mathieui.net>2015-02-12 12:23:47 +0100
commit1e2665df19a866d5676abec566b9d8f190ecdc80 (patch)
tree9fe2f0c501d376291f3d9efc3e9550b34afbf6c7 /tests/test_stream_roster.py
parent4d063e287e1bb2010d115325a3c8c6ca7c542bfc (diff)
downloadslixmpp-1e2665df19a866d5676abec566b9d8f190ecdc80.tar.gz
slixmpp-1e2665df19a866d5676abec566b9d8f190ecdc80.tar.bz2
slixmpp-1e2665df19a866d5676abec566b9d8f190ecdc80.tar.xz
slixmpp-1e2665df19a866d5676abec566b9d8f190ecdc80.zip
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
Diffstat (limited to 'tests/test_stream_roster.py')
-rw-r--r--tests/test_stream_roster.py59
1 files changed, 8 insertions, 51 deletions
diff --git a/tests/test_stream_roster.py b/tests/test_stream_roster.py
index a9aa15e1..6a171ce7 100644
--- a/tests/test_stream_roster.py
+++ b/tests/test_stream_roster.py
@@ -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)