Updated tests to use a relative import for SleekTest to please Python3.

Fixed some tabs/spaces issues.
This commit is contained in:
Lance Stout 2010-08-05 20:23:07 -04:00
parent c54466596f
commit 58f77d898f
13 changed files with 337 additions and 336 deletions

View file

@ -1,110 +1,111 @@
from sleektest import * from . sleektest import *
import sleekxmpp.plugins.xep_0033 as xep_0033 import sleekxmpp.plugins.xep_0033 as xep_0033
class TestAddresses(SleekTest): class TestAddresses(SleekTest):
def setUp(self): def setUp(self):
registerStanzaPlugin(Message, xep_0033.Addresses) registerStanzaPlugin(Message, xep_0033.Addresses)
def testAddAddress(self): def testAddAddress(self):
"""Testing adding extended stanza address.""" """Testing adding extended stanza address."""
msg = self.Message() msg = self.Message()
msg['addresses'].addAddress(atype='to', jid='to@header1.org') msg['addresses'].addAddress(atype='to', jid='to@header1.org')
self.checkMessage(msg, """ self.checkMessage(msg, """
<message> <message>
<addresses xmlns="http://jabber.org/protocol/address"> <addresses xmlns="http://jabber.org/protocol/address">
<address jid="to@header1.org" type="to" /> <address jid="to@header1.org" type="to" />
</addresses> </addresses>
</message> </message>
""") """)
msg = self.Message() msg = self.Message()
msg['addresses'].addAddress(atype='replyto', msg['addresses'].addAddress(atype='replyto',
jid='replyto@header1.org', jid='replyto@header1.org',
desc='Reply address') desc='Reply address')
self.checkMessage(msg, """ self.checkMessage(msg, """
<message> <message>
<addresses xmlns="http://jabber.org/protocol/address"> <addresses xmlns="http://jabber.org/protocol/address">
<address jid="replyto@header1.org" type="replyto" desc="Reply address" /> <address jid="replyto@header1.org" type="replyto" desc="Reply address" />
</addresses> </addresses>
</message> </message>
""") """)
def testAddAddresses(self): def testAddAddresses(self):
"""Testing adding multiple extended stanza addresses.""" """Testing adding multiple extended stanza addresses."""
xmlstring = """ xmlstring = """
<message> <message>
<addresses xmlns="http://jabber.org/protocol/address"> <addresses xmlns="http://jabber.org/protocol/address">
<address jid="replyto@header1.org" type="replyto" desc="Reply address" /> <address jid="replyto@header1.org" type="replyto" desc="Reply address" />
<address jid="cc@header2.org" type="cc" /> <address jid="cc@header2.org" type="cc" />
<address jid="bcc@header2.org" type="bcc" /> <address jid="bcc@header2.org" type="bcc" />
</addresses> </addresses>
</message> </message>
""" """
msg = self.Message() msg = self.Message()
msg['addresses'].setAddresses([{'type':'replyto', msg['addresses'].setAddresses([
'jid':'replyto@header1.org', {'type':'replyto',
'desc':'Reply address'}, 'jid':'replyto@header1.org',
{'type':'cc', 'desc':'Reply address'},
'jid':'cc@header2.org'}, {'type':'cc',
{'type':'bcc', 'jid':'cc@header2.org'},
'jid':'bcc@header2.org'}]) {'type':'bcc',
self.checkMessage(msg, xmlstring) 'jid':'bcc@header2.org'}])
self.checkMessage(msg, xmlstring)
msg = self.Message() msg = self.Message()
msg['addresses']['replyto'] = [{'jid':'replyto@header1.org', msg['addresses']['replyto'] = [{'jid':'replyto@header1.org',
'desc':'Reply address'}] 'desc':'Reply address'}]
msg['addresses']['cc'] = [{'jid':'cc@header2.org'}] msg['addresses']['cc'] = [{'jid':'cc@header2.org'}]
msg['addresses']['bcc'] = [{'jid':'bcc@header2.org'}] msg['addresses']['bcc'] = [{'jid':'bcc@header2.org'}]
self.checkMessage(msg, xmlstring) self.checkMessage(msg, xmlstring)
def testAddURI(self): def testAddURI(self):
"""Testing adding URI attribute to extended stanza address.""" """Testing adding URI attribute to extended stanza address."""
msg = self.Message() msg = self.Message()
addr = msg['addresses'].addAddress(atype='to', addr = msg['addresses'].addAddress(atype='to',
jid='to@header1.org', jid='to@header1.org',
node='foo') node='foo')
self.checkMessage(msg, """ self.checkMessage(msg, """
<message> <message>
<addresses xmlns="http://jabber.org/protocol/address"> <addresses xmlns="http://jabber.org/protocol/address">
<address node="foo" jid="to@header1.org" type="to" /> <address node="foo" jid="to@header1.org" type="to" />
</addresses> </addresses>
</message> </message>
""") """)
addr['uri'] = 'mailto:to@header2.org' addr['uri'] = 'mailto:to@header2.org'
self.checkMessage(msg, """ self.checkMessage(msg, """
<message> <message>
<addresses xmlns="http://jabber.org/protocol/address"> <addresses xmlns="http://jabber.org/protocol/address">
<address type="to" uri="mailto:to@header2.org" /> <address type="to" uri="mailto:to@header2.org" />
</addresses> </addresses>
</message> </message>
""") """)
def testDelivered(self): def testDelivered(self):
"""Testing delivered attribute of extended stanza addresses.""" """Testing delivered attribute of extended stanza addresses."""
xmlstring = """ xmlstring = """
<message> <message>
<addresses xmlns="http://jabber.org/protocol/address"> <addresses xmlns="http://jabber.org/protocol/address">
<address %s jid="to@header1.org" type="to" /> <address %s jid="to@header1.org" type="to" />
</addresses> </addresses>
</message> </message>
""" """
msg = self.Message() msg = self.Message()
addr = msg['addresses'].addAddress(jid='to@header1.org', atype='to') addr = msg['addresses'].addAddress(jid='to@header1.org', atype='to')
self.checkMessage(msg, xmlstring % '') self.checkMessage(msg, xmlstring % '')
addr['delivered'] = True addr['delivered'] = True
self.checkMessage(msg, xmlstring % 'delivered="true"') self.checkMessage(msg, xmlstring % 'delivered="true"')
addr['delivered'] = False addr['delivered'] = False
self.checkMessage(msg, xmlstring % '') self.checkMessage(msg, xmlstring % '')
suite = unittest.TestLoader().loadTestsFromTestCase(TestAddresses) suite = unittest.TestLoader().loadTestsFromTestCase(TestAddresses)

