changeset 1910:55440ee00905

test: update some tests
author souliane <souliane@mailoo.org>
date Fri, 11 Mar 2016 17:42:56 +0100
parents 0681d69cbe0a
children 3b75ab26f09b
files src/test/helpers.py src/test/test_memory.py src/test/test_plugin_misc_groupblog.py src/test/test_plugin_misc_text_syntaxes.py src/test/test_plugin_xep_0277.py src/test/test_plugin_xep_0313.py
diffstat 6 files changed, 50 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/src/test/helpers.py	Fri Mar 11 16:41:44 2016 +0100
+++ b/src/test/helpers.py	Fri Mar 11 17:42:56 2016 +0100
@@ -190,12 +190,12 @@
         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 @@
         # 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):
--- a/src/test/test_memory.py	Fri Mar 11 16:41:44 2016 +0100
+++ b/src/test/test_memory.py	Fri Mar 11 17:42:56 2016 +0100
@@ -131,7 +131,7 @@
         """
         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()
--- a/src/test/test_plugin_misc_groupblog.py	Fri Mar 11 16:41:44 2016 +0100
+++ b/src/test/test_plugin_misc_groupblog.py	Fri Mar 11 17:42:56 2016 +0100
@@ -136,12 +136,13 @@
 
     def setUp(self):
         self.host = helpers.FakeSAT()
+        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.host.plugins['XEP-0060'] = plugin_xep_0060.XEP_0060(self.host)
-        self.host.plugins['XEP-0163'] = plugin_xep_0163.XEP_0163(self.host)
-        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.__initialised = False
         self._initialise(C.PROFILE[0])
 
--- a/src/test/test_plugin_misc_text_syntaxes.py	Fri Mar 11 16:41:44 2016 +0100
+++ b/src/test/test_plugin_misc_text_syntaxes.py	Fri Mar 11 17:42:56 2016 +0100
@@ -58,6 +58,7 @@
 
     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):
--- a/src/test/test_plugin_xep_0277.py	Fri Mar 11 16:41:44 2016 +0100
+++ b/src/test/test_plugin_xep_0277.py	Fri Mar 11 17:42:56 2016 +0100
@@ -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 @@
 
             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)
 
--- a/src/test/test_plugin_xep_0313.py	Fri Mar 11 16:41:44 2016 +0100
+++ b/src/test/test_plugin_xep_0313.py	Fri Mar 11 17:42:56 2016 +0100
@@ -25,12 +25,13 @@
 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 @@
     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 @@
         </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 @@
         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 @@
         """ % (("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 @@
         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 @@
         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 @@
           </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 @@
         """ % (("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