mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-27 11:09:56 +00:00
XEP-0060 v1.13 dictates publishing/retracting one item at a time.
This commit is contained in:
parent
d2dc4824ee
commit
76bc0a2ba6
3 changed files with 27 additions and 108 deletions
|
@ -282,9 +282,8 @@ class xep_0060(base_plugin):
|
|||
iq['pubsub_owner']['configure']['form'].values = config.values
|
||||
return iq.send(block=block, callback=callback, timeout=timeout)
|
||||
|
||||
def publish(self, jid, node, item_id=None, payload=None, items=None,
|
||||
options=None, ifrom=None, block=True, callback=None,
|
||||
timeout=None):
|
||||
def publish(self, jid, node, id=None, payload=None, options=None,
|
||||
ifrom=None, block=True, callback=None, timeout=None):
|
||||
"""
|
||||
Add or edit items in a node.
|
||||
|
||||
|
@ -294,21 +293,14 @@ class xep_0060(base_plugin):
|
|||
"""
|
||||
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set')
|
||||
iq['pubsub']['publish']['node'] = node
|
||||
|
||||
if items is None:
|
||||
items = []
|
||||
if item_id is not None:
|
||||
items.insert(0, (item_id, payload))
|
||||
for id, payload in items:
|
||||
item = stanza.pubsub.Item()
|
||||
if id is not None:
|
||||
item['id'] = id
|
||||
item['payload'] = payload
|
||||
iq['pubsub']['publish'].append(item)
|
||||
if id is not None:
|
||||
iq['pubsub']['publish']['item']['id'] = id
|
||||
if payload is not None:
|
||||
iq['pubsub']['publish']['item']['payload'] = payload
|
||||
iq['pubsub']['publish_options'] = options
|
||||
return iq.send(block=block, callback=callback, timeout=timeout)
|
||||
|
||||
def retract(self, jid, node, item_id, ifrom=None, block=True,
|
||||
def retract(self, jid, node, id, ifrom=None, block=True,
|
||||
callback=None, timeout=None):
|
||||
"""
|
||||
Delete a single item from a node.
|
||||
|
@ -316,7 +308,7 @@ class xep_0060(base_plugin):
|
|||
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set')
|
||||
|
||||
iq['pubsub']['retract']['node'] = node
|
||||
iq['pubsub']['retract']['item']['id'] = item_id
|
||||
iq['pubsub']['retract']['item']['id'] = id
|
||||
return iq.send(block=block, callback=callback, timeout=timeout)
|
||||
|
||||
def purge(self, jid, node, ifrom=None, block=True, callback=None,
|
||||
|
|
|
@ -140,7 +140,7 @@ registerStanzaPlugin(Pubsub, Create)
|
|||
#
|
||||
#registerStanzaPlugin(Pubsub, Default)
|
||||
|
||||
class Publish(Items):
|
||||
class Publish(ElementBase):
|
||||
namespace = 'http://jabber.org/protocol/pubsub'
|
||||
name = 'publish'
|
||||
plugin_attrib = name
|
||||
|
@ -150,6 +150,7 @@ class Publish(Items):
|
|||
subitem = (Item,)
|
||||
|
||||
registerStanzaPlugin(Pubsub, Publish)
|
||||
registerStanzaPlugin(Publish, Item)
|
||||
|
||||
class Retract(ElementBase):
|
||||
namespace = 'http://jabber.org/protocol/pubsub'
|
||||
|
|
|
@ -359,6 +359,20 @@ class TestStreamPubsub(SleekTest):
|
|||
</iq>
|
||||
""")
|
||||
|
||||
def testPublishNoItems(self):
|
||||
"""Test publishing no items (in order to generate events)"""
|
||||
self.xmpp['xep_0060'].publish(
|
||||
'pubsub.example.com',
|
||||
'somenode',
|
||||
block=False)
|
||||
self.send("""
|
||||
<iq type="set" id="1" to="pubsub.example.com">
|
||||
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
||||
<publish node="somenode" />
|
||||
</pubsub>
|
||||
</iq>
|
||||
""")
|
||||
|
||||
def testPublishSingle(self):
|
||||
"""Test publishing a single item."""
|
||||
payload = AtomEntry()
|
||||
|
@ -369,14 +383,14 @@ class TestStreamPubsub(SleekTest):
|
|||
self.xmpp['xep_0060'].publish(
|
||||
'pubsub.example.com',
|
||||
'somenode',
|
||||
item_id='ID42',
|
||||
id='id42',
|
||||
payload=payload,
|
||||
block=False)
|
||||
self.send("""
|
||||
<iq type="set" id="1" to="pubsub.example.com">
|
||||
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
||||
<publish node="somenode">
|
||||
<item id="ID42">
|
||||
<item id="id42">
|
||||
<entry xmlns="http://www.w3.org/2005/Atom">
|
||||
<title>Test</title>
|
||||
</entry>
|
||||
|
@ -403,7 +417,7 @@ class TestStreamPubsub(SleekTest):
|
|||
self.xmpp['xep_0060'].publish(
|
||||
'pubsub.example.com',
|
||||
'somenode',
|
||||
item_id='ID42',
|
||||
id='ID42',
|
||||
payload=payload,
|
||||
options=options,
|
||||
block=False)
|
||||
|
@ -431,94 +445,6 @@ class TestStreamPubsub(SleekTest):
|
|||
</iq>
|
||||
""", use_values=False)
|
||||
|
||||
def testPublishMulti(self):
|
||||
"""Test publishing multiple items."""
|
||||
payload1 = AtomEntry()
|
||||
payload1['title'] = 'Test 1'
|
||||
|
||||
payload2 = AtomEntry()
|
||||
payload2['title'] = 'Test 2'
|
||||
|
||||
register_stanza_plugin(self.xmpp['xep_0060'].stanza.Item, AtomEntry)
|
||||
|
||||
self.xmpp['xep_0060'].publish(
|
||||
'pubsub.example.com',
|
||||
'somenode',
|
||||
items=[('ID1', payload1),
|
||||
('ID2', payload2)],
|
||||
block=False)
|
||||
self.send("""
|
||||
<iq type="set" id="1" to="pubsub.example.com">
|
||||
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
||||
<publish node="somenode">
|
||||
<item id="ID1">
|
||||
<entry xmlns="http://www.w3.org/2005/Atom">
|
||||
<title>Test 1</title>
|
||||
</entry>
|
||||
</item>
|
||||
<item id="ID2">
|
||||
<entry xmlns="http://www.w3.org/2005/Atom">
|
||||
<title>Test 2</title>
|
||||
</entry>
|
||||
</item>
|
||||
</publish>
|
||||
</pubsub>
|
||||
</iq>
|
||||
""", use_values=False)
|
||||
|
||||
def testPublishMultiOptions(self):
|
||||
"""Test publishing multiple items, with options."""
|
||||
payload1 = AtomEntry()
|
||||
payload1['title'] = 'Test 1'
|
||||
|
||||
payload2 = AtomEntry()
|
||||
payload2['title'] = 'Test 2'
|
||||
|
||||
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'
|
||||
|
||||
self.xmpp['xep_0060'].publish(
|
||||
'pubsub.example.com',
|
||||
'somenode',
|
||||
items=[('ID1', payload1),
|
||||
('ID2', payload2)],
|
||||
options=options,
|
||||
block=False)
|
||||
self.send("""
|
||||
<iq type="set" id="1" to="pubsub.example.com">
|
||||
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
||||
<publish node="somenode">
|
||||
<item id="ID1">
|
||||
<entry xmlns="http://www.w3.org/2005/Atom">
|
||||
<title>Test 1</title>
|
||||
</entry>
|
||||
</item>
|
||||
<item id="ID2">
|
||||
<entry xmlns="http://www.w3.org/2005/Atom">
|
||||
<title>Test 2</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)
|
||||
|
||||
def testRetract(self):
|
||||
"""Test deleting an item."""
|
||||
self.xmpp['xep_0060'].retract(
|
||||
|
|
Loading…
Reference in a new issue