summaryrefslogtreecommitdiff
path: root/tests/test_stream_xep_0050.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2011-08-13 00:00:34 -0700
committerLance Stout <lancestout@gmail.com>2011-08-13 00:10:06 -0700
commitc26b716164d123b177fd069b9e04cb07eab79b56 (patch)
tree64bb5393ecb99f061a65812bac1f423ed733b1fd /tests/test_stream_xep_0050.py
parentdcaddb804221790e778742f3f5ef22464608cc87 (diff)
downloadslixmpp-c26b716164d123b177fd069b9e04cb07eab79b56.tar.gz
slixmpp-c26b716164d123b177fd069b9e04cb07eab79b56.tar.bz2
slixmpp-c26b716164d123b177fd069b9e04cb07eab79b56.tar.xz
slixmpp-c26b716164d123b177fd069b9e04cb07eab79b56.zip
Update XEP-0050 to use new IQ exceptions.
IqError is now caught and forwarded to the command error handler referenced in the session. Errors are now caught and processed by the session's error handler whether or not the results Iq stanza includes the <command> substanza. Added the option for blocking command calls. The blocking option is set during start_command with block=True. Subsequent command flow methods use session['block'] to determine their blocking behaviour. If you use blocking commands, then you will need to wrap your command calls in a try/except block for IqTimeout exceptions.
Diffstat (limited to 'tests/test_stream_xep_0050.py')
-rw-r--r--tests/test_stream_xep_0050.py46
1 files changed, 43 insertions, 3 deletions
diff --git a/tests/test_stream_xep_0050.py b/tests/test_stream_xep_0050.py
index 11b293c8..1931349d 100644
--- a/tests/test_stream_xep_0050.py
+++ b/tests/test_stream_xep_0050.py
@@ -504,7 +504,7 @@ class TestAdHocCommands(SleekTest):
""")
self.recv("""
- <iq id="1" to="foo@example.com" type="result">
+ <iq id="1" from="foo@example.com" type="result">
<command xmlns="http://jabber.org/protocol/commands"
node="test_client"
sessionid="_sessionid_"
@@ -532,7 +532,7 @@ class TestAdHocCommands(SleekTest):
""")
self.recv("""
- <iq id="2" to="foo@example.com" type="result">
+ <iq id="2" from="foo@example.com" type="result">
<command xmlns="http://jabber.org/protocol/commands"
node="test_client"
sessionid="_sessionid_"
@@ -560,7 +560,7 @@ class TestAdHocCommands(SleekTest):
""")
self.recv("""
- <iq id="3" to="foo@example.com" type="result">
+ <iq id="3" from="foo@example.com" type="result">
<command xmlns="http://jabber.org/protocol/commands"
node="test_client"
sessionid="_sessionid_"
@@ -681,6 +681,46 @@ class TestAdHocCommands(SleekTest):
self.failUnless(results == ['foo'],
'Incomplete command workflow: %s' % results)
+ def testClientAPIErrorStrippedResponse(self):
+ """Test errors that don't include the command substanza."""
+ results = []
+
+ def handle_error(iq, session):
+ for item in session['custom_data']:
+ results.append(item)
+
+ session = {'custom_data': ['foo'],
+ 'error': handle_error}
+
+ self.xmpp['xep_0050'].start_command(
+ 'foo@example.com',
+ 'test_client',
+ session)
+
+ self.send("""
+ <iq id="1" to="foo@example.com" type="set">
+ <command xmlns="http://jabber.org/protocol/commands"
+ node="test_client"
+ action="execute" />
+ </iq>
+ """)
+
+ self.recv("""
+ <iq id="1" to="foo@example.com" type="error">
+ <error type='cancel'>
+ <item-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas' />
+ </error>
+ </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)