plugin XEP-0313: update (still draft)

This commit is contained in:
souliane 2015-01-09 10:51:12 +01:00
commit 27cb7fac73
2 changed files with 137 additions and 139 deletions

View file

@ -115,6 +115,10 @@ class FakeSAT(object):
"""
return mess_data # TODO
def getProfileName(self, profile_key):
"""Get the profile name from the profile_key"""
return profile_key
def getClient(self, profile_key):
"""Convenient method to get client from profile key
@return: client or None if it doesn't exist"""

View file

@ -28,8 +28,11 @@ from twisted.words.xish import domish
from dateutil.tz import tzutc
import datetime
from wokkel.rsm import RSMRequest
from wokkel.mam import buildForm
NS_PUBSUB = 'http://jabber.org/protocol/pubsub'
SERVICE = 'sat-pubsub.tazar.int'
SERVICE_JID = JID(SERVICE)
class XEP_0313Test(helpers.SatTestCase):
@ -37,30 +40,32 @@ class XEP_0313Test(helpers.SatTestCase):
def setUp(self):
self.host = helpers.FakeSAT()
self.plugin = XEP_0313(self.host)
client = self.plugin.getHandler(C.PROFILE[0])
client.makeConnection(self.host.getClient(C.PROFILE[0]).xmlstream)
def test_queryArchive(self):
xml = """
<iq type='set' id='%s'>
<iq type='set' id='%s' to='%s'>
<query xmlns='urn:xmpp:mam:0'/>
</iq>
""" % ("H_%d" % domish.Element._idCounter)
d = self.plugin.queryArchive(profile_key=C.PROFILE[0])
""" % (("H_%d" % domish.Element._idCounter), SERVICE)
d = self.plugin.queryArchive(SERVICE_JID, profile_key=C.PROFILE[0])
d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
return d
def test_queryArchivePubsub(self):
xml = """
<iq type='set' id='%s'>
<iq type='set' id='%s' to='%s'>
<query xmlns='urn:xmpp:mam:0' node='fdp/submitted/capulet.lit/sonnets' />
</iq>
""" % ("H_%d" % domish.Element._idCounter)
d = self.plugin.queryArchive(node="fdp/submitted/capulet.lit/sonnets", profile_key=C.PROFILE[0])
""" % (("H_%d" % domish.Element._idCounter), SERVICE)
d = self.plugin.queryArchive(SERVICE_JID, node="fdp/submitted/capulet.lit/sonnets", profile_key=C.PROFILE[0])
d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
return d
def test_queryArchiveWith(self):
xml = """
<iq type='set' id='%s'>
<iq type='set' id='%s' to='%s'>
<query xmlns='urn:xmpp:mam:0'>
<x xmlns='jabber:x:data' type='submit'>
<field var='FORM_TYPE' type='hidden'>
@ -72,15 +77,15 @@ class XEP_0313Test(helpers.SatTestCase):
</x>
</query>
</iq>
""" % ("H_%d" % domish.Element._idCounter)
form = self.plugin.buildForm(with_jid=JID('juliet@capulet.lit'))
d = self.plugin.queryArchive(form, profile_key=C.PROFILE[0])
""" % (("H_%d" % domish.Element._idCounter), SERVICE)
form = buildForm(with_jid=JID('juliet@capulet.lit'))
d = self.plugin.queryArchive(SERVICE_JID, form, profile_key=C.PROFILE[0])
d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
return d
def test_queryArchiveStartEnd(self):
xml = """
<iq type='set' id='%s'>
<iq type='set' id='%s' to='%s'>
<query xmlns='urn:xmpp:mam:0'>
<x xmlns='jabber:x:data' type='submit'>
<field var='FORM_TYPE' type='hidden'>
@ -95,17 +100,17 @@ class XEP_0313Test(helpers.SatTestCase):
</x>
</query>
</iq>
""" % ("H_%d" % domish.Element._idCounter)
""" % (("H_%d" % domish.Element._idCounter), SERVICE)
start = datetime.datetime(2010, 6, 7, 0, 0, 0, tzinfo=tzutc())
end = datetime.datetime(2010, 7, 7, 13, 23, 54, tzinfo=tzutc())
form = self.plugin.buildForm(start=start, end=end)
d = self.plugin.queryArchive(form, profile_key=C.PROFILE[0])
form = buildForm(start=start, end=end)
d = self.plugin.queryArchive(SERVICE_JID, form, profile_key=C.PROFILE[0])
d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
return d
def test_queryArchiveStart(self):
xml = """
<iq type='set' id='%s'>
<iq type='set' id='%s' to='%s'>
<query xmlns='urn:xmpp:mam:0'>
<x xmlns='jabber:x:data' type='submit'>
<field var='FORM_TYPE' type='hidden'>
@ -117,16 +122,16 @@ class XEP_0313Test(helpers.SatTestCase):
</x>
</query>
</iq>
""" % ("H_%d" % domish.Element._idCounter)
""" % (("H_%d" % domish.Element._idCounter), SERVICE)
start = datetime.datetime(2010, 8, 7, 0, 0, 0, tzinfo=tzutc())
form = self.plugin.buildForm(start=start)
d = self.plugin.queryArchive(form, profile_key=C.PROFILE[0])
form = buildForm(start=start)
d = self.plugin.queryArchive(SERVICE_JID, form, profile_key=C.PROFILE[0])
d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
return d
def test_queryArchiveRSM(self):
xml = """
<iq type='set' id='%s'>
<iq type='set' id='%s' to='%s'>
<query xmlns='urn:xmpp:mam:0'>
<x xmlns='jabber:x:data' type='submit'>
<field var='FORM_TYPE' type='hidden'>
@ -141,17 +146,17 @@ class XEP_0313Test(helpers.SatTestCase):
</set>
</query>
</iq>
""" % ("H_%d" % domish.Element._idCounter)
""" % (("H_%d" % domish.Element._idCounter), SERVICE)
start = datetime.datetime(2010, 8, 7, 0, 0, 0, tzinfo=tzutc())
form = self.plugin.buildForm(start=start)
form = buildForm(start=start)
rsm = RSMRequest(max=10)
d = self.plugin.queryArchive(form=form, rsm=rsm, profile_key=C.PROFILE[0])
d = self.plugin.queryArchive(SERVICE_JID, form=form, rsm=rsm, profile_key=C.PROFILE[0])
d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
return d
def test_queryArchiveRSMPaging(self):
xml = """
<iq type='set' id='%s'>
<iq type='set' id='%s' to='%s'>
<query xmlns='urn:xmpp:mam:0'>
<x xmlns='jabber:x:data' type='submit'>
<field var='FORM_TYPE' type='hidden'><value>urn:xmpp:mam:0</value></field>
@ -163,27 +168,27 @@ class XEP_0313Test(helpers.SatTestCase):
</set>
</query>
</iq>
""" % ("H_%d" % domish.Element._idCounter)
""" % (("H_%d" % domish.Element._idCounter), SERVICE)
start = datetime.datetime(2010, 8, 7, 0, 0, 0, tzinfo=tzutc())
form = self.plugin.buildForm(start=start)
form = buildForm(start=start)
rsm = RSMRequest(max=10, after=u'09af3-cc343-b409f')
d = self.plugin.queryArchive(form=form, rsm=rsm, profile_key=C.PROFILE[0])
d = self.plugin.queryArchive(SERVICE_JID, form=form, rsm=rsm, profile_key=C.PROFILE[0])
d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
return d
def test_queryFields(self):
xml = """
<iq type='get' id="%s">
<iq type='get' id="%s" to='%s'>
<query xmlns='urn:xmpp:mam:0'/>
</iq>
""" % ("H_%d" % domish.Element._idCounter)
d = self.plugin.queryFields(C.PROFILE[0])
""" % (("H_%d" % domish.Element._idCounter), SERVICE)
d = self.plugin.queryFields(SERVICE_JID, C.PROFILE[0])
d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
return d
def test_queryArchiveFields(self):
xml = """
<iq type='set' id='%s'>
<iq type='set' id='%s' to='%s'>
<query xmlns='urn:xmpp:mam:0'>
<x xmlns='jabber:x:data' type='submit'>
<field type='hidden' var='FORM_TYPE'>
@ -198,29 +203,34 @@ class XEP_0313Test(helpers.SatTestCase):
</x>
</query>
</iq>
""" % ("H_%d" % domish.Element._idCounter)
extra = (('text-single', 'urn:example:xmpp:free-text-search',
'Where arth thou, my Juliet?'),
('text-single', 'urn:example:xmpp:stanza-content',
'{http://jabber.org/protocol/mood}mood/lonely'))
form = self.plugin.buildForm(extra=extra)
d = self.plugin.queryArchive(form=form, profile_key=C.PROFILE[0])
""" % (("H_%d" % domish.Element._idCounter), SERVICE)
extra = [{'fieldType': 'text-single',
'var': 'urn:example:xmpp:free-text-search',
'value': 'Where arth thou, my Juliet?'},
{'fieldType': 'text-single',
'var': 'urn:example:xmpp:stanza-content',
'value': '{http://jabber.org/protocol/mood}mood/lonely'}]
form = buildForm(extra=extra)
d = self.plugin.queryArchive(SERVICE_JID, form=form, profile_key=C.PROFILE[0])
d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
return d
def test_queryPrefs(self):
xml = """
<iq type='get' id='%s'>
<prefs xmlns='urn:xmpp:mam:0'/>
<iq type='get' id='%s' to='%s'>
<prefs xmlns='urn:xmpp:mam:0'>
<always/>
<never/>
</prefs>
</iq>
""" % ("H_%d" % domish.Element._idCounter)
d = self.plugin.queryPrefs(profile_key=C.PROFILE[0])
""" % (("H_%d" % domish.Element._idCounter), SERVICE)
d = self.plugin.getPrefs(SERVICE_JID, profile_key=C.PROFILE[0])
d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
return d
def test_setPrefs(self):
xml = """
<iq type='set' id='%s'>
<iq type='set' id='%s' to='%s'>
<prefs xmlns='urn:xmpp:mam:0' default='roster'>
<always>
<jid>romeo@montague.lit</jid>
@ -230,9 +240,9 @@ class XEP_0313Test(helpers.SatTestCase):
</never>
</prefs>
</iq>
""" % ("H_%d" % domish.Element._idCounter)
""" % (("H_%d" % domish.Element._idCounter), SERVICE)
always = [JID('romeo@montague.lit')]
never = [JID('montague@montague.lit')]
d = self.plugin.setPrefs(always=always, never=never, profile_key=C.PROFILE[0])
d = self.plugin.setPrefs(SERVICE_JID, always=always, never=never, profile_key=C.PROFILE[0])
d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
return d