From bd9bf3f1c7c17606f455ce0cf9c4d0b6b237a7fe Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Thu, 27 Jan 2011 18:05:05 -0500 Subject: Update tostring methods. Will now always show top-level namespace, unless it is the same as the stream's default namespace. Also added the XMPP stream namespace to the namespace map as 'stream'. --- tests/test_tostring.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_tostring.py b/tests/test_tostring.py index 638e613a..e456d28e 100644 --- a/tests/test_tostring.py +++ b/tests/test_tostring.py @@ -102,11 +102,13 @@ class TestToString(SleekTest): """ Test that stanza objects are serialized properly. """ + self.stream_start() + utf8_message = '\xe0\xb2\xa0_\xe0\xb2\xa0' if not hasattr(utf8_message, 'decode'): # Python 3 utf8_message = bytes(utf8_message, encoding='utf-8') - msg = Message() + msg = self.Message() msg['body'] = utf8_message.decode('utf-8') expected = '\xe0\xb2\xa0_\xe0\xb2\xa0' result = msg.__str__() -- cgit v1.2.3 From d8d9e8df16c07bd13bbac72e4445a2930407b244 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Mon, 20 Jun 2011 16:25:56 -0700 Subject: Fix stanza clobbering when replying to errors. If a stanza handler raised an exception, the exception was processed and replied by the modified stanza, not a stanza with the original content. A copy is now made before handler processing, and if an exception occurs it is the copy that processes the exception using the original content. --- tests/test_stream_exceptions.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'tests') diff --git a/tests/test_stream_exceptions.py b/tests/test_stream_exceptions.py index bc01c2a7..1143ce28 100644 --- a/tests/test_stream_exceptions.py +++ b/tests/test_stream_exceptions.py @@ -15,6 +15,35 @@ class TestStreamExceptions(SleekTest): sys.excepthook = sys.__excepthook__ 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) + + + sys.excepthook = lambda *args, **kwargs: None + self.stream_start() + self.xmpp.add_event_handler('message', message) + + self.recv(""" + + This is going to cause an error. + + """) + + self.send(""" + + This is going to cause an error. + + + + + """) + def testXMPPErrorException(self): """Test raising an XMPPError exception.""" -- cgit v1.2.3 From 2a2ac73845ffc8695e2bc55746f45e1a18d55e6c Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Fri, 1 Jul 2011 15:15:13 -0700 Subject: So using sys.excepthook to catch errors only works once. The error bubbles through the event processing loop, breaking it and hanging the application. Instead, there is now a .exception(e) method on XMLStream which may be overridden or reassigned that will receive all unhandled exceptions (read: not XMPPError) from event and stream handlers. --- tests/test_stream_exceptions.py | 99 +++++++++++++++++++++++++++++++++++++++-- tests/test_stream_xep_0030.py | 14 +++--- tests/test_stream_xep_0128.py | 1 - tests/test_stream_xep_0249.py | 1 - 4 files changed, 102 insertions(+), 13 deletions(-) (limited to 'tests') diff --git a/tests/test_stream_exceptions.py b/tests/test_stream_exceptions.py index 1143ce28..c41edbb2 100644 --- a/tests/test_stream_exceptions.py +++ b/tests/test_stream_exceptions.py @@ -12,7 +12,6 @@ class TestStreamExceptions(SleekTest): """ def tearDown(self): - sys.excepthook = sys.__excepthook__ self.stream_close() def testExceptionReply(self): @@ -23,8 +22,33 @@ class TestStreamExceptions(SleekTest): msg['body'] = 'Body changed' raise XMPPError(clear=False) + self.stream_start() + self.xmpp.add_event_handler('message', message) + + self.recv(""" + + This is going to cause an error. + + """) + + self.send(""" + + This is going to cause an error. + + + + + """) + + def testExceptionContinueWorking(self): + """Test that Sleek continues to respond after an XMPPError is raised.""" + + def message(msg): + msg.reply() + msg['body'] = 'Body changed' + raise XMPPError(clear=False) - sys.excepthook = lambda *args, **kwargs: None self.stream_start() self.xmpp.add_event_handler('message', message) @@ -44,6 +68,22 @@ class TestStreamExceptions(SleekTest): """) + self.recv(""" + + This is going to cause an error. + + """) + + self.send(""" + + This is going to cause an error. + + + + + """) + def testXMPPErrorException(self): """Test raising an XMPPError exception.""" @@ -153,9 +193,8 @@ class TestStreamExceptions(SleekTest): def catch_error(*args, **kwargs): raised_errors.append(True) - sys.excepthook = catch_error - self.stream_start() + self.xmpp.exception = catch_error self.xmpp.add_event_handler('message', message) self.recv(""" @@ -178,6 +217,58 @@ class TestStreamExceptions(SleekTest): self.assertEqual(raised_errors, [True], "Exception was not raised: %s" % raised_errors) + def testUnknownException(self): + """Test Sleek continues to respond after an unknown exception.""" + + raised_errors = [] + + def message(msg): + raise ValueError("Did something wrong") + + def catch_error(*args, **kwargs): + raised_errors.append(True) + + self.stream_start() + self.xmpp.exception = catch_error + self.xmpp.add_event_handler('message', message) + + self.recv(""" + + This is going to cause an error. + + """) + + self.send(""" + + + + + SleekXMPP got into trouble. + + + + """) + + self.recv(""" + + This is going to cause an error. + + """) + + self.send(""" + + + + + SleekXMPP got into trouble. + + + + """) + + self.assertEqual(raised_errors, [True, True], "Exceptions were not raised: %s" % raised_errors) suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamExceptions) diff --git a/tests/test_stream_xep_0030.py b/tests/test_stream_xep_0030.py index c960fc7a..1666d3a1 100644 --- a/tests/test_stream_xep_0030.py +++ b/tests/test_stream_xep_0030.py @@ -12,7 +12,6 @@ class TestStreamDisco(SleekTest): """ def tearDown(self): - sys.excepthook = sys.__excepthook__ self.stream_close() def testInfoEmptyDefaultNode(self): @@ -531,11 +530,6 @@ class TestStreamDisco(SleekTest): raised_exceptions = [] - def catch_exception(*args, **kwargs): - raised_exceptions.append(True) - - sys.excepthook = catch_exception - self.stream_start(mode='client', plugins=['xep_0030', 'xep_0059']) @@ -544,8 +538,14 @@ class TestStreamDisco(SleekTest): iterator=True) results.amount = 10 + def run_test(): + try: + results.next() + except StopIteration: + raised_exceptions.append(True) + t = threading.Thread(name="get_items_iterator", - target=results.next) + target=run_test) t.start() self.send(""" diff --git a/tests/test_stream_xep_0128.py b/tests/test_stream_xep_0128.py index 6fee6556..42fc9143 100644 --- a/tests/test_stream_xep_0128.py +++ b/tests/test_stream_xep_0128.py @@ -13,7 +13,6 @@ class TestStreamExtendedDisco(SleekTest): """ def tearDown(self): - sys.excepthook = sys.__excepthook__ self.stream_close() def testUsingExtendedInfo(self): diff --git a/tests/test_stream_xep_0249.py b/tests/test_stream_xep_0249.py index f49d1f7e..9a25253f 100644 --- a/tests/test_stream_xep_0249.py +++ b/tests/test_stream_xep_0249.py @@ -13,7 +13,6 @@ class TestStreamDirectInvite(SleekTest): """ def tearDown(self): - sys.excepthook = sys.__excepthook__ self.stream_close() def testReceiveInvite(self): -- cgit v1.2.3 From 086bf89d699c88ab89ad1e1975d6022335ca5c04 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Sun, 3 Jul 2011 00:35:36 -0700 Subject: Added XEP-0066: Out-of-Band Data --- tests/test_stream_xep_0066.py | 72 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 tests/test_stream_xep_0066.py (limited to 'tests') diff --git a/tests/test_stream_xep_0066.py b/tests/test_stream_xep_0066.py new file mode 100644 index 00000000..3dbaf840 --- /dev/null +++ b/tests/test_stream_xep_0066.py @@ -0,0 +1,72 @@ +import time +import threading + +from sleekxmpp.test import * + + +class TestOOB(SleekTest): + + def tearDown(self): + self.stream_close() + + def testSendOOB(self): + """Test sending an OOB transfer request.""" + self.stream_start(plugins=['xep_0066', 'xep_0030']) + + url = 'http://github.com/fritzy/SleekXMPP/blob/master/README' + + t = threading.Thread( + name='send_oob', + target=self.xmpp['xep_0066'].send_oob, + args=('user@example.com', url), + kwargs={'desc': 'SleekXMPP README'}) + + t.start() + + self.send(""" + + + http://github.com/fritzy/SleekXMPP/blob/master/README + SleekXMPP README + + + """) + + self.recv(""" + + """) + + t.join() + + def testReceiveOOB(self): + """Test receiving an OOB request.""" + self.stream_start(plugins=['xep_0066', 'xep_0030']) + + events = [] + + def receive_oob(iq): + events.append(iq['oob_transfer']['url']) + + self.xmpp.add_event_handler('oob_transfer', receive_oob) + + self.recv(""" + + + http://github.com/fritzy/SleekXMPP/blob/master/README + SleekXMPP README + + + """) + + time.sleep(0.1) + + self.assertEqual(events, + ['http://github.com/fritzy/SleekXMPP/blob/master/README'], + 'URL was not received: %s' % events) + + +suite = unittest.TestLoader().loadTestsFromTestCase(TestOOB) -- cgit v1.2.3 From b2d42b1d6cad5c7f77f41c813f1b8f421d9339af Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Tue, 5 Jul 2011 11:18:46 -0700 Subject: Test no longer applies to latest version of XEP-0066. --- tests/test_stream_xep_0066.py | 28 ---------------------------- 1 file changed, 28 deletions(-) (limited to 'tests') diff --git a/tests/test_stream_xep_0066.py b/tests/test_stream_xep_0066.py index 3dbaf840..e3f2ddfa 100644 --- a/tests/test_stream_xep_0066.py +++ b/tests/test_stream_xep_0066.py @@ -40,33 +40,5 @@ class TestOOB(SleekTest): t.join() - def testReceiveOOB(self): - """Test receiving an OOB request.""" - self.stream_start(plugins=['xep_0066', 'xep_0030']) - - events = [] - - def receive_oob(iq): - events.append(iq['oob_transfer']['url']) - - self.xmpp.add_event_handler('oob_transfer', receive_oob) - - self.recv(""" - - - http://github.com/fritzy/SleekXMPP/blob/master/README - SleekXMPP README - - - """) - - time.sleep(0.1) - - self.assertEqual(events, - ['http://github.com/fritzy/SleekXMPP/blob/master/README'], - 'URL was not received: %s' % events) - suite = unittest.TestLoader().loadTestsFromTestCase(TestOOB) -- cgit v1.2.3 From 712da4c46e4ef5ee7995c37d8502c12391e23050 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Tue, 5 Jul 2011 21:29:31 -0700 Subject: Add test to check that presence events are firing. --- tests/test_stream_presence.py | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'tests') diff --git a/tests/test_stream_presence.py b/tests/test_stream_presence.py index 1d5caa98..0b086266 100644 --- a/tests/test_stream_presence.py +++ b/tests/test_stream_presence.py @@ -184,5 +184,56 @@ class TestStreamPresence(SleekTest): self.assertEqual(events, expected, "Incorrect events triggered: %s" % events) + def test_presence_events(self): + """Test that presence events are raised.""" + + events = [] + + self.stream_start() + + ptypes = ['available', 'away', 'dnd', 'xa', 'chat', + 'unavailable', 'subscribe', 'subscribed', + 'unsubscribe', 'unsubscribed'] + + for ptype in ptypes: + handler = lambda p: events.append(p['type']) + self.xmpp.add_event_handler('presence_%s' % ptype, handler) + + self.recv(""" + + """) + self.recv(""" + away + """) + self.recv(""" + dnd + """) + self.recv(""" + xa + """) + self.recv(""" + chat + """) + self.recv(""" + + """) + self.recv(""" + + """) + self.recv(""" + + """) + self.recv(""" + + """) + self.recv(""" + + """) + + time.sleep(.5) + + self.assertEqual(events, ptypes, + "Not all events raised: %s" % events) + suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamPresence) -- cgit v1.2.3 From 9ffdba8643ca8e52a30ce227331cd772a5fea6d1 Mon Sep 17 00:00:00 2001 From: Nathan Fritz Date: Wed, 3 Aug 2011 23:56:24 -0700 Subject: the great xep_0060 re-organization in preperation for rewrite --- tests/test_stanza_xep_0060.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_stanza_xep_0060.py b/tests/test_stanza_xep_0060.py index 8e6e820d..d42c11bd 100644 --- a/tests/test_stanza_xep_0060.py +++ b/tests/test_stanza_xep_0060.py @@ -1,6 +1,6 @@ from sleekxmpp.test import * import sleekxmpp.plugins.xep_0004 as xep_0004 -import sleekxmpp.plugins.stanza_pubsub as pubsub +import sleekxmpp.plugins.xep_0060.stanza as pubsub class TestPubsubStanzas(SleekTest): -- cgit v1.2.3