diff src/test/test_plugin_xep_0313.py @ 1284:41ffe2c2dddc

plugin XEP-0313: update (still draft)
author souliane <souliane@mailoo.org>
date Fri, 09 Jan 2015 10:51:12 +0100
parents 3a3e3014f9f8
children ed2c718bfe03
line wrap: on
line diff
--- a/src/test/test_plugin_xep_0313.py	Fri Jan 09 10:50:11 2015 +0100
+++ b/src/test/test_plugin_xep_0313.py	Fri Jan 09 10:51:12 2015 +0100
@@ -28,8 +28,11 @@
 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 @@
     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 @@
             </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 @@
             </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 @@
             </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 @@
             </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 @@
               </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 @@
             </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 @@
             </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