2013-07-26 11:02:26 +00:00
|
|
|
import unittest
|
2014-07-17 12:19:04 +00:00
|
|
|
from slixmpp.test import SlixTest
|
|
|
|
import slixmpp.plugins.xep_0004 as xep_0004
|
|
|
|
import slixmpp.plugins.xep_0060.stanza as pubsub
|
|
|
|
from slixmpp.xmlstream.stanzabase import ET
|
2010-01-08 07:01:19 +00:00
|
|
|
|
|
|
|
|
2014-07-17 12:19:04 +00:00
|
|
|
class TestPubsubStanzas(SlixTest):
|
2010-01-08 07:01:19 +00:00
|
|
|
|
2010-07-20 16:18:38 +00:00
|
|
|
def testAffiliations(self):
|
|
|
|
"Testing iq/pubsub/affiliations/affiliation stanzas"
|
|
|
|
iq = self.Iq()
|
|
|
|
aff1 = pubsub.Affiliation()
|
|
|
|
aff1['node'] = 'testnode'
|
|
|
|
aff1['affiliation'] = 'owner'
|
|
|
|
aff2 = pubsub.Affiliation()
|
|
|
|
aff2['node'] = 'testnode2'
|
|
|
|
aff2['affiliation'] = 'publisher'
|
|
|
|
iq['pubsub']['affiliations'].append(aff1)
|
|
|
|
iq['pubsub']['affiliations'].append(aff2)
|
2010-11-05 18:45:58 +00:00
|
|
|
self.check(iq, """
|
2010-07-20 16:18:38 +00:00
|
|
|
<iq id="0">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<affiliations>
|
|
|
|
<affiliation node="testnode" affiliation="owner" />
|
|
|
|
<affiliation node="testnode2" affiliation="publisher" />
|
|
|
|
</affiliations>
|
|
|
|
</pubsub>
|
|
|
|
</iq>""")
|
2010-08-06 00:23:07 +00:00
|
|
|
|
2010-07-20 16:18:38 +00:00
|
|
|
def testSubscriptions(self):
|
|
|
|
"Testing iq/pubsub/subscriptions/subscription stanzas"
|
|
|
|
iq = self.Iq()
|
|
|
|
sub1 = pubsub.Subscription()
|
|
|
|
sub1['node'] = 'testnode'
|
|
|
|
sub1['jid'] = 'steve@myserver.tld/someresource'
|
|
|
|
sub2 = pubsub.Subscription()
|
|
|
|
sub2['node'] = 'testnode2'
|
|
|
|
sub2['jid'] = 'boogers@bork.top/bill'
|
|
|
|
sub2['subscription'] = 'subscribed'
|
|
|
|
iq['pubsub']['subscriptions'].append(sub1)
|
|
|
|
iq['pubsub']['subscriptions'].append(sub2)
|
2010-11-05 18:45:58 +00:00
|
|
|
self.check(iq, """
|
2010-07-20 16:18:38 +00:00
|
|
|
<iq id="0">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<subscriptions>
|
|
|
|
<subscription node="testnode" jid="steve@myserver.tld/someresource" />
|
|
|
|
<subscription node="testnode2" jid="boogers@bork.top/bill" subscription="subscribed" />
|
|
|
|
</subscriptions>
|
|
|
|
</pubsub>
|
|
|
|
</iq>""")
|
2010-04-14 08:23:17 +00:00
|
|
|
|
2010-07-20 16:18:38 +00:00
|
|
|
def testOptionalSettings(self):
|
|
|
|
"Testing iq/pubsub/subscription/subscribe-options stanzas"
|
|
|
|
iq = self.Iq()
|
|
|
|
iq['pubsub']['subscription']['suboptions']['required'] = True
|
|
|
|
iq['pubsub']['subscription']['node'] = 'testnode alsdkjfas'
|
2014-07-17 12:19:04 +00:00
|
|
|
iq['pubsub']['subscription']['jid'] = "fritzy@netflint.net/slixmpp"
|
2010-07-20 16:18:38 +00:00
|
|
|
iq['pubsub']['subscription']['subscription'] = 'unconfigured'
|
2010-11-05 18:45:58 +00:00
|
|
|
self.check(iq, """
|
2010-07-20 16:18:38 +00:00
|
|
|
<iq id="0">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
2014-07-17 12:19:04 +00:00
|
|
|
<subscription node="testnode alsdkjfas" jid="fritzy@netflint.net/slixmpp" subscription="unconfigured">
|
2010-07-20 16:18:38 +00:00
|
|
|
<subscribe-options>
|
|
|
|
<required />
|
|
|
|
</subscribe-options>
|
|
|
|
</subscription>
|
|
|
|
</pubsub>
|
|
|
|
</iq>""")
|
2010-01-08 07:01:19 +00:00
|
|
|
|
2010-07-20 16:18:38 +00:00
|
|
|
def testItems(self):
|
|
|
|
"Testing iq/pubsub/items stanzas"
|
|
|
|
iq = self.Iq()
|
2010-08-22 06:08:48 +00:00
|
|
|
iq['pubsub']['items']['node'] = 'crap'
|
2010-07-20 16:18:38 +00:00
|
|
|
payload = ET.fromstring("""
|
|
|
|
<thinger xmlns="http://andyet.net/protocol/thinger" x="1" y='2'>
|
|
|
|
<child1 />
|
|
|
|
<child2 normandy='cheese' foo='bar' />
|
|
|
|
</thinger>""")
|
|
|
|
payload2 = ET.fromstring("""
|
|
|
|
<thinger2 xmlns="http://andyet.net/protocol/thinger2" x="12" y='22'>
|
|
|
|
<child12 />
|
|
|
|
<child22 normandy='cheese2' foo='bar2' />
|
|
|
|
</thinger2>""")
|
|
|
|
item = pubsub.Item()
|
|
|
|
item['id'] = 'asdf'
|
|
|
|
item['payload'] = payload
|
|
|
|
item2 = pubsub.Item()
|
|
|
|
item2['id'] = 'asdf2'
|
|
|
|
item2['payload'] = payload2
|
|
|
|
iq['pubsub']['items'].append(item)
|
|
|
|
iq['pubsub']['items'].append(item2)
|
2010-11-05 18:45:58 +00:00
|
|
|
self.check(iq, """
|
2010-07-20 16:18:38 +00:00
|
|
|
<iq id="0">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
2010-08-22 06:08:48 +00:00
|
|
|
<items node="crap">
|
2010-07-20 16:18:38 +00:00
|
|
|
<item id="asdf">
|
|
|
|
<thinger xmlns="http://andyet.net/protocol/thinger" y="2" x="1">
|
|
|
|
<child1 />
|
|
|
|
<child2 foo="bar" normandy="cheese" />
|
|
|
|
</thinger>
|
|
|
|
</item>
|
|
|
|
<item id="asdf2">
|
|
|
|
<thinger2 xmlns="http://andyet.net/protocol/thinger2" y="22" x="12">
|
|
|
|
<child12 />
|
|
|
|
<child22 foo="bar2" normandy="cheese2" />
|
|
|
|
</thinger2>
|
|
|
|
</item>
|
|
|
|
</items>
|
|
|
|
</pubsub>
|
|
|
|
</iq>""")
|
2010-04-22 06:51:37 +00:00
|
|
|
|
2010-07-20 16:18:38 +00:00
|
|
|
def testCreate(self):
|
|
|
|
"Testing iq/pubsub/create&configure stanzas"
|
|
|
|
iq = self.Iq()
|
|
|
|
iq['pubsub']['create']['node'] = 'mynode'
|
2010-08-06 00:23:07 +00:00
|
|
|
iq['pubsub']['configure']['form'].addField('pubsub#title',
|
|
|
|
ftype='text-single',
|
2010-07-20 16:18:38 +00:00
|
|
|
value='This thing is awesome')
|
2010-11-05 18:45:58 +00:00
|
|
|
self.check(iq, """
|
2010-07-20 16:18:38 +00:00
|
|
|
<iq id="0">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<create node="mynode" />
|
|
|
|
<configure>
|
|
|
|
<x xmlns="jabber:x:data" type="form">
|
|
|
|
<field var="pubsub#title" type="text-single">
|
|
|
|
<value>This thing is awesome</value>
|
|
|
|
</field>
|
|
|
|
</x>
|
|
|
|
</configure>
|
|
|
|
</pubsub>
|
|
|
|
</iq>""")
|
2010-04-22 06:51:37 +00:00
|
|
|
|
2010-07-20 16:18:38 +00:00
|
|
|
def testDefault(self):
|
2010-08-06 00:23:07 +00:00
|
|
|
"Testing iq/pubsub_owner/default stanzas"
|
|
|
|
iq = self.Iq()
|
|
|
|
iq['pubsub_owner']['default']
|
|
|
|
iq['pubsub_owner']['default']['node'] = 'mynode'
|
2016-10-04 19:15:01 +00:00
|
|
|
iq['pubsub_owner']['default']['form'].add_field('pubsub#title',
|
2010-08-06 00:23:07 +00:00
|
|
|
ftype='text-single',
|
2010-07-20 16:18:38 +00:00
|
|
|
value='This thing is awesome')
|
2010-11-05 18:45:58 +00:00
|
|
|
self.check(iq, """
|
2016-10-04 19:15:01 +00:00
|
|
|
<iq id="0">
|
2010-07-20 16:18:38 +00:00
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
|
2011-08-31 17:43:33 +00:00
|
|
|
<default node="mynode">
|
2010-07-20 16:18:38 +00:00
|
|
|
<x xmlns="jabber:x:data" type="form">
|
|
|
|
<field var="pubsub#title" type="text-single">
|
|
|
|
<value>This thing is awesome</value>
|
|
|
|
</field>
|
|
|
|
</x>
|
|
|
|
</default>
|
|
|
|
</pubsub>
|
|
|
|
</iq>""", use_values=False)
|
2010-04-22 06:51:37 +00:00
|
|
|
|
2010-07-20 16:18:38 +00:00
|
|
|
def testSubscribe(self):
|
2010-08-06 00:23:07 +00:00
|
|
|
"testing iq/pubsub/subscribe stanzas"
|
|
|
|
iq = self.Iq()
|
|
|
|
iq['pubsub']['subscribe']['options']
|
|
|
|
iq['pubsub']['subscribe']['node'] = 'cheese'
|
2014-07-17 12:19:04 +00:00
|
|
|
iq['pubsub']['subscribe']['jid'] = 'fritzy@netflint.net/slixmpp'
|
2010-08-06 00:23:07 +00:00
|
|
|
iq['pubsub']['subscribe']['options']['node'] = 'cheese'
|
2014-07-17 12:19:04 +00:00
|
|
|
iq['pubsub']['subscribe']['options']['jid'] = 'fritzy@netflint.net/slixmpp'
|
2010-08-06 00:23:07 +00:00
|
|
|
form = xep_0004.Form()
|
2016-10-04 19:21:55 +00:00
|
|
|
form['type'] = 'submit'
|
2016-10-04 19:15:01 +00:00
|
|
|
form.add_field('pubsub#title', ftype='text-single', value='this thing is awesome')
|
2010-08-06 00:23:07 +00:00
|
|
|
iq['pubsub']['subscribe']['options']['options'] = form
|
2010-11-05 18:45:58 +00:00
|
|
|
self.check(iq, """
|
2010-08-06 00:23:07 +00:00
|
|
|
<iq id="0">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
2014-07-17 12:19:04 +00:00
|
|
|
<subscribe node="cheese" jid="fritzy@netflint.net/slixmpp">
|
|
|
|
<options node="cheese" jid="fritzy@netflint.net/slixmpp">
|
2011-02-09 02:09:49 +00:00
|
|
|
<x xmlns="jabber:x:data" type="submit">
|
2011-08-12 04:59:55 +00:00
|
|
|
<field var="pubsub#title">
|
2010-08-06 00:23:07 +00:00
|
|
|
<value>this thing is awesome</value>
|
|
|
|
</field>
|
|
|
|
</x>
|
|
|
|
</options>
|
|
|
|
</subscribe>
|
|
|
|
</pubsub>
|
|
|
|
</iq>""", use_values=False)
|
2010-07-20 16:18:38 +00:00
|
|
|
|
|
|
|
def testPublish(self):
|
2010-08-06 00:23:07 +00:00
|
|
|
"Testing iq/pubsub/publish stanzas"
|
|
|
|
iq = self.Iq()
|
|
|
|
iq['pubsub']['publish']['node'] = 'thingers'
|
|
|
|
payload = ET.fromstring("""
|
2010-07-20 16:18:38 +00:00
|
|
|
<thinger xmlns="http://andyet.net/protocol/thinger" x="1" y='2'>
|
|
|
|
<child1 />
|
|
|
|
<child2 normandy='cheese' foo='bar' />
|
|
|
|
</thinger>""")
|
2010-08-06 00:23:07 +00:00
|
|
|
payload2 = ET.fromstring("""
|
2010-07-20 16:18:38 +00:00
|
|
|
<thinger2 xmlns="http://andyet.net/protocol/thinger2" x="12" y='22'>
|
|
|
|
<child12 />
|
|
|
|
<child22 normandy='cheese2' foo='bar2' />
|
|
|
|
</thinger2>""")
|
2010-08-06 00:23:07 +00:00
|
|
|
item = pubsub.Item()
|
|
|
|
item['id'] = 'asdf'
|
|
|
|
item['payload'] = payload
|
|
|
|
item2 = pubsub.Item()
|
|
|
|
item2['id'] = 'asdf2'
|
|
|
|
item2['payload'] = payload2
|
|
|
|
iq['pubsub']['publish'].append(item)
|
|
|
|
iq['pubsub']['publish'].append(item2)
|
2011-08-31 06:03:04 +00:00
|
|
|
form = xep_0004.Form()
|
2016-10-04 19:21:55 +00:00
|
|
|
form['type'] = 'submit'
|
2011-08-31 06:03:04 +00:00
|
|
|
form.addField('pubsub#description', ftype='text-single', value='this thing is awesome')
|
|
|
|
iq['pubsub']['publish_options'] = form
|
2010-08-06 00:23:07 +00:00
|
|
|
|
2010-11-05 18:45:58 +00:00
|
|
|
self.check(iq, """
|
2010-07-20 16:18:38 +00:00
|
|
|
<iq id="0">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<publish node="thingers">
|
|
|
|
<item id="asdf">
|
|
|
|
<thinger xmlns="http://andyet.net/protocol/thinger" y="2" x="1">
|
|
|
|
<child1 />
|
|
|
|
<child2 foo="bar" normandy="cheese" />
|
|
|
|
</thinger>
|
|
|
|
</item>
|
|
|
|
<item id="asdf2">
|
|
|
|
<thinger2 xmlns="http://andyet.net/protocol/thinger2" y="22" x="12">
|
|
|
|
<child12 />
|
|
|
|
<child22 foo="bar2" normandy="cheese2" />
|
|
|
|
</thinger2>
|
|
|
|
</item>
|
|
|
|
</publish>
|
2011-08-31 06:03:04 +00:00
|
|
|
<publish-options>
|
|
|
|
<x xmlns="jabber:x:data" type="submit">
|
|
|
|
<field var="pubsub#description">
|
|
|
|
<value>this thing is awesome</value>
|
|
|
|
</field>
|
|
|
|
</x>
|
|
|
|
</publish-options>
|
2010-07-20 16:18:38 +00:00
|
|
|
</pubsub>
|
|
|
|
</iq>""")
|
|
|
|
|
|
|
|
def testDelete(self):
|
2010-08-06 00:23:07 +00:00
|
|
|
"Testing iq/pubsub_owner/delete stanzas"
|
|
|
|
iq = self.Iq()
|
|
|
|
iq['pubsub_owner']['delete']['node'] = 'thingers'
|
2010-11-05 18:45:58 +00:00
|
|
|
self.check(iq, """
|
2010-08-06 00:23:07 +00:00
|
|
|
<iq id="0">
|
2010-07-20 16:18:38 +00:00
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
|
|
|
|
<delete node="thingers" />
|
|
|
|
</pubsub>
|
|
|
|
</iq>""")
|
|
|
|
|
|
|
|
def testCreateConfigGet(self):
|
2010-08-06 00:23:07 +00:00
|
|
|
"""Testing getting config from full create"""
|
|
|
|
iq = self.Iq()
|
2010-07-20 16:18:38 +00:00
|
|
|
iq['to'] = 'pubsub.asdf'
|
|
|
|
iq['from'] = 'fritzy@asdf/87292ede-524d-4117-9076-d934ed3db8e7'
|
|
|
|
iq['type'] = 'set'
|
|
|
|
iq['id'] = 'E'
|
|
|
|
|
|
|
|
pub = iq['pubsub']
|
|
|
|
pub['create']['node'] = 'testnode2'
|
|
|
|
pub['configure']['form']['type'] = 'submit'
|
2016-10-04 19:15:01 +00:00
|
|
|
pub['configure']['form'].set_fields([
|
2010-07-20 16:18:38 +00:00
|
|
|
('FORM_TYPE', {'type': 'hidden',
|
|
|
|
'value': 'http://jabber.org/protocol/pubsub#node_config'}),
|
|
|
|
('pubsub#node_type', {'type': 'list-single',
|
|
|
|
'label': 'Select the node type',
|
|
|
|
'value': 'leaf'}),
|
|
|
|
('pubsub#title', {'type': 'text-single',
|
|
|
|
'label': 'A friendly name for the node'}),
|
|
|
|
('pubsub#deliver_notifications', {'type': 'boolean',
|
|
|
|
'label': 'Deliver event notifications',
|
|
|
|
'value': True}),
|
|
|
|
('pubsub#deliver_payloads', {'type': 'boolean',
|
|
|
|
'label': 'Deliver payloads with event notifications',
|
|
|
|
'value': True}),
|
|
|
|
('pubsub#notify_config', {'type': 'boolean',
|
|
|
|
'label': 'Notify subscribers when the node configuration changes'}),
|
|
|
|
('pubsub#notify_delete', {'type': 'boolean',
|
|
|
|
'label': 'Notify subscribers when the node is deleted'}),
|
|
|
|
('pubsub#notify_retract', {'type': 'boolean',
|
|
|
|
'label': 'Notify subscribers when items are removed from the node',
|
|
|
|
'value': True}),
|
|
|
|
('pubsub#notify_sub', {'type': 'boolean',
|
|
|
|
'label': 'Notify owners about new subscribers and unsubscribes'}),
|
|
|
|
('pubsub#persist_items', {'type': 'boolean',
|
|
|
|
'label': 'Persist items in storage'}),
|
|
|
|
('pubsub#max_items', {'type': 'text-single',
|
|
|
|
'label': 'Max # of items to persist',
|
|
|
|
'value': '10'}),
|
|
|
|
('pubsub#subscribe', {'type': 'boolean',
|
|
|
|
'label': 'Whether to allow subscriptions',
|
|
|
|
'value': True}),
|
|
|
|
('pubsub#access_model', {'type': 'list-single',
|
|
|
|
'label': 'Specify the subscriber model',
|
|
|
|
'value': 'open'}),
|
|
|
|
('pubsub#publish_model', {'type': 'list-single',
|
|
|
|
'label': 'Specify the publisher model',
|
|
|
|
'value': 'publishers'}),
|
|
|
|
('pubsub#send_last_published_item', {'type': 'list-single',
|
|
|
|
'label': 'Send last published item',
|
|
|
|
'value': 'never'}),
|
|
|
|
('pubsub#presence_based_delivery', {'type': 'boolean',
|
|
|
|
'label': 'Deliver notification only to available users'}),
|
|
|
|
])
|
|
|
|
|
2010-11-05 18:45:58 +00:00
|
|
|
self.check(iq, """
|
2010-07-20 16:18:38 +00:00
|
|
|
<iq to="pubsub.asdf" type="set" id="E" from="fritzy@asdf/87292ede-524d-4117-9076-d934ed3db8e7">
|
|
|
|
<pubsub xmlns="http://jabber.org/protocol/pubsub">
|
|
|
|
<create node="testnode2" />
|
|
|
|
<configure>
|
|
|
|
<x xmlns="jabber:x:data" type="submit">
|
2011-08-12 04:59:55 +00:00
|
|
|
<field var="FORM_TYPE">
|
2010-07-20 16:18:38 +00:00
|
|
|
<value>http://jabber.org/protocol/pubsub#node_config</value>
|
|
|
|
</field>
|
2011-08-12 04:59:55 +00:00
|
|
|
<field var="pubsub#node_type">
|
2010-07-20 16:18:38 +00:00
|
|
|
<value>leaf</value>
|
|
|
|
</field>
|
2011-08-12 04:59:55 +00:00
|
|
|
<field var="pubsub#title" />
|
|
|
|
<field var="pubsub#deliver_notifications">
|
2010-07-20 16:18:38 +00:00
|
|
|
<value>1</value>
|
|
|
|
</field>
|
2011-08-12 04:59:55 +00:00
|
|
|
<field var="pubsub#deliver_payloads">
|
2010-07-20 16:18:38 +00:00
|
|
|
<value>1</value>
|
|
|
|
</field>
|
2011-08-12 04:59:55 +00:00
|
|
|
<field var="pubsub#notify_config" />
|
|
|
|
<field var="pubsub#notify_delete" />
|
|
|
|
<field var="pubsub#notify_retract">
|
2010-07-20 16:18:38 +00:00
|
|
|
<value>1</value>
|
|
|
|
</field>
|
2011-08-12 04:59:55 +00:00
|
|
|
<field var="pubsub#notify_sub" />
|
|
|
|
<field var="pubsub#persist_items" />
|
|
|
|
<field var="pubsub#max_items">
|
2010-07-20 16:18:38 +00:00
|
|
|
<value>10</value>
|
|
|
|
</field>
|
2011-08-12 04:59:55 +00:00
|
|
|
<field var="pubsub#subscribe">
|
2010-07-20 16:18:38 +00:00
|
|
|
<value>1</value>
|
|
|
|
</field>
|
2011-08-12 04:59:55 +00:00
|
|
|
<field var="pubsub#access_model">
|
2010-07-20 16:18:38 +00:00
|
|
|
<value>open</value>
|
|
|
|
</field>
|
2011-08-12 04:59:55 +00:00
|
|
|
<field var="pubsub#publish_model">
|
2010-07-20 16:18:38 +00:00
|
|
|
<value>publishers</value>
|
|
|
|
</field>
|
2011-08-12 04:59:55 +00:00
|
|
|
<field var="pubsub#send_last_published_item">
|
2010-07-20 16:18:38 +00:00
|
|
|
<value>never</value>
|
|
|
|
</field>
|
2011-08-12 04:59:55 +00:00
|
|
|
<field var="pubsub#presence_based_delivery" />
|
2010-07-20 16:18:38 +00:00
|
|
|
</x>
|
|
|
|
</configure>
|
|
|
|
</pubsub>
|
|
|
|
</iq>""")
|
|
|
|
|
|
|
|
def testItemEvent(self):
|
2010-08-06 00:23:07 +00:00
|
|
|
"""Testing message/pubsub_event/items/item"""
|
|
|
|
msg = self.Message()
|
|
|
|
item = pubsub.EventItem()
|
|
|
|
pl = ET.Element('{http://netflint.net/protocol/test}test', {'failed':'3', 'passed':'24'})
|
|
|
|
item['payload'] = pl
|
|
|
|
item['id'] = 'abc123'
|
|
|
|
msg['pubsub_event']['items'].append(item)
|
|
|
|
msg['pubsub_event']['items']['node'] = 'cheese'
|
|
|
|
msg['type'] = 'normal'
|
2010-11-05 18:45:58 +00:00
|
|
|
self.check(msg, """
|
2010-07-20 16:18:38 +00:00
|
|
|
<message type="normal">
|
|
|
|
<event xmlns="http://jabber.org/protocol/pubsub#event">
|
|
|
|
<items node="cheese">
|
|
|
|
<item id="abc123">
|
|
|
|
<test xmlns="http://netflint.net/protocol/test" failed="3" passed="24" />
|
|
|
|
</item>
|
|
|
|
</items>
|
|
|
|
</event>
|
|
|
|
</message>""")
|
|
|
|
|
|
|
|
def testItemsEvent(self):
|
2010-08-06 00:23:07 +00:00
|
|
|
"""Testing multiple message/pubsub_event/items/item"""
|
|
|
|
msg = self.Message()
|
|
|
|
item = pubsub.EventItem()
|
|
|
|
item2 = pubsub.EventItem()
|
|
|
|
pl = ET.Element('{http://netflint.net/protocol/test}test', {'failed':'3', 'passed':'24'})
|
|
|
|
pl2 = ET.Element('{http://netflint.net/protocol/test-other}test', {'total':'27', 'failed':'3'})
|
|
|
|
item2['payload'] = pl2
|
|
|
|
item['payload'] = pl
|
|
|
|
item['id'] = 'abc123'
|
|
|
|
item2['id'] = '123abc'
|
|
|
|
msg['pubsub_event']['items'].append(item)
|
|
|
|
msg['pubsub_event']['items'].append(item2)
|
|
|
|
msg['pubsub_event']['items']['node'] = 'cheese'
|
|
|
|
msg['type'] = 'normal'
|
2010-11-05 18:45:58 +00:00
|
|
|
self.check(msg, """
|
2010-07-20 16:18:38 +00:00
|
|
|
<message type="normal">
|
|
|
|
<event xmlns="http://jabber.org/protocol/pubsub#event">
|
|
|
|
<items node="cheese">
|
|
|
|
<item id="abc123">
|
|
|
|
<test xmlns="http://netflint.net/protocol/test" failed="3" passed="24" />
|
|
|
|
</item>
|
|
|
|
<item id="123abc">
|
|
|
|
<test xmlns="http://netflint.net/protocol/test-other" failed="3" total="27" />
|
|
|
|
</item>
|
|
|
|
</items>
|
|
|
|
</event>
|
|
|
|
</message>""")
|
|
|
|
|
|
|
|
def testItemsEvent(self):
|
2010-08-06 00:23:07 +00:00
|
|
|
"""Testing message/pubsub_event/items/item & retract mix"""
|
|
|
|
msg = self.Message()
|
|
|
|
item = pubsub.EventItem()
|
|
|
|
item2 = pubsub.EventItem()
|
|
|
|
pl = ET.Element('{http://netflint.net/protocol/test}test', {'failed':'3', 'passed':'24'})
|
|
|
|
pl2 = ET.Element('{http://netflint.net/protocol/test-other}test', {'total':'27', 'failed':'3'})
|
|
|
|
item2['payload'] = pl2
|
|
|
|
retract = pubsub.EventRetract()
|
|
|
|
retract['id'] = 'aabbcc'
|
|
|
|
item['payload'] = pl
|
|
|
|
item['id'] = 'abc123'
|
|
|
|
item2['id'] = '123abc'
|
|
|
|
msg['pubsub_event']['items'].append(item)
|
|
|
|
msg['pubsub_event']['items'].append(retract)
|
|
|
|
msg['pubsub_event']['items'].append(item2)
|
|
|
|
msg['pubsub_event']['items']['node'] = 'cheese'
|
|
|
|
msg['type'] = 'normal'
|
2010-11-05 18:45:58 +00:00
|
|
|
self.check(msg, """
|
2010-07-20 16:18:38 +00:00
|
|
|
<message type="normal">
|
|
|
|
<event xmlns="http://jabber.org/protocol/pubsub#event">
|
|
|
|
<items node="cheese">
|
|
|
|
<item id="abc123">
|
|
|
|
<test xmlns="http://netflint.net/protocol/test" failed="3" passed="24" />
|
|
|
|
</item><retract id="aabbcc" />
|
|
|
|
<item id="123abc">
|
|
|
|
<test xmlns="http://netflint.net/protocol/test-other" failed="3" total="27" />
|
|
|
|
</item>
|
|
|
|
</items>
|
|
|
|
</event>
|
|
|
|
</message>""")
|
|
|
|
|
|
|
|
def testCollectionAssociate(self):
|
2010-08-06 00:23:07 +00:00
|
|
|
"""Testing message/pubsub_event/collection/associate"""
|
|
|
|
msg = self.Message()
|
|
|
|
msg['pubsub_event']['collection']['associate']['node'] = 'cheese'
|
|
|
|
msg['pubsub_event']['collection']['node'] = 'cheeseburger'
|
|
|
|
msg['type'] = 'headline'
|
2010-11-05 18:45:58 +00:00
|
|
|
self.check(msg, """
|
2010-07-20 16:18:38 +00:00
|
|
|
<message type="headline">
|
|
|
|
<event xmlns="http://jabber.org/protocol/pubsub#event">
|
|
|
|
<collection node="cheeseburger">
|
|
|
|
<associate node="cheese" />
|
|
|
|
</collection>
|
|
|
|
</event>
|
|
|
|
</message>""")
|
|
|
|
|
|
|
|
def testCollectionDisassociate(self):
|
2010-08-06 00:23:07 +00:00
|
|
|
"""Testing message/pubsub_event/collection/disassociate"""
|
|
|
|
msg = self.Message()
|
|
|
|
msg['pubsub_event']['collection']['disassociate']['node'] = 'cheese'
|
|
|
|
msg['pubsub_event']['collection']['node'] = 'cheeseburger'
|
|
|
|
msg['type'] = 'headline'
|
2010-11-05 18:45:58 +00:00
|
|
|
self.check(msg, """
|
2010-07-20 16:18:38 +00:00
|
|
|
<message type="headline">
|
|
|
|
<event xmlns="http://jabber.org/protocol/pubsub#event">
|
|
|
|
<collection node="cheeseburger">
|
|
|
|
<disassociate node="cheese" />
|
|
|
|
</collection>
|
|
|
|
</event>
|
|
|
|
</message>""")
|
|
|
|
|
|
|
|
def testEventConfiguration(self):
|
2010-08-06 00:23:07 +00:00
|
|
|
"""Testing message/pubsub_event/configuration/config"""
|
|
|
|
msg = self.Message()
|
|
|
|
msg['pubsub_event']['configuration']['node'] = 'cheese'
|
|
|
|
msg['pubsub_event']['configuration']['form'].addField('pubsub#title',
|
|
|
|
ftype='text-single',
|
2010-07-20 16:18:38 +00:00
|
|
|
value='This thing is awesome')
|
2010-08-06 00:23:07 +00:00
|
|
|
msg['type'] = 'headline'
|
2010-11-05 18:45:58 +00:00
|
|
|
self.check(msg, """
|
2010-08-06 00:23:07 +00:00
|
|
|
<message type="headline">
|
2010-07-20 16:18:38 +00:00
|
|
|
<event xmlns="http://jabber.org/protocol/pubsub#event">
|
|
|
|
<configuration node="cheese">
|
|
|
|
<x xmlns="jabber:x:data" type="form">
|
|
|
|
<field var="pubsub#title" type="text-single">
|
|
|
|
<value>This thing is awesome</value>
|
|
|
|
</field>
|
|
|
|
</x>
|
|
|
|
</configuration>
|
|
|
|
</event>
|
|
|
|
</message>""")
|
|
|
|
|
|
|
|
def testEventPurge(self):
|
2010-08-06 00:23:07 +00:00
|
|
|
"""Testing message/pubsub_event/purge"""
|
|
|
|
msg = self.Message()
|
|
|
|
msg['pubsub_event']['purge']['node'] = 'pickles'
|
|
|
|
msg['type'] = 'headline'
|
2010-11-05 18:45:58 +00:00
|
|
|
self.check(msg, """
|
2010-07-20 16:18:38 +00:00
|
|
|
<message type="headline">
|
|
|
|
<event xmlns="http://jabber.org/protocol/pubsub#event">
|
|
|
|
<purge node="pickles" />
|
|
|
|
</event>
|
|
|
|
</message>""")
|
|
|
|
|
|
|
|
def testEventSubscription(self):
|
2010-08-06 00:23:07 +00:00
|
|
|
"""Testing message/pubsub_event/subscription"""
|
|
|
|
msg = self.Message()
|
|
|
|
msg['pubsub_event']['subscription']['node'] = 'pickles'
|
|
|
|
msg['pubsub_event']['subscription']['jid'] = 'fritzy@netflint.net/test'
|
|
|
|
msg['pubsub_event']['subscription']['subid'] = 'aabb1122'
|
|
|
|
msg['pubsub_event']['subscription']['subscription'] = 'subscribed'
|
|
|
|
msg['pubsub_event']['subscription']['expiry'] = 'presence'
|
|
|
|
msg['type'] = 'headline'
|
2010-11-05 18:45:58 +00:00
|
|
|
self.check(msg, """
|
2010-07-20 16:18:38 +00:00
|
|
|
<message type="headline">
|
|
|
|
<event xmlns="http://jabber.org/protocol/pubsub#event">
|
|
|
|
<subscription node="pickles" subid="aabb1122" jid="fritzy@netflint.net/test" subscription="subscribed" expiry="presence" />
|
|
|
|
</event>
|
|
|
|
</message>""")
|
2010-04-22 06:51:37 +00:00
|
|
|
|
2011-09-01 22:26:54 +00:00
|
|
|
def testPubsubError(self):
|
|
|
|
"""Test getting a pubsub specific condition from an error stanza"""
|
|
|
|
iq = self.Iq()
|
|
|
|
iq['error']['type'] = 'cancel'
|
|
|
|
iq['error']['code'] = '501'
|
|
|
|
iq['error']['condition'] = 'feature-not-implemented'
|
|
|
|
iq['error']['pubsub']['condition'] = 'subid-required'
|
|
|
|
self.check(iq, """
|
|
|
|
<iq type="error">
|
|
|
|
<error type="cancel" code="501">
|
|
|
|
<feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
|
|
|
|
<subid-required xmlns="http://jabber.org/protocol/pubsub#errors" />
|
|
|
|
</error>
|
|
|
|
</iq>
|
|
|
|
""", use_values=False)
|
|
|
|
|
|
|
|
del iq['error']['pubsub']['condition']
|
|
|
|
self.check(iq, """
|
|
|
|
<iq type="error">
|
|
|
|
<error type="cancel" code="501">
|
|
|
|
<feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
|
|
|
|
</error>
|
|
|
|
</iq>
|
|
|
|
""", use_values=False)
|
|
|
|
|
|
|
|
def testPubsubUnsupportedError(self):
|
|
|
|
"""Test getting the feature from an unsupported error"""
|
|
|
|
iq = self.Iq()
|
|
|
|
iq['error']['type'] = 'cancel'
|
|
|
|
iq['error']['code'] = '501'
|
|
|
|
iq['error']['condition'] = 'feature-not-implemented'
|
|
|
|
iq['error']['pubsub']['condition'] = 'unsupported'
|
|
|
|
iq['error']['pubsub']['unsupported'] = 'instant-node'
|
|
|
|
self.check(iq, """
|
|
|
|
<iq type="error">
|
|
|
|
<error type="cancel" code="501">
|
|
|
|
<feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
|
|
|
|
<unsupported xmlns="http://jabber.org/protocol/pubsub#errors" feature="instant-node" />
|
|
|
|
</error>
|
|
|
|
</iq>
|
|
|
|
""", use_values=False)
|
|
|
|
|
|
|
|
self.assertEqual(iq['error']['pubsub']['condition'], 'unsupported')
|
|
|
|
self.assertEqual(iq['error']['pubsub']['unsupported'], 'instant-node')
|
|
|
|
|
|
|
|
del iq['error']['pubsub']['unsupported']
|
|
|
|
self.check(iq, """
|
|
|
|
<iq type="error">
|
|
|
|
<error type="cancel" code="501">
|
|
|
|
<feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
|
|
|
|
</error>
|
|
|
|
</iq>
|
|
|
|
""", use_values=False)
|
|
|
|
|
|
|
|
|
2010-07-20 16:18:38 +00:00
|
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(TestPubsubStanzas)
|