View file

@ -1,44 +1,44 @@
from sleektest import * from . sleektest import *
import sleekxmpp.plugins.xep_0085 as xep_0085 import sleekxmpp.plugins.xep_0085 as xep_0085
class TestChatStates(SleekTest): class TestChatStates(SleekTest):
def setUp(self): def setUp(self):
registerStanzaPlugin(Message, xep_0085.Active) registerStanzaPlugin(Message, xep_0085.Active)
registerStanzaPlugin(Message, xep_0085.Composing) registerStanzaPlugin(Message, xep_0085.Composing)
registerStanzaPlugin(Message, xep_0085.Gone) registerStanzaPlugin(Message, xep_0085.Gone)
registerStanzaPlugin(Message, xep_0085.Inactive) registerStanzaPlugin(Message, xep_0085.Inactive)
registerStanzaPlugin(Message, xep_0085.Paused) registerStanzaPlugin(Message, xep_0085.Paused)
def testCreateChatState(self):
"""Testing creating chat states."""
xmlstring = """
<message>
<%s xmlns="http://jabber.org/protocol/chatstates" />
</message>
"""
msg = self.Message() def testCreateChatState(self):
msg['chat_state'].active() """Testing creating chat states."""
self.checkMessage(msg, xmlstring % 'active',
use_values=False)
msg['chat_state'].composing() xmlstring = """
self.checkMessage(msg, xmlstring % 'composing', <message>
use_values=False) <%s xmlns="http://jabber.org/protocol/chatstates" />
</message>
"""
msg = self.Message()
msg['chat_state'].active()
self.checkMessage(msg, xmlstring % 'active',
use_values=False)
msg['chat_state'].composing()
self.checkMessage(msg, xmlstring % 'composing',
use_values=False)
msg['chat_state'].gone() msg['chat_state'].gone()
self.checkMessage(msg, xmlstring % 'gone', self.checkMessage(msg, xmlstring % 'gone',
use_values=False) use_values=False)
msg['chat_state'].inactive() msg['chat_state'].inactive()
self.checkMessage(msg, xmlstring % 'inactive', self.checkMessage(msg, xmlstring % 'inactive',
use_values=False) use_values=False)
msg['chat_state'].paused() msg['chat_state'].paused()
self.checkMessage(msg, xmlstring % 'paused', self.checkMessage(msg, xmlstring % 'paused',
use_values=False) use_values=False)
suite = unittest.TestLoader().loadTestsFromTestCase(TestChatStates) suite = unittest.TestLoader().loadTestsFromTestCase(TestChatStates)

View file

@ -1,4 +1,4 @@
from sleektest import * from . sleektest import *
import sleekxmpp.plugins.xep_0030 as xep_0030 import sleekxmpp.plugins.xep_0030 as xep_0030
@ -7,7 +7,7 @@ class TestDisco(SleekTest):
def setUp(self): def setUp(self):
registerStanzaPlugin(Iq, xep_0030.DiscoInfo) registerStanzaPlugin(Iq, xep_0030.DiscoInfo)
registerStanzaPlugin(Iq, xep_0030.DiscoItems) registerStanzaPlugin(Iq, xep_0030.DiscoItems)
def testCreateInfoQueryNoNode(self): def testCreateInfoQueryNoNode(self):
"""Testing disco#info query with no node.""" """Testing disco#info query with no node."""
iq = self.Iq() iq = self.Iq()
@ -61,7 +61,7 @@ class TestDisco(SleekTest):
iq = self.Iq() iq = self.Iq()
iq['id'] = "0" iq['id'] = "0"
iq['disco_info']['node'] = 'foo' iq['disco_info']['node'] = 'foo'
iq['disco_info'].addIdentity('conference', 'text', 'Chatroom') iq['disco_info'].addIdentity('conference', 'text', 'Chatroom')
self.checkIq(iq, """ self.checkIq(iq, """
<iq id="0"> <iq id="0">
@ -76,8 +76,8 @@ class TestDisco(SleekTest):
iq = self.Iq() iq = self.Iq()
iq['id'] = "0" iq['id'] = "0"
iq['disco_info']['node'] = 'foo' iq['disco_info']['node'] = 'foo'
iq['disco_info'].addFeature('foo') iq['disco_info'].addFeature('foo')
iq['disco_info'].addFeature('bar') iq['disco_info'].addFeature('bar')
self.checkIq(iq, """ self.checkIq(iq, """
<iq id="0"> <iq id="0">
@ -93,9 +93,9 @@ class TestDisco(SleekTest):
iq = self.Iq() iq = self.Iq()
iq['id'] = "0" iq['id'] = "0"
iq['disco_items']['node'] = 'foo' iq['disco_items']['node'] = 'foo'
iq['disco_items'].addItem('user@localhost') iq['disco_items'].addItem('user@localhost')
iq['disco_items'].addItem('user@localhost', 'foo') iq['disco_items'].addItem('user@localhost', 'foo')
iq['disco_items'].addItem('user@localhost', 'bar', 'Testing') iq['disco_items'].addItem('user@localhost', 'bar', 'Testing')
self.checkIq(iq, """ self.checkIq(iq, """
<iq id="0"> <iq id="0">
@ -109,68 +109,68 @@ class TestDisco(SleekTest):
def testAddRemoveIdentities(self): def testAddRemoveIdentities(self):
"""Test adding and removing identities to disco#info stanza""" """Test adding and removing identities to disco#info stanza"""
ids = [('automation', 'commands', 'AdHoc'), ids = [('automation', 'commands', 'AdHoc'),
('conference', 'text', 'ChatRoom')] ('conference', 'text', 'ChatRoom')]
info = xep_0030.DiscoInfo() info = xep_0030.DiscoInfo()
info.addIdentity(*ids[0]) info.addIdentity(*ids[0])
self.failUnless(info.getIdentities() == [ids[0]]) self.failUnless(info.getIdentities() == [ids[0]])
info.delIdentity('automation', 'commands') info.delIdentity('automation', 'commands')
self.failUnless(info.getIdentities() == []) self.failUnless(info.getIdentities() == [])
info.setIdentities(ids) info.setIdentities(ids)
self.failUnless(info.getIdentities() == ids) self.failUnless(info.getIdentities() == ids)
info.delIdentity('automation', 'commands') info.delIdentity('automation', 'commands')
self.failUnless(info.getIdentities() == [ids[1]]) self.failUnless(info.getIdentities() == [ids[1]])
info.delIdentities() info.delIdentities()
self.failUnless(info.getIdentities() == []) self.failUnless(info.getIdentities() == [])
def testAddRemoveFeatures(self): def testAddRemoveFeatures(self):
"""Test adding and removing features to disco#info stanza""" """Test adding and removing features to disco#info stanza"""
features = ['foo', 'bar', 'baz'] features = ['foo', 'bar', 'baz']
info = xep_0030.DiscoInfo() info = xep_0030.DiscoInfo()
info.addFeature(features[0]) info.addFeature(features[0])
self.failUnless(info.getFeatures() == [features[0]]) self.failUnless(info.getFeatures() == [features[0]])
info.delFeature('foo') info.delFeature('foo')
self.failUnless(info.getFeatures() == []) self.failUnless(info.getFeatures() == [])
info.setFeatures(features) info.setFeatures(features)
self.failUnless(info.getFeatures() == features) self.failUnless(info.getFeatures() == features)
info.delFeature('bar') info.delFeature('bar')
self.failUnless(info.getFeatures() == ['foo', 'baz']) self.failUnless(info.getFeatures() == ['foo', 'baz'])
info.delFeatures() info.delFeatures()
self.failUnless(info.getFeatures() == []) self.failUnless(info.getFeatures() == [])
def testAddRemoveItems(self): def testAddRemoveItems(self):
"""Test adding and removing items to disco#items stanza""" """Test adding and removing items to disco#items stanza"""
items = [('user@localhost', None, None), items = [('user@localhost', None, None),
('user@localhost', 'foo', None), ('user@localhost', 'foo', None),
('user@localhost', 'bar', 'Test')] ('user@localhost', 'bar', 'Test')]
info = xep_0030.DiscoItems() info = xep_0030.DiscoItems()
self.failUnless(True, ""+str(items[0])) self.failUnless(True, ""+str(items[0]))
info.addItem(*(items[0])) info.addItem(*(items[0]))
self.failUnless(info.getItems() == [items[0]], info.getItems()) self.failUnless(info.getItems() == [items[0]], info.getItems())
info.delItem('user@localhost') info.delItem('user@localhost')
self.failUnless(info.getItems() == []) self.failUnless(info.getItems() == [])
info.setItems(items) info.setItems(items)
self.failUnless(info.getItems() == items) self.failUnless(info.getItems() == items)
info.delItem('user@localhost', 'foo') info.delItem('user@localhost', 'foo')
self.failUnless(info.getItems() == [items[0], items[2]]) self.failUnless(info.getItems() == [items[0], items[2]])
info.delItems()
self.failUnless(info.getItems() == [])
info.delItems()
self.failUnless(info.getItems() == [])
suite = unittest.TestLoader().loadTestsFromTestCase(TestDisco) suite = unittest.TestLoader().loadTestsFromTestCase(TestDisco)

View file

@ -1,7 +1,7 @@
from sleektest import * from . sleektest import *
class TestErrorStanzas(SleekTest): class TestErrorStanzas(SleekTest):
def testSetup(self): def testSetup(self):
"""Test setting initial values in error stanza.""" """Test setting initial values in error stanza."""
msg = self.Message() msg = self.Message()
@ -16,7 +16,7 @@ class TestErrorStanzas(SleekTest):
def testCondition(self): def testCondition(self):
"""Test modifying the error condition.""" """Test modifying the error condition."""
msg = self.Message() msg = self.Message()
msg['error']['condition'] = 'item-not-found' msg['error']['condition'] = 'item-not-found'
self.checkMessage(msg, """ self.checkMessage(msg, """
@ -42,7 +42,7 @@ class TestErrorStanzas(SleekTest):
msg = self.Message() msg = self.Message()
msg['error']['text'] = 'Error!' msg['error']['text'] = 'Error!'
msg['error']['condition'] = 'internal-server-error' msg['error']['condition'] = 'internal-server-error'
del msg['error']['condition'] del msg['error']['condition']
self.checkMessage(msg, """ self.checkMessage(msg, """

View file

@ -1,5 +1,5 @@
import sleekxmpp import sleekxmpp
from sleektest import * from . sleektest import *
class TestEvents(SleekTest): class TestEvents(SleekTest):

View file

@ -1,4 +1,4 @@
from sleektest import * from . sleektest import *
import sleekxmpp.plugins.xep_0004 as xep_0004 import sleekxmpp.plugins.xep_0004 as xep_0004
@ -28,11 +28,11 @@ class TestDataForms(SleekTest):
msg = self.Message() msg = self.Message()
form = msg['form'] form = msg['form']
form.addField(var='f1', form.addField(var='f1',
ftype='text-single', ftype='text-single',
label='Text', label='Text',
desc='A text field', desc='A text field',
required=True, required=True,
value='Some text!') value='Some text!')
self.checkMessage(msg, """ self.checkMessage(msg, """
@ -47,8 +47,8 @@ class TestDataForms(SleekTest):
</message> </message>
""") """)
form['fields'] = [('f1', {'type': 'text-single', form['fields'] = [('f1', {'type': 'text-single',
'label': 'Username', 'label': 'Username',
'required': True}), 'required': True}),
('f2', {'type': 'text-private', ('f2', {'type': 'text-private',
'label': 'Password', 'label': 'Password',
@ -58,7 +58,7 @@ class TestDataForms(SleekTest):
'value': 'Enter message.\nA long one even.'}), 'value': 'Enter message.\nA long one even.'}),
('f4', {'type': 'list-single', ('f4', {'type': 'list-single',
'label': 'Message Type', 'label': 'Message Type',
'options': [{'label': 'Cool!', 'options': [{'label': 'Cool!',
'value': 'cool'}, 'value': 'cool'},
{'label': 'Urgh!', {'label': 'Urgh!',
'value': 'urgh'}]})] 'value': 'urgh'}]})]
@ -89,13 +89,13 @@ class TestDataForms(SleekTest):
def testSetValues(self): def testSetValues(self):
"""Testing setting form values""" """Testing setting form values"""
msg = self.Message() msg = self.Message()
form = msg['form'] form = msg['form']
form.setFields([ form.setFields([
('foo', {'type': 'text-single'}), ('foo', {'type': 'text-single'}),
('bar', {'type': 'list-multi'})]) ('bar', {'type': 'list-multi'})])
form.setValues({'foo': 'Foo!', form.setValues({'foo': 'Foo!',
'bar': ['a', 'b']}) 'bar': ['a', 'b']})

View file

@ -1,4 +1,4 @@
from sleektest import * from . sleektest import *
import sleekxmpp.plugins.gmail_notify as gmail import sleekxmpp.plugins.gmail_notify as gmail

View file

@ -1,4 +1,4 @@
from sleektest import * from . sleektest import *
from sleekxmpp.xmlstream.stanzabase import ET from sleekxmpp.xmlstream.stanzabase import ET
@ -18,7 +18,7 @@ class TestIqStanzas(SleekTest):
self.checkIq(iq, """ self.checkIq(iq, """
<iq id="0" /> <iq id="0" />
""") """)
def testPayload(self): def testPayload(self):
"""Test setting Iq stanza payload.""" """Test setting Iq stanza payload."""
iq = self.Iq() iq = self.Iq()
@ -38,10 +38,10 @@ class TestIqStanzas(SleekTest):
</iq> </iq>
""") """)
iq = self.Iq() iq = self.Iq()
iq['id'] = 'test' iq['id'] = 'test'
iq['error']['condition'] = 'feature-not-implemented' iq['error']['condition'] = 'feature-not-implemented'
iq['error']['text'] = 'No handlers registered for this request.' iq['error']['text'] = 'No handlers registered for this request.'
self.streamSendIq(iq, """ self.streamSendIq(iq, """
<iq id="test" type="error"> <iq id="test" type="error">
@ -72,21 +72,21 @@ class TestIqStanzas(SleekTest):
</iq> </iq>
""") """)
self.failUnless(iq['query'] == 'query_ns2', "Query namespace doesn't match") self.failUnless(iq['query'] == 'query_ns2', "Query namespace doesn't match")
del iq['query'] del iq['query']
self.checkIq(iq, """ self.checkIq(iq, """
<iq id="0" /> <iq id="0" />
""") """)
def testReply(self): def testReply(self):
"""Test setting proper result type in Iq replies.""" """Test setting proper result type in Iq replies."""
iq = self.Iq() iq = self.Iq()
iq['to'] = 'user@localhost' iq['to'] = 'user@localhost'
iq['type'] = 'get' iq['type'] = 'get'
iq.reply() iq.reply()
self.checkIq(iq, """ self.checkIq(iq, """
<iq id="0" type="result" /> <iq id="0" type="result" />
""") """)

View file

@ -1,4 +1,4 @@
from sleektest import * from . sleektest import *
from sleekxmpp.xmlstream.jid import JID from sleekxmpp.xmlstream.jid import JID
class TestJIDClass(SleekTest): class TestJIDClass(SleekTest):

View file

@ -1,4 +1,4 @@
from sleektest import * from . sleektest import *
from sleekxmpp.stanza.message import Message from sleekxmpp.stanza.message import Message
from sleekxmpp.stanza.htmlim import HTMLIM from sleekxmpp.stanza.htmlim import HTMLIM

View file

@ -1,5 +1,5 @@
import sleekxmpp import sleekxmpp
from sleektest import * from . sleektest import *
from sleekxmpp.stanza.presence import Presence from sleekxmpp.stanza.presence import Presence

View file

@ -1,4 +1,4 @@
from sleektest import * from . sleektest import *
import sleekxmpp.plugins.xep_0004 as xep_0004 import sleekxmpp.plugins.xep_0004 as xep_0004
import sleekxmpp.plugins.stanza_pubsub as pubsub import sleekxmpp.plugins.stanza_pubsub as pubsub
@ -25,7 +25,7 @@ class TestPubsubStanzas(SleekTest):
</affiliations> </affiliations>
</pubsub> </pubsub>
</iq>""") </iq>""")
def testSubscriptions(self): def testSubscriptions(self):
"Testing iq/pubsub/subscriptions/subscription stanzas" "Testing iq/pubsub/subscriptions/subscription stanzas"
iq = self.Iq() iq = self.Iq()
@ -38,7 +38,7 @@ class TestPubsubStanzas(SleekTest):
sub2['subscription'] = 'subscribed' sub2['subscription'] = 'subscribed'
iq['pubsub']['subscriptions'].append(sub1) iq['pubsub']['subscriptions'].append(sub1)
iq['pubsub']['subscriptions'].append(sub2) iq['pubsub']['subscriptions'].append(sub2)
self.checkIq(iq, """ self.checkIq(iq, """
<iq id="0"> <iq id="0">
<pubsub xmlns="http://jabber.org/protocol/pubsub"> <pubsub xmlns="http://jabber.org/protocol/pubsub">
<subscriptions> <subscriptions>
@ -55,7 +55,7 @@ class TestPubsubStanzas(SleekTest):
iq['pubsub']['subscription']['node'] = 'testnode alsdkjfas' iq['pubsub']['subscription']['node'] = 'testnode alsdkjfas'
iq['pubsub']['subscription']['jid'] = "fritzy@netflint.net/sleekxmpp" iq['pubsub']['subscription']['jid'] = "fritzy@netflint.net/sleekxmpp"
iq['pubsub']['subscription']['subscription'] = 'unconfigured' iq['pubsub']['subscription']['subscription'] = 'unconfigured'
self.checkIq(iq, """ self.checkIq(iq, """
<iq id="0"> <iq id="0">
<pubsub xmlns="http://jabber.org/protocol/pubsub"> <pubsub xmlns="http://jabber.org/protocol/pubsub">
<subscription node="testnode alsdkjfas" jid="fritzy@netflint.net/sleekxmpp" subscription="unconfigured"> <subscription node="testnode alsdkjfas" jid="fritzy@netflint.net/sleekxmpp" subscription="unconfigured">
@ -88,7 +88,7 @@ class TestPubsubStanzas(SleekTest):
item2['payload'] = payload2 item2['payload'] = payload2
iq['pubsub']['items'].append(item) iq['pubsub']['items'].append(item)
iq['pubsub']['items'].append(item2) iq['pubsub']['items'].append(item2)
self.checkIq(iq, """ self.checkIq(iq, """
<iq id="0"> <iq id="0">
<pubsub xmlns="http://jabber.org/protocol/pubsub"> <pubsub xmlns="http://jabber.org/protocol/pubsub">
<items> <items>
@ -112,8 +112,8 @@ class TestPubsubStanzas(SleekTest):
"Testing iq/pubsub/create&configure stanzas" "Testing iq/pubsub/create&configure stanzas"
iq = self.Iq() iq = self.Iq()
iq['pubsub']['create']['node'] = 'mynode' iq['pubsub']['create']['node'] = 'mynode'
iq['pubsub']['configure']['form'].addField('pubsub#title', iq['pubsub']['configure']['form'].addField('pubsub#title',
ftype='text-single', ftype='text-single',
value='This thing is awesome') value='This thing is awesome')
self.checkIq(iq, """ self.checkIq(iq, """
<iq id="0"> <iq id="0">
@ -131,12 +131,12 @@ class TestPubsubStanzas(SleekTest):
def testState(self): def testState(self):
"Testing iq/psstate stanzas" "Testing iq/psstate stanzas"
iq = self.Iq() iq = self.Iq()
iq['psstate']['node']= 'mynode' iq['psstate']['node']= 'mynode'
iq['psstate']['item']= 'myitem' iq['psstate']['item']= 'myitem'
pl = ET.Element('{http://andyet.net/protocol/pubsubqueue}claimed') pl = ET.Element('{http://andyet.net/protocol/pubsubqueue}claimed')
iq['psstate']['payload'] = pl iq['psstate']['payload'] = pl
self.checkIq(iq, """ self.checkIq(iq, """
<iq id="0"> <iq id="0">
<state xmlns="http://jabber.org/protocol/psstate" node="mynode" item="myitem"> <state xmlns="http://jabber.org/protocol/psstate" node="mynode" item="myitem">
<claimed xmlns="http://andyet.net/protocol/pubsubqueue" /> <claimed xmlns="http://andyet.net/protocol/pubsubqueue" />
@ -144,16 +144,16 @@ class TestPubsubStanzas(SleekTest):
</iq>""") </iq>""")
def testDefault(self): def testDefault(self):
"Testing iq/pubsub_owner/default stanzas" "Testing iq/pubsub_owner/default stanzas"
iq = self.Iq() iq = self.Iq()
iq['pubsub_owner']['default'] iq['pubsub_owner']['default']
iq['pubsub_owner']['default']['node'] = 'mynode' iq['pubsub_owner']['default']['node'] = 'mynode'
iq['pubsub_owner']['default']['type'] = 'leaf' iq['pubsub_owner']['default']['type'] = 'leaf'
iq['pubsub_owner']['default']['form'].addField('pubsub#title', iq['pubsub_owner']['default']['form'].addField('pubsub#title',
ftype='text-single', ftype='text-single',
value='This thing is awesome') value='This thing is awesome')
self.checkIq(iq, """ self.checkIq(iq, """
<iq id="0"> <iq id="0">
<pubsub xmlns="http://jabber.org/protocol/pubsub#owner"> <pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
<default node="mynode" type="leaf"> <default node="mynode" type="leaf">
<x xmlns="jabber:x:data" type="form"> <x xmlns="jabber:x:data" type="form">
@ -166,54 +166,54 @@ class TestPubsubStanzas(SleekTest):
</iq>""", use_values=False) </iq>""", use_values=False)
def testSubscribe(self): def testSubscribe(self):
"Testing iq/pubsub/subscribe stanzas" "testing iq/pubsub/subscribe stanzas"
iq = self.Iq() iq = self.Iq()
iq['pubsub']['subscribe']['options'] iq['pubsub']['subscribe']['options']
iq['pubsub']['subscribe']['node'] = 'cheese' iq['pubsub']['subscribe']['node'] = 'cheese'
iq['pubsub']['subscribe']['jid'] = 'fritzy@netflint.net/sleekxmpp' iq['pubsub']['subscribe']['jid'] = 'fritzy@netflint.net/sleekxmpp'
iq['pubsub']['subscribe']['options']['node'] = 'cheese' iq['pubsub']['subscribe']['options']['node'] = 'cheese'
iq['pubsub']['subscribe']['options']['jid'] = 'fritzy@netflint.net/sleekxmpp' iq['pubsub']['subscribe']['options']['jid'] = 'fritzy@netflint.net/sleekxmpp'
form = xep_0004.Form() form = xep_0004.Form()
form.addField('pubsub#title', ftype='text-single', value='This thing is awesome') form.addField('pubsub#title', ftype='text-single', value='this thing is awesome')
iq['pubsub']['subscribe']['options']['options'] = form iq['pubsub']['subscribe']['options']['options'] = form
self.checkIq(iq, """ self.checkIq(iq, """
<iq id="0"> <iq id="0">
<pubsub xmlns="http://jabber.org/protocol/pubsub"> <pubsub xmlns="http://jabber.org/protocol/pubsub">
<subscribe node="cheese" jid="fritzy@netflint.net/sleekxmpp"> <subscribe node="cheese" jid="fritzy@netflint.net/sleekxmpp">
<options node="cheese" jid="fritzy@netflint.net/sleekxmpp"> <options node="cheese" jid="fritzy@netflint.net/sleekxmpp">
<x xmlns="jabber:x:data" type="form"> <x xmlns="jabber:x:data" type="form">
<field var="pubsub#title" type="text-single"> <field var="pubsub#title" type="text-single">
<value>This thing is awesome</value> <value>this thing is awesome</value>
</field> </field>
</x> </x>
</options> </options>
</subscribe> </subscribe>
</pubsub> </pubsub>
</iq>""", use_values=False) </iq>""", use_values=False)
def testPublish(self): def testPublish(self):
"Testing iq/pubsub/publish stanzas" "Testing iq/pubsub/publish stanzas"
iq = self.Iq() iq = self.Iq()
iq['pubsub']['publish']['node'] = 'thingers' iq['pubsub']['publish']['node'] = 'thingers'
payload = ET.fromstring(""" payload = ET.fromstring("""
<thinger xmlns="http://andyet.net/protocol/thinger" x="1" y='2'> <thinger xmlns="http://andyet.net/protocol/thinger" x="1" y='2'>
<child1 /> <child1 />
<child2 normandy='cheese' foo='bar' /> <child2 normandy='cheese' foo='bar' />
</thinger>""") </thinger>""")
payload2 = ET.fromstring(""" payload2 = ET.fromstring("""
<thinger2 xmlns="http://andyet.net/protocol/thinger2" x="12" y='22'> <thinger2 xmlns="http://andyet.net/protocol/thinger2" x="12" y='22'>
<child12 /> <child12 />
<child22 normandy='cheese2' foo='bar2' /> <child22 normandy='cheese2' foo='bar2' />
</thinger2>""") </thinger2>""")
item = pubsub.Item() item = pubsub.Item()
item['id'] = 'asdf' item['id'] = 'asdf'
item['payload'] = payload item['payload'] = payload
item2 = pubsub.Item() item2 = pubsub.Item()
item2['id'] = 'asdf2' item2['id'] = 'asdf2'
item2['payload'] = payload2 item2['payload'] = payload2
iq['pubsub']['publish'].append(item) iq['pubsub']['publish'].append(item)
iq['pubsub']['publish'].append(item2) iq['pubsub']['publish'].append(item2)
self.checkIq(iq, """ self.checkIq(iq, """
<iq id="0"> <iq id="0">
<pubsub xmlns="http://jabber.org/protocol/pubsub"> <pubsub xmlns="http://jabber.org/protocol/pubsub">
@ -235,19 +235,19 @@ class TestPubsubStanzas(SleekTest):
</iq>""") </iq>""")
def testDelete(self): def testDelete(self):
"Testing iq/pubsub_owner/delete stanzas" "Testing iq/pubsub_owner/delete stanzas"
iq = self.Iq() iq = self.Iq()
iq['pubsub_owner']['delete']['node'] = 'thingers' iq['pubsub_owner']['delete']['node'] = 'thingers'
self.checkIq(iq, """ self.checkIq(iq, """
<iq id="0"> <iq id="0">
<pubsub xmlns="http://jabber.org/protocol/pubsub#owner"> <pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
<delete node="thingers" /> <delete node="thingers" />
</pubsub> </pubsub>
</iq>""") </iq>""")
def testCreateConfigGet(self): def testCreateConfigGet(self):
"""Testing getting config from full create""" """Testing getting config from full create"""
iq = self.Iq() iq = self.Iq()
iq['to'] = 'pubsub.asdf' iq['to'] = 'pubsub.asdf'
iq['from'] = 'fritzy@asdf/87292ede-524d-4117-9076-d934ed3db8e7' iq['from'] = 'fritzy@asdf/87292ede-524d-4117-9076-d934ed3db8e7'
iq['type'] = 'set' iq['type'] = 'set'
@ -348,16 +348,16 @@ class TestPubsubStanzas(SleekTest):
</iq>""") </iq>""")
def testItemEvent(self): def testItemEvent(self):
"""Testing message/pubsub_event/items/item""" """Testing message/pubsub_event/items/item"""
msg = self.Message() msg = self.Message()
item = pubsub.EventItem() item = pubsub.EventItem()
pl = ET.Element('{http://netflint.net/protocol/test}test', {'failed':'3', 'passed':'24'}) pl = ET.Element('{http://netflint.net/protocol/test}test', {'failed':'3', 'passed':'24'})
item['payload'] = pl item['payload'] = pl
item['id'] = 'abc123' item['id'] = 'abc123'
msg['pubsub_event']['items'].append(item) msg['pubsub_event']['items'].append(item)
msg['pubsub_event']['items']['node'] = 'cheese' msg['pubsub_event']['items']['node'] = 'cheese'
msg['type'] = 'normal' msg['type'] = 'normal'
self.checkMessage(msg, """ self.checkMessage(msg, """
<message type="normal"> <message type="normal">
<event xmlns="http://jabber.org/protocol/pubsub#event"> <event xmlns="http://jabber.org/protocol/pubsub#event">
<items node="cheese"> <items node="cheese">
@ -369,21 +369,21 @@ class TestPubsubStanzas(SleekTest):
</message>""") </message>""")
def testItemsEvent(self): def testItemsEvent(self):
"""Testing multiple message/pubsub_event/items/item""" """Testing multiple message/pubsub_event/items/item"""
msg = self.Message() msg = self.Message()
item = pubsub.EventItem() item = pubsub.EventItem()
item2 = pubsub.EventItem() item2 = pubsub.EventItem()
pl = ET.Element('{http://netflint.net/protocol/test}test', {'failed':'3', 'passed':'24'}) 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'}) pl2 = ET.Element('{http://netflint.net/protocol/test-other}test', {'total':'27', 'failed':'3'})
item2['payload'] = pl2 item2['payload'] = pl2
item['payload'] = pl item['payload'] = pl
item['id'] = 'abc123' item['id'] = 'abc123'
item2['id'] = '123abc' item2['id'] = '123abc'
msg['pubsub_event']['items'].append(item) msg['pubsub_event']['items'].append(item)
msg['pubsub_event']['items'].append(item2) msg['pubsub_event']['items'].append(item2)
msg['pubsub_event']['items']['node'] = 'cheese' msg['pubsub_event']['items']['node'] = 'cheese'
msg['type'] = 'normal' msg['type'] = 'normal'
self.checkMessage(msg, """ self.checkMessage(msg, """
<message type="normal"> <message type="normal">
<event xmlns="http://jabber.org/protocol/pubsub#event"> <event xmlns="http://jabber.org/protocol/pubsub#event">
<items node="cheese"> <items node="cheese">
@ -398,24 +398,24 @@ class TestPubsubStanzas(SleekTest):
</message>""") </message>""")
def testItemsEvent(self): def testItemsEvent(self):
"""Testing message/pubsub_event/items/item & retract mix""" """Testing message/pubsub_event/items/item & retract mix"""
msg = self.Message() msg = self.Message()
item = pubsub.EventItem() item = pubsub.EventItem()
item2 = pubsub.EventItem() item2 = pubsub.EventItem()
pl = ET.Element('{http://netflint.net/protocol/test}test', {'failed':'3', 'passed':'24'}) 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'}) pl2 = ET.Element('{http://netflint.net/protocol/test-other}test', {'total':'27', 'failed':'3'})
item2['payload'] = pl2 item2['payload'] = pl2
retract = pubsub.EventRetract() retract = pubsub.EventRetract()
retract['id'] = 'aabbcc' retract['id'] = 'aabbcc'
item['payload'] = pl item['payload'] = pl
item['id'] = 'abc123' item['id'] = 'abc123'
item2['id'] = '123abc' item2['id'] = '123abc'
msg['pubsub_event']['items'].append(item) msg['pubsub_event']['items'].append(item)
msg['pubsub_event']['items'].append(retract) msg['pubsub_event']['items'].append(retract)
msg['pubsub_event']['items'].append(item2) msg['pubsub_event']['items'].append(item2)
msg['pubsub_event']['items']['node'] = 'cheese' msg['pubsub_event']['items']['node'] = 'cheese'
msg['type'] = 'normal' msg['type'] = 'normal'
self.checkMessage(msg, """ self.checkMessage(msg, """
<message type="normal"> <message type="normal">
<event xmlns="http://jabber.org/protocol/pubsub#event"> <event xmlns="http://jabber.org/protocol/pubsub#event">
<items node="cheese"> <items node="cheese">
@ -430,12 +430,12 @@ class TestPubsubStanzas(SleekTest):
</message>""") </message>""")
def testCollectionAssociate(self): def testCollectionAssociate(self):
"""Testing message/pubsub_event/collection/associate""" """Testing message/pubsub_event/collection/associate"""
msg = self.Message() msg = self.Message()
msg['pubsub_event']['collection']['associate']['node'] = 'cheese' msg['pubsub_event']['collection']['associate']['node'] = 'cheese'
msg['pubsub_event']['collection']['node'] = 'cheeseburger' msg['pubsub_event']['collection']['node'] = 'cheeseburger'
msg['type'] = 'headline' msg['type'] = 'headline'
self.checkMessage(msg, """ self.checkMessage(msg, """
<message type="headline"> <message type="headline">
<event xmlns="http://jabber.org/protocol/pubsub#event"> <event xmlns="http://jabber.org/protocol/pubsub#event">
<collection node="cheeseburger"> <collection node="cheeseburger">
@ -445,12 +445,12 @@ class TestPubsubStanzas(SleekTest):
</message>""") </message>""")
def testCollectionDisassociate(self): def testCollectionDisassociate(self):
"""Testing message/pubsub_event/collection/disassociate""" """Testing message/pubsub_event/collection/disassociate"""
msg = self.Message() msg = self.Message()
msg['pubsub_event']['collection']['disassociate']['node'] = 'cheese' msg['pubsub_event']['collection']['disassociate']['node'] = 'cheese'
msg['pubsub_event']['collection']['node'] = 'cheeseburger' msg['pubsub_event']['collection']['node'] = 'cheeseburger'
msg['type'] = 'headline' msg['type'] = 'headline'
self.checkMessage(msg, """ self.checkMessage(msg, """
<message type="headline"> <message type="headline">
<event xmlns="http://jabber.org/protocol/pubsub#event"> <event xmlns="http://jabber.org/protocol/pubsub#event">
<collection node="cheeseburger"> <collection node="cheeseburger">
@ -460,15 +460,15 @@ class TestPubsubStanzas(SleekTest):
</message>""") </message>""")
def testEventConfiguration(self): def testEventConfiguration(self):
"""Testing message/pubsub_event/configuration/config""" """Testing message/pubsub_event/configuration/config"""
msg = self.Message() msg = self.Message()
msg['pubsub_event']['configuration']['node'] = 'cheese' msg['pubsub_event']['configuration']['node'] = 'cheese'
msg['pubsub_event']['configuration']['form'].addField('pubsub#title', msg['pubsub_event']['configuration']['form'].addField('pubsub#title',
ftype='text-single', ftype='text-single',
value='This thing is awesome') value='This thing is awesome')
msg['type'] = 'headline' msg['type'] = 'headline'
self.checkMessage(msg, """ self.checkMessage(msg, """
<message type="headline"> <message type="headline">
<event xmlns="http://jabber.org/protocol/pubsub#event"> <event xmlns="http://jabber.org/protocol/pubsub#event">
<configuration node="cheese"> <configuration node="cheese">
<x xmlns="jabber:x:data" type="form"> <x xmlns="jabber:x:data" type="form">
@ -481,11 +481,11 @@ class TestPubsubStanzas(SleekTest):
</message>""") </message>""")
def testEventPurge(self): def testEventPurge(self):
"""Testing message/pubsub_event/purge""" """Testing message/pubsub_event/purge"""
msg = self.Message() msg = self.Message()
msg['pubsub_event']['purge']['node'] = 'pickles' msg['pubsub_event']['purge']['node'] = 'pickles'
msg['type'] = 'headline' msg['type'] = 'headline'
self.checkMessage(msg, """ self.checkMessage(msg, """
<message type="headline"> <message type="headline">
<event xmlns="http://jabber.org/protocol/pubsub#event"> <event xmlns="http://jabber.org/protocol/pubsub#event">
<purge node="pickles" /> <purge node="pickles" />
@ -493,15 +493,15 @@ class TestPubsubStanzas(SleekTest):
</message>""") </message>""")
def testEventSubscription(self): def testEventSubscription(self):
"""Testing message/pubsub_event/subscription""" """Testing message/pubsub_event/subscription"""
msg = self.Message() msg = self.Message()
msg['pubsub_event']['subscription']['node'] = 'pickles' msg['pubsub_event']['subscription']['node'] = 'pickles'
msg['pubsub_event']['subscription']['jid'] = 'fritzy@netflint.net/test' msg['pubsub_event']['subscription']['jid'] = 'fritzy@netflint.net/test'
msg['pubsub_event']['subscription']['subid'] = 'aabb1122' msg['pubsub_event']['subscription']['subid'] = 'aabb1122'
msg['pubsub_event']['subscription']['subscription'] = 'subscribed' msg['pubsub_event']['subscription']['subscription'] = 'subscribed'
msg['pubsub_event']['subscription']['expiry'] = 'presence' msg['pubsub_event']['subscription']['expiry'] = 'presence'
msg['type'] = 'headline' msg['type'] = 'headline'
self.checkMessage(msg, """ self.checkMessage(msg, """
<message type="headline"> <message type="headline">
<event xmlns="http://jabber.org/protocol/pubsub#event"> <event xmlns="http://jabber.org/protocol/pubsub#event">
<subscription node="pickles" subid="aabb1122" jid="fritzy@netflint.net/test" subscription="subscribed" expiry="presence" /> <subscription node="pickles" subid="aabb1122" jid="fritzy@netflint.net/test" subscription="subscribed" expiry="presence" />

View file

@ -1,4 +1,4 @@
from sleektest import * from . sleektest import *
import sleekxmpp.plugins.xep_0033 as xep_0033 import sleekxmpp.plugins.xep_0033 as xep_0033