mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-30 19:19:55 +00:00
Test publishng an item with options.
This commit is contained in:
parent
09252baa71
commit
46f23f7348
3 changed files with 60 additions and 4 deletions
|
@ -283,7 +283,8 @@ class xep_0060(base_plugin):
|
||||||
return iq.send(block=block, callback=callback, timeout=timeout)
|
return iq.send(block=block, callback=callback, timeout=timeout)
|
||||||
|
|
||||||
def publish(self, jid, node, item_id=None, payload=None, items=None,
|
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.
|
Add or edit items in a node.
|
||||||
|
|
||||||
|
@ -304,6 +305,8 @@ class xep_0060(base_plugin):
|
||||||
item['id'] = id
|
item['id'] = id
|
||||||
item['payload'] = payload
|
item['payload'] = payload
|
||||||
iq['pubsub']['publish'].append(item)
|
iq['pubsub']['publish'].append(item)
|
||||||
|
if options is not None:
|
||||||
|
iq['pubsub']['publish_options'] = options
|
||||||
return iq.send(block=block, callback=callback, timeout=timeout)
|
return iq.send(block=block, callback=callback, timeout=timeout)
|
||||||
|
|
||||||
def retract(self, jid, node, item, ifrom=None, block=True,
|
def retract(self, jid, node, item, ifrom=None, block=True,
|
||||||
|
|
|
@ -257,11 +257,15 @@ class PublishOptions(ElementBase):
|
||||||
return form
|
return form
|
||||||
|
|
||||||
def set_publish_options(self, value):
|
def set_publish_options(self, value):
|
||||||
|
if value is None:
|
||||||
|
del self['publish_options']
|
||||||
|
else:
|
||||||
self.xml.append(value.getXML())
|
self.xml.append(value.getXML())
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def del_publish_options(self):
|
def del_publish_options(self):
|
||||||
config = self.xml.find('{jabber:x:data}x')
|
config = self.xml.find('{jabber:x:data}x')
|
||||||
|
if config is not None:
|
||||||
self.xml.remove(config)
|
self.xml.remove(config)
|
||||||
|
|
||||||
registerStanzaPlugin(Pubsub, PublishOptions)
|
registerStanzaPlugin(Pubsub, PublishOptions)
|
||||||
|
|
|
@ -416,9 +416,58 @@ class TestStreamPubsub(SleekTest):
|
||||||
|
|
||||||
t.join()
|
t.join()
|
||||||
|
|
||||||
|
|
||||||
def testPublishSingleOptions(self):
|
def testPublishSingleOptions(self):
|
||||||
"""Test publishing a single item, with options."""
|
"""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):
|
def testPublishMulti(self):
|
||||||
"""Test publishing multiple items."""
|
"""Test publishing multiple items."""
|
||||||
|
|
Loading…
Reference in a new issue