summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sleekxmpp/plugins/xep_0060/pubsub.py5
-rw-r--r--sleekxmpp/plugins/xep_0060/stanza/pubsub.py8
-rw-r--r--tests/test_stream_xep_0060.py51
3 files changed, 60 insertions, 4 deletions
diff --git a/sleekxmpp/plugins/xep_0060/pubsub.py b/sleekxmpp/plugins/xep_0060/pubsub.py
index cb6cbacd..fadcf652 100644
--- a/sleekxmpp/plugins/xep_0060/pubsub.py
+++ b/sleekxmpp/plugins/xep_0060/pubsub.py
@@ -283,7 +283,8 @@ class xep_0060(base_plugin):
return iq.send(block=block, callback=callback, timeout=timeout)
def publish(self, jid, node, item_id=None, payload=None, items=None,
- ifrom=None, block=True, callback=None, timeout=None):
+ options=None, ifrom=None, block=True, callback=None,
+ timeout=None):
"""
Add or edit items in a node.
@@ -304,6 +305,8 @@ class xep_0060(base_plugin):
item['id'] = id
item['payload'] = payload
iq['pubsub']['publish'].append(item)
+ if options is not None:
+ iq['pubsub']['publish_options'] = options
return iq.send(block=block, callback=callback, timeout=timeout)
def retract(self, jid, node, item, ifrom=None, block=True,
diff --git a/sleekxmpp/plugins/xep_0060/stanza/pubsub.py b/sleekxmpp/plugins/xep_0060/stanza/pubsub.py
index 139992e3..6a9a3df9 100644
--- a/sleekxmpp/plugins/xep_0060/stanza/pubsub.py
+++ b/sleekxmpp/plugins/xep_0060/stanza/pubsub.py
@@ -257,12 +257,16 @@ class PublishOptions(ElementBase):
return form
def set_publish_options(self, value):
- self.xml.append(value.getXML())
+ if value is None:
+ del self['publish_options']
+ else:
+ self.xml.append(value.getXML())
return self
def del_publish_options(self):
config = self.xml.find('{jabber:x:data}x')
- self.xml.remove(config)
+ if config is not None:
+ self.xml.remove(config)
registerStanzaPlugin(Pubsub, PublishOptions)
diff --git a/tests/test_stream_xep_0060.py b/tests/test_stream_xep_0060.py
index 048e41eb..9feb629c 100644
--- a/tests/test_stream_xep_0060.py
+++ b/tests/test_stream_xep_0060.py
@@ -416,9 +416,58 @@ class TestStreamPubsub(SleekTest):
t.join()
-
def testPublishSingleOptions(self):
"""Test publishing a single item, with options."""
+ payload = AtomEntry()
+ payload['title'] = 'Test'
+
+ register_stanza_plugin(self.xmpp['xep_0060'].stanza.Item, AtomEntry)
+
+ options = self.xmpp['xep_0004'].make_form()
+ options.add_field(var='FORM_TYPE', ftype='hidden',
+ value='http://jabber.org/protocol/pubsub#publish-options')
+ options.add_field(var='pubsub#access_model', ftype='text-single',
+ value='presence')
+ options['type'] = 'submit'
+
+ t = threading.Thread(name='publish_single',
+ target=self.xmpp['xep_0060'].publish,
+ args=('pubsub.example.com', 'somenode'),
+ kwargs={'item_id': 'ID42',
+ 'payload': payload,
+ 'options': options})
+ t.start()
+
+ self.send("""
+ <iq type="set" id="1" to="pubsub.example.com">
+ <pubsub xmlns="http://jabber.org/protocol/pubsub">
+ <publish node="somenode">
+ <item id="ID42">
+ <entry xmlns="http://www.w3.org/2005/Atom">
+ <title>Test</title>
+ </entry>
+ </item>
+ </publish>
+ <publish-options>
+ <x xmlns="jabber:x:data" type="submit">
+ <field var="FORM_TYPE">
+ <value>http://jabber.org/protocol/pubsub#publish-options</value>
+ </field>
+ <field var="pubsub#access_model">
+ <value>presence</value>
+ </field>
+ </x>
+ </publish-options>
+ </pubsub>
+ </iq>
+ """, use_values=False)
+
+ self.recv("""
+ <iq type="result" id="1"
+ to="tester@localhost" from="pubsub.example.com" />
+ """)
+
+ t.join()
def testPublishMulti(self):
"""Test publishing multiple items."""