test: update some tests
This commit is contained in:
parent
8bc634d4c2
commit
27f74af7b0
6 changed files with 48 additions and 44 deletions
|
|
@ -190,12 +190,12 @@ class FakeSAT(object):
|
|||
entry = self.getSentMessage(profile_index)
|
||||
return entry.toXml() if entry else None
|
||||
|
||||
def findFeaturesSet(self, features, category=None, type_=None, jid_=None, profile_key=None):
|
||||
def findFeaturesSet(self, features, identity=None, jid_=None, profile=C.PROF_KEY_NONE):
|
||||
"""Call self.addFeature from your tests to change the return value.
|
||||
|
||||
@return: a set of entities
|
||||
"""
|
||||
client = self.getClient(profile_key)
|
||||
client = self.getClient(profile)
|
||||
if jid_ is None:
|
||||
jid_ = JID(client.jid.host)
|
||||
try:
|
||||
|
|
@ -301,7 +301,7 @@ class FakeMemory(Memory):
|
|||
# manipulating basic stuff, the others should be overwritten when needed
|
||||
self.host = host
|
||||
self.params = FakeParams(host, None)
|
||||
self.config = self.parseMainConf()
|
||||
self.config = tools_config.parseMainConf()
|
||||
self.reinit()
|
||||
|
||||
def reinit(self):
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ class MemoryTest(unittest.TestCase):
|
|||
"""
|
||||
if profile_key == '@NONE@':
|
||||
profile_key = '@DEFAULT@'
|
||||
return self.host.memory.getParams(security_limit, app, profile_key)
|
||||
return self.host.memory.params.getParams(security_limit, app, profile_key)
|
||||
|
||||
def test_updateParams(self):
|
||||
self.host.memory.reinit()
|
||||
|
|
|
|||
|
|
@ -136,12 +136,13 @@ class XEP_groupblogTest(helpers.SatTestCase):
|
|||
|
||||
def setUp(self):
|
||||
self.host = helpers.FakeSAT()
|
||||
self.plugin = plugin_misc_groupblog.GroupBlog(self.host)
|
||||
self.plugin._initialise = self._initialise
|
||||
self.host.plugins['XEP-0060'] = plugin_xep_0060.XEP_0060(self.host)
|
||||
self.host.plugins['XEP-0163'] = plugin_xep_0163.XEP_0163(self.host)
|
||||
reload(plugin_misc_text_syntaxes) # reload the plugin to avoid conflict error
|
||||
self.host.plugins['TEXT-SYNTAXES'] = plugin_misc_text_syntaxes.TextSyntaxes(self.host)
|
||||
self.host.plugins['XEP-0277'] = plugin_xep_0277.XEP_0277(self.host)
|
||||
self.plugin = plugin_misc_groupblog.GroupBlog(self.host)
|
||||
self.plugin._initialise = self._initialise
|
||||
self.__initialised = False
|
||||
self._initialise(C.PROFILE[0])
|
||||
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ class SanitisationTest(helpers.SatTestCase):
|
|||
|
||||
def setUp(self):
|
||||
self.host = helpers.FakeSAT()
|
||||
reload(plugin_misc_text_syntaxes) # reload the plugin to avoid conflict error
|
||||
self.text_syntaxes = plugin_misc_text_syntaxes.TextSyntaxes(self.host)
|
||||
|
||||
def test_xhtml_sanitise(self):
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
from sat.test import helpers
|
||||
from sat.plugins import plugin_xep_0277
|
||||
from sat.plugins import plugin_xep_0060
|
||||
from sat.plugins import plugin_misc_text_syntaxes
|
||||
from sat.tools.xml_tools import ElementParser
|
||||
|
||||
|
|
@ -69,7 +70,9 @@ class XEP_0277Test(helpers.SatTestCase):
|
|||
|
||||
def addPEPEvent(self, *args):
|
||||
pass
|
||||
self.host.plugins["XEP-0060"] = plugin_xep_0060.XEP_0060(self.host)
|
||||
self.host.plugins["XEP-0163"] = XEP_0163(self.host)
|
||||
reload(plugin_misc_text_syntaxes) # reload the plugin to avoid conflict error
|
||||
self.host.plugins["TEXT-SYNTAXES"] = plugin_misc_text_syntaxes.TextSyntaxes(self.host)
|
||||
self.plugin = plugin_xep_0277.XEP_0277(self.host)
|
||||
|
||||
|
|
|
|||
|
|
@ -25,12 +25,13 @@ from sat.test import helpers
|
|||
from sat.plugins.plugin_xep_0313 import XEP_0313
|
||||
from twisted.words.protocols.jabber.jid import JID
|
||||
from twisted.words.xish import domish
|
||||
from wokkel.data_form import Field
|
||||
from dateutil.tz import tzutc
|
||||
import datetime
|
||||
|
||||
# TODO: change this when RSM and MAM are in wokkel
|
||||
from sat.tmp.wokkel.rsm import RSMRequest
|
||||
from sat.tmp.wokkel.mam import buildForm
|
||||
from sat.tmp.wokkel.mam import buildForm, MAMRequest
|
||||
|
||||
NS_PUBSUB = 'http://jabber.org/protocol/pubsub'
|
||||
SERVICE = 'sat-pubsub.tazar.int'
|
||||
|
|
@ -42,36 +43,37 @@ 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)
|
||||
self.client = self.host.getClient(C.PROFILE[0])
|
||||
mam_client = self.plugin.getHandler(C.PROFILE[0])
|
||||
mam_client.makeConnection(self.host.getClient(C.PROFILE[0]).xmlstream)
|
||||
|
||||
def test_queryArchive(self):
|
||||
xml = """
|
||||
<iq type='set' id='%s' to='%s'>
|
||||
<query xmlns='urn:xmpp:mam:0'/>
|
||||
<query xmlns='urn:xmpp:mam:1'/>
|
||||
</iq>
|
||||
""" % (("H_%d" % domish.Element._idCounter), SERVICE)
|
||||
d = self.plugin.queryArchive(SERVICE_JID, profile_key=C.PROFILE[0])
|
||||
d = self.plugin.queryArchive(self.client, MAMRequest(), SERVICE_JID)
|
||||
d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
|
||||
return d
|
||||
|
||||
def test_queryArchivePubsub(self):
|
||||
xml = """
|
||||
<iq type='set' id='%s' to='%s'>
|
||||
<query xmlns='urn:xmpp:mam:0' node='fdp/submitted/capulet.lit/sonnets' />
|
||||
<query xmlns='urn:xmpp:mam:1' node='fdp/submitted/capulet.lit/sonnets' />
|
||||
</iq>
|
||||
""" % (("H_%d" % domish.Element._idCounter), SERVICE)
|
||||
d = self.plugin.queryArchive(SERVICE_JID, node="fdp/submitted/capulet.lit/sonnets", profile_key=C.PROFILE[0])
|
||||
d = self.plugin.queryArchive(self.client, MAMRequest(node="fdp/submitted/capulet.lit/sonnets"), SERVICE_JID)
|
||||
d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
|
||||
return d
|
||||
|
||||
def test_queryArchiveWith(self):
|
||||
xml = """
|
||||
<iq type='set' id='%s' to='%s'>
|
||||
<query xmlns='urn:xmpp:mam:0'>
|
||||
<query xmlns='urn:xmpp:mam:1'>
|
||||
<x xmlns='jabber:x:data' type='submit'>
|
||||
<field var='FORM_TYPE' type='hidden'>
|
||||
<value>urn:xmpp:mam:0</value>
|
||||
<value>urn:xmpp:mam:1</value>
|
||||
</field>
|
||||
<field var='with' type='jid-single'>
|
||||
<value>juliet@capulet.lit</value>
|
||||
|
|
@ -81,17 +83,17 @@ class XEP_0313Test(helpers.SatTestCase):
|
|||
</iq>
|
||||
""" % (("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 = self.plugin.queryArchive(self.client, MAMRequest(form), SERVICE_JID)
|
||||
d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
|
||||
return d
|
||||
|
||||
def test_queryArchiveStartEnd(self):
|
||||
xml = """
|
||||
<iq type='set' id='%s' to='%s'>
|
||||
<query xmlns='urn:xmpp:mam:0'>
|
||||
<query xmlns='urn:xmpp:mam:1'>
|
||||
<x xmlns='jabber:x:data' type='submit'>
|
||||
<field var='FORM_TYPE' type='hidden'>
|
||||
<value>urn:xmpp:mam:0</value>
|
||||
<value>urn:xmpp:mam:1</value>
|
||||
</field>
|
||||
<field var='start' type='text-single'>
|
||||
<value>2010-06-07T00:00:00Z</value>
|
||||
|
|
@ -106,17 +108,17 @@ class XEP_0313Test(helpers.SatTestCase):
|
|||
start = datetime.datetime(2010, 6, 7, 0, 0, 0, tzinfo=tzutc())
|
||||
end = datetime.datetime(2010, 7, 7, 13, 23, 54, tzinfo=tzutc())
|
||||
form = buildForm(start=start, end=end)
|
||||
d = self.plugin.queryArchive(SERVICE_JID, form, profile_key=C.PROFILE[0])
|
||||
d = self.plugin.queryArchive(self.client, MAMRequest(form), SERVICE_JID)
|
||||
d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
|
||||
return d
|
||||
|
||||
def test_queryArchiveStart(self):
|
||||
xml = """
|
||||
<iq type='set' id='%s' to='%s'>
|
||||
<query xmlns='urn:xmpp:mam:0'>
|
||||
<query xmlns='urn:xmpp:mam:1'>
|
||||
<x xmlns='jabber:x:data' type='submit'>
|
||||
<field var='FORM_TYPE' type='hidden'>
|
||||
<value>urn:xmpp:mam:0</value>
|
||||
<value>urn:xmpp:mam:1</value>
|
||||
</field>
|
||||
<field var='start' type='text-single'>
|
||||
<value>2010-08-07T00:00:00Z</value>
|
||||
|
|
@ -127,17 +129,17 @@ class XEP_0313Test(helpers.SatTestCase):
|
|||
""" % (("H_%d" % domish.Element._idCounter), SERVICE)
|
||||
start = datetime.datetime(2010, 8, 7, 0, 0, 0, tzinfo=tzutc())
|
||||
form = buildForm(start=start)
|
||||
d = self.plugin.queryArchive(SERVICE_JID, form, profile_key=C.PROFILE[0])
|
||||
d = self.plugin.queryArchive(self.client, MAMRequest(form), SERVICE_JID)
|
||||
d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
|
||||
return d
|
||||
|
||||
def test_queryArchiveRSM(self):
|
||||
xml = """
|
||||
<iq type='set' id='%s' to='%s'>
|
||||
<query xmlns='urn:xmpp:mam:0'>
|
||||
<query xmlns='urn:xmpp:mam:1'>
|
||||
<x xmlns='jabber:x:data' type='submit'>
|
||||
<field var='FORM_TYPE' type='hidden'>
|
||||
<value>urn:xmpp:mam:0</value>
|
||||
<value>urn:xmpp:mam:1</value>
|
||||
</field>
|
||||
<field var='start' type='text-single'>
|
||||
<value>2010-08-07T00:00:00Z</value>
|
||||
|
|
@ -152,16 +154,16 @@ class XEP_0313Test(helpers.SatTestCase):
|
|||
start = datetime.datetime(2010, 8, 7, 0, 0, 0, tzinfo=tzutc())
|
||||
form = buildForm(start=start)
|
||||
rsm = RSMRequest(max_=10)
|
||||
d = self.plugin.queryArchive(SERVICE_JID, form=form, rsm=rsm, profile_key=C.PROFILE[0])
|
||||
d = self.plugin.queryArchive(self.client, MAMRequest(form, rsm), SERVICE_JID)
|
||||
d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
|
||||
return d
|
||||
|
||||
def test_queryArchiveRSMPaging(self):
|
||||
xml = """
|
||||
<iq type='set' id='%s' to='%s'>
|
||||
<query xmlns='urn:xmpp:mam:0'>
|
||||
<query xmlns='urn:xmpp:mam:1'>
|
||||
<x xmlns='jabber:x:data' type='submit'>
|
||||
<field var='FORM_TYPE' type='hidden'><value>urn:xmpp:mam:0</value></field>
|
||||
<field var='FORM_TYPE' type='hidden'><value>urn:xmpp:mam:1</value></field>
|
||||
<field var='start' type='text-single'><value>2010-08-07T00:00:00Z</value></field>
|
||||
</x>
|
||||
<set xmlns='http://jabber.org/protocol/rsm'>
|
||||
|
|
@ -174,27 +176,27 @@ class XEP_0313Test(helpers.SatTestCase):
|
|||
start = datetime.datetime(2010, 8, 7, 0, 0, 0, tzinfo=tzutc())
|
||||
form = buildForm(start=start)
|
||||
rsm = RSMRequest(max_=10, after=u'09af3-cc343-b409f')
|
||||
d = self.plugin.queryArchive(SERVICE_JID, form=form, rsm=rsm, profile_key=C.PROFILE[0])
|
||||
d = self.plugin.queryArchive(self.client, MAMRequest(form, rsm), SERVICE_JID)
|
||||
d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
|
||||
return d
|
||||
|
||||
def test_queryFields(self):
|
||||
xml = """
|
||||
<iq type='get' id="%s" to='%s'>
|
||||
<query xmlns='urn:xmpp:mam:0'/>
|
||||
<query xmlns='urn:xmpp:mam:1'/>
|
||||
</iq>
|
||||
""" % (("H_%d" % domish.Element._idCounter), SERVICE)
|
||||
d = self.plugin.queryFields(SERVICE_JID, C.PROFILE[0])
|
||||
d = self.plugin.queryFields(self.client, SERVICE_JID)
|
||||
d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
|
||||
return d
|
||||
|
||||
def test_queryArchiveFields(self):
|
||||
xml = """
|
||||
<iq type='set' id='%s' to='%s'>
|
||||
<query xmlns='urn:xmpp:mam:0'>
|
||||
<query xmlns='urn:xmpp:mam:1'>
|
||||
<x xmlns='jabber:x:data' type='submit'>
|
||||
<field type='hidden' var='FORM_TYPE'>
|
||||
<value>urn:xmpp:mam:0</value>
|
||||
<value>urn:xmpp:mam:1</value>
|
||||
</field>
|
||||
<field type='text-single' var='urn:example:xmpp:free-text-search'>
|
||||
<value>Where arth thou, my Juliet?</value>
|
||||
|
|
@ -206,34 +208,31 @@ class XEP_0313Test(helpers.SatTestCase):
|
|||
</query>
|
||||
</iq>
|
||||
""" % (("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])
|
||||
extra_fields = [Field('text-single', 'urn:example:xmpp:free-text-search', 'Where arth thou, my Juliet?'),
|
||||
Field('text-single', 'urn:example:xmpp:stanza-content', '{http://jabber.org/protocol/mood}mood/lonely')
|
||||
]
|
||||
form = buildForm(extra_fields=extra_fields)
|
||||
d = self.plugin.queryArchive(self.client, MAMRequest(form), SERVICE_JID)
|
||||
d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
|
||||
return d
|
||||
|
||||
def test_queryPrefs(self):
|
||||
xml = """
|
||||
<iq type='get' id='%s' to='%s'>
|
||||
<prefs xmlns='urn:xmpp:mam:0'>
|
||||
<prefs xmlns='urn:xmpp:mam:1'>
|
||||
<always/>
|
||||
<never/>
|
||||
</prefs>
|
||||
</iq>
|
||||
""" % (("H_%d" % domish.Element._idCounter), SERVICE)
|
||||
d = self.plugin.getPrefs(SERVICE_JID, profile_key=C.PROFILE[0])
|
||||
d = self.plugin.getPrefs(self.client, SERVICE_JID)
|
||||
d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
|
||||
return d
|
||||
|
||||
def test_setPrefs(self):
|
||||
xml = """
|
||||
<iq type='set' id='%s' to='%s'>
|
||||
<prefs xmlns='urn:xmpp:mam:0' default='roster'>
|
||||
<prefs xmlns='urn:xmpp:mam:1' default='roster'>
|
||||
<always>
|
||||
<jid>romeo@montague.lit</jid>
|
||||
</always>
|
||||
|
|
@ -245,6 +244,6 @@ class XEP_0313Test(helpers.SatTestCase):
|
|||
""" % (("H_%d" % domish.Element._idCounter), SERVICE)
|
||||
always = [JID('romeo@montague.lit')]
|
||||
never = [JID('montague@montague.lit')]
|
||||
d = self.plugin.setPrefs(SERVICE_JID, always=always, never=never, profile_key=C.PROFILE[0])
|
||||
d = self.plugin.setPrefs(self.client, SERVICE_JID, always=always, never=never)
|
||||
d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
|
||||
return d
|
||||
|
|
|
|||
Loading…
Reference in a new issue