From 8aa4396e4490a964e3e1b1a5e6f555e97c16fd3d Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Tue, 31 May 2011 12:48:43 -0700 Subject: Begin experimental use of exceptions. Provides IqTimeout and IqError which are raised when an Iq response does not arrive in time, or it arrives with type='error'. --- tests/test_stream_handlers.py | 5 ++++- tests/test_stream_roster.py | 15 ++++----------- 2 files changed, 8 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/test_stream_handlers.py b/tests/test_stream_handlers.py index dae4456d..1b831e21 100644 --- a/tests/test_stream_handlers.py +++ b/tests/test_stream_handlers.py @@ -90,7 +90,10 @@ class TestHandlers(SleekTest): iq['id'] = 'test2' iq['type'] = 'set' iq['query'] = 'test2' - reply = iq.send(block=True, timeout=0) + try: + reply = iq.send(block=True, timeout=0) + except IqTimeout: + pass self.xmpp.add_event_handler('message', waiter_handler, threaded=True) diff --git a/tests/test_stream_roster.py b/tests/test_stream_roster.py index e1aa1766..95163744 100644 --- a/tests/test_stream_roster.py +++ b/tests/test_stream_roster.py @@ -111,19 +111,12 @@ class TestStreamRoster(SleekTest): def testRosterTimeout(self): """Test handling a timed out roster request.""" self.stream_start() - events = [] - - def roster_timeout(event): - events.append('roster_timeout') - - self.xmpp.add_event_handler('roster_timeout', roster_timeout) - self.xmpp.get_roster(timeout=0) - # Give the event queue time to process. - time.sleep(.1) + def do_test(): + self.xmpp.get_roster(timeout=0) + time.sleep(.1) - self.failUnless(events == ['roster_timeout'], - "Roster timeout event not triggered: %s." % events) + self.assertRaises(IqTimeout, do_test) def testRosterCallback(self): """Test handling a roster request callback.""" -- cgit v1.2.3 From 9b7ed73f95145f88887d6fc3daa1bd2a9596b943 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Thu, 11 Aug 2011 21:59:55 -0700 Subject: Reorganize XEP-0004. Changes: May now use underscored method names form.field is replaced by form['fields'] form.get_fields no longer accepts use_dict parameter, it always returns an OrderedDict now form.set_fields will accept either an OrderedDict, or a list of (var, dict) tuples as before. Setting the form type to 'submit' will remove extra meta data from the form fields, leaving just the 'var' and 'value' Setting the form type to 'cancel' will remove all fields. --- tests/test_stanza_xep_0004.py | 41 +++++++++++++++++++++++------------------ tests/test_stanza_xep_0060.py | 34 +++++++++++++++++----------------- 2 files changed, 40 insertions(+), 35 deletions(-) (limited to 'tests') diff --git a/tests/test_stanza_xep_0004.py b/tests/test_stanza_xep_0004.py index bdc4a878..22f8b77d 100644 --- a/tests/test_stanza_xep_0004.py +++ b/tests/test_stanza_xep_0004.py @@ -1,4 +1,6 @@ from sleekxmpp.test import * +from sleekxmpp.thirdparty import OrderedDict + import sleekxmpp.plugins.xep_0004 as xep_0004 @@ -47,21 +49,25 @@ class TestDataForms(SleekTest): """) - form['fields'] = [('f1', {'type': 'text-single', - 'label': 'Username', - 'required': True}), - ('f2', {'type': 'text-private', - 'label': 'Password', - 'required': True}), - ('f3', {'type': 'text-multi', - 'label': 'Message', - 'value': 'Enter message.\nA long one even.'}), - ('f4', {'type': 'list-single', - 'label': 'Message Type', - 'options': [{'label': 'Cool!', - 'value': 'cool'}, - {'label': 'Urgh!', - 'value': 'urgh'}]})] + fields = OrderedDict() + fields['f1'] = {'type': 'text-single', + 'label': 'Username', + 'required': True} + fields['f2'] = {'type': 'text-private', + 'label': 'Password', + 'required': True} + fields['f3'] = {'type': 'text-multi', + 'label': 'Message', + 'value': 'Enter message.\nA long one even.'} + fields['f4'] = {'type': 'list-single', + 'label': 'Message Type', + 'options': [{'label': 'Cool!', + 'value': 'cool'}, + {'label': 'Urgh!', + 'value': 'urgh'}]} + form['fields'] = fields + + self.check(msg, """ @@ -92,9 +98,8 @@ class TestDataForms(SleekTest): msg = self.Message() form = msg['form'] - form.setFields([ - ('foo', {'type': 'text-single'}), - ('bar', {'type': 'list-multi'})]) + form.add_field(var='foo', ftype='text-single') + form.add_field(var='bar', ftype='list-multi') form.setValues({'foo': 'Foo!', 'bar': ['a', 'b']}) diff --git a/tests/test_stanza_xep_0060.py b/tests/test_stanza_xep_0060.py index d42c11bd..2427b787 100644 --- a/tests/test_stanza_xep_0060.py +++ b/tests/test_stanza_xep_0060.py @@ -182,7 +182,7 @@ class TestPubsubStanzas(SleekTest): - + this thing is awesome @@ -306,42 +306,42 @@ class TestPubsubStanzas(SleekTest): - + http://jabber.org/protocol/pubsub#node_config - + leaf - - + + 1 - + 1 - - - + + + 1 - - - + + + 10 - + 1 - + open - + publishers - + never - + -- cgit v1.2.3