From 993829b23f923bc76aa0680977b34995105752ae Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Thu, 1 Sep 2011 10:44:14 -0700 Subject: Add tests for pubsub subscription options. --- sleekxmpp/plugins/xep_0060/pubsub.py | 2 + tests/test_stream_xep_0060.py | 98 +++++++++++++++++++++++++++++++++++- 2 files changed, 99 insertions(+), 1 deletion(-) diff --git a/sleekxmpp/plugins/xep_0060/pubsub.py b/sleekxmpp/plugins/xep_0060/pubsub.py index c0038cee..788d3397 100644 --- a/sleekxmpp/plugins/xep_0060/pubsub.py +++ b/sleekxmpp/plugins/xep_0060/pubsub.py @@ -120,6 +120,8 @@ class xep_0060(base_plugin): subscribee = self.xmpp.boundjid iq['pubsub']['subscribe']['jid'] = subscribee + if options is not None: + iq['pubsub']['options'].append(options) return iq.send(block=block, callback=callback, timeout=timeout) def unsubscribe(self, jid, node, subid=None, bare=True, subscribee=None, diff --git a/tests/test_stream_xep_0060.py b/tests/test_stream_xep_0060.py index 0ac7d9fc..9ba01468 100644 --- a/tests/test_stream_xep_0060.py +++ b/tests/test_stream_xep_0060.py @@ -201,7 +201,40 @@ class TestStreamPubsub(SleekTest): """) def testSubscribeWithOptions(self): - pass + """Test subscribing to a node, with options.""" + opts = self.xmpp['xep_0004'].make_form() + opts.add_field( + var='FORM_TYPE', + value='http://jabber.org/protocol/pubsub#subscribe_options', + ftype='hidden') + opts.add_field( + var='pubsub#digest', + value=False, + ftype='boolean') + opts['type'] = 'submit' + + self.xmpp['xep_0060'].subscribe( + 'pubsub.example.com', + 'somenode', + options=opts, + block=False) + self.send(""" + + + + + + + http://jabber.org/protocol/pubsub#subscribe_options + + + 0 + + + + + + """) def testUnsubscribeCase1(self): """ @@ -541,6 +574,69 @@ class TestStreamPubsub(SleekTest): """) + def testGetSubscriptionOptions(self): + """Test getting the subscription options for a node/JID.""" + self.xmpp['xep_0060'].get_subscription_options( + 'pubsub.example.com', + 'somenode', + 'tester@localhost', + block=False) + self.send(""" + + + + + + """, use_values=False) + + def testSetSubscriptionOptions(self): + """Test setting the subscription options for a node/JID.""" + opts = self.xmpp['xep_0004'].make_form() + opts.add_field( + var='FORM_TYPE', + value='http://jabber.org/protocol/pubsub#subscribe_options', + ftype='hidden') + opts.add_field( + var='pubsub#digest', + value=False, + ftype='boolean') + opts['type'] = 'submit' + + self.xmpp['xep_0060'].set_subscription_options( + 'pubsub.example.com', + 'somenode', + 'tester@localhost', + opts, + block=False) + self.send(""" + + + + + + http://jabber.org/protocol/pubsub#subscribe_options + + + 0 + + + + + + """) + def testGetNodeSubscriptions(self): + """Test retrieving the subscriptions for a node.""" + self.xmpp['xep_0060'].get_node_subscriptions( + 'pubsub.example.com', + 'somenode', + block=False) + self.send(""" + + + + + + """) suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamPubsub) -- cgit v1.2.3