comparison 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
comparison
equal deleted inserted replaced
1283:7d9ff14a2d9d 1284:41ffe2c2dddc
26 from twisted.words.protocols.jabber.jid import JID 26 from twisted.words.protocols.jabber.jid import JID
27 from twisted.words.xish import domish 27 from twisted.words.xish import domish
28 from dateutil.tz import tzutc 28 from dateutil.tz import tzutc
29 import datetime 29 import datetime
30 from wokkel.rsm import RSMRequest 30 from wokkel.rsm import RSMRequest
31 from wokkel.mam import buildForm
31 32
32 NS_PUBSUB = 'http://jabber.org/protocol/pubsub' 33 NS_PUBSUB = 'http://jabber.org/protocol/pubsub'
34 SERVICE = 'sat-pubsub.tazar.int'
35 SERVICE_JID = JID(SERVICE)
33 36
34 37
35 class XEP_0313Test(helpers.SatTestCase): 38 class XEP_0313Test(helpers.SatTestCase):
36 39
37 def setUp(self): 40 def setUp(self):
38 self.host = helpers.FakeSAT() 41 self.host = helpers.FakeSAT()
39 self.plugin = XEP_0313(self.host) 42 self.plugin = XEP_0313(self.host)
43 client = self.plugin.getHandler(C.PROFILE[0])
44 client.makeConnection(self.host.getClient(C.PROFILE[0]).xmlstream)
40 45
41 def test_queryArchive(self): 46 def test_queryArchive(self):
42 xml = """ 47 xml = """
43 <iq type='set' id='%s'> 48 <iq type='set' id='%s' to='%s'>
44 <query xmlns='urn:xmpp:mam:0'/> 49 <query xmlns='urn:xmpp:mam:0'/>
45 </iq> 50 </iq>
46 """ % ("H_%d" % domish.Element._idCounter) 51 """ % (("H_%d" % domish.Element._idCounter), SERVICE)
47 d = self.plugin.queryArchive(profile_key=C.PROFILE[0]) 52 d = self.plugin.queryArchive(SERVICE_JID, profile_key=C.PROFILE[0])
48 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) 53 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
49 return d 54 return d
50 55
51 def test_queryArchivePubsub(self): 56 def test_queryArchivePubsub(self):
52 xml = """ 57 xml = """
53 <iq type='set' id='%s'> 58 <iq type='set' id='%s' to='%s'>
54 <query xmlns='urn:xmpp:mam:0' node='fdp/submitted/capulet.lit/sonnets' /> 59 <query xmlns='urn:xmpp:mam:0' node='fdp/submitted/capulet.lit/sonnets' />
55 </iq> 60 </iq>
56 """ % ("H_%d" % domish.Element._idCounter) 61 """ % (("H_%d" % domish.Element._idCounter), SERVICE)
57 d = self.plugin.queryArchive(node="fdp/submitted/capulet.lit/sonnets", profile_key=C.PROFILE[0]) 62 d = self.plugin.queryArchive(SERVICE_JID, node="fdp/submitted/capulet.lit/sonnets", profile_key=C.PROFILE[0])
58 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) 63 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
59 return d 64 return d
60 65
61 def test_queryArchiveWith(self): 66 def test_queryArchiveWith(self):
62 xml = """ 67 xml = """
63 <iq type='set' id='%s'> 68 <iq type='set' id='%s' to='%s'>
64 <query xmlns='urn:xmpp:mam:0'> 69 <query xmlns='urn:xmpp:mam:0'>
65 <x xmlns='jabber:x:data' type='submit'> 70 <x xmlns='jabber:x:data' type='submit'>
66 <field var='FORM_TYPE' type='hidden'> 71 <field var='FORM_TYPE' type='hidden'>
67 <value>urn:xmpp:mam:0</value> 72 <value>urn:xmpp:mam:0</value>
68 </field> 73 </field>
70 <value>juliet@capulet.lit</value> 75 <value>juliet@capulet.lit</value>
71 </field> 76 </field>
72 </x> 77 </x>
73 </query> 78 </query>
74 </iq> 79 </iq>
75 """ % ("H_%d" % domish.Element._idCounter) 80 """ % (("H_%d" % domish.Element._idCounter), SERVICE)
76 form = self.plugin.buildForm(with_jid=JID('juliet@capulet.lit')) 81 form = buildForm(with_jid=JID('juliet@capulet.lit'))
77 d = self.plugin.queryArchive(form, profile_key=C.PROFILE[0]) 82 d = self.plugin.queryArchive(SERVICE_JID, form, profile_key=C.PROFILE[0])
78 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) 83 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
79 return d 84 return d
80 85
81 def test_queryArchiveStartEnd(self): 86 def test_queryArchiveStartEnd(self):
82 xml = """ 87 xml = """
83 <iq type='set' id='%s'> 88 <iq type='set' id='%s' to='%s'>
84 <query xmlns='urn:xmpp:mam:0'> 89 <query xmlns='urn:xmpp:mam:0'>
85 <x xmlns='jabber:x:data' type='submit'> 90 <x xmlns='jabber:x:data' type='submit'>
86 <field var='FORM_TYPE' type='hidden'> 91 <field var='FORM_TYPE' type='hidden'>
87 <value>urn:xmpp:mam:0</value> 92 <value>urn:xmpp:mam:0</value>
88 </field> 93 </field>
93 <value>2010-07-07T13:23:54Z</value> 98 <value>2010-07-07T13:23:54Z</value>
94 </field> 99 </field>
95 </x> 100 </x>
96 </query> 101 </query>
97 </iq> 102 </iq>
98 """ % ("H_%d" % domish.Element._idCounter) 103 """ % (("H_%d" % domish.Element._idCounter), SERVICE)
99 start = datetime.datetime(2010, 6, 7, 0, 0, 0, tzinfo=tzutc()) 104 start = datetime.datetime(2010, 6, 7, 0, 0, 0, tzinfo=tzutc())
100 end = datetime.datetime(2010, 7, 7, 13, 23, 54, tzinfo=tzutc()) 105 end = datetime.datetime(2010, 7, 7, 13, 23, 54, tzinfo=tzutc())
101 form = self.plugin.buildForm(start=start, end=end) 106 form = buildForm(start=start, end=end)
102 d = self.plugin.queryArchive(form, profile_key=C.PROFILE[0]) 107 d = self.plugin.queryArchive(SERVICE_JID, form, profile_key=C.PROFILE[0])
103 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) 108 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
104 return d 109 return d
105 110
106 def test_queryArchiveStart(self): 111 def test_queryArchiveStart(self):
107 xml = """ 112 xml = """
108 <iq type='set' id='%s'> 113 <iq type='set' id='%s' to='%s'>
109 <query xmlns='urn:xmpp:mam:0'> 114 <query xmlns='urn:xmpp:mam:0'>
110 <x xmlns='jabber:x:data' type='submit'> 115 <x xmlns='jabber:x:data' type='submit'>
111 <field var='FORM_TYPE' type='hidden'> 116 <field var='FORM_TYPE' type='hidden'>
112 <value>urn:xmpp:mam:0</value> 117 <value>urn:xmpp:mam:0</value>
113 </field> 118 </field>
115 <value>2010-08-07T00:00:00Z</value> 120 <value>2010-08-07T00:00:00Z</value>
116 </field> 121 </field>
117 </x> 122 </x>
118 </query> 123 </query>
119 </iq> 124 </iq>
120 """ % ("H_%d" % domish.Element._idCounter) 125 """ % (("H_%d" % domish.Element._idCounter), SERVICE)
121 start = datetime.datetime(2010, 8, 7, 0, 0, 0, tzinfo=tzutc()) 126 start = datetime.datetime(2010, 8, 7, 0, 0, 0, tzinfo=tzutc())
122 form = self.plugin.buildForm(start=start) 127 form = buildForm(start=start)
123 d = self.plugin.queryArchive(form, profile_key=C.PROFILE[0]) 128 d = self.plugin.queryArchive(SERVICE_JID, form, profile_key=C.PROFILE[0])
124 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) 129 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
125 return d 130 return d
126 131
127 def test_queryArchiveRSM(self): 132 def test_queryArchiveRSM(self):
128 xml = """ 133 xml = """
129 <iq type='set' id='%s'> 134 <iq type='set' id='%s' to='%s'>
130 <query xmlns='urn:xmpp:mam:0'> 135 <query xmlns='urn:xmpp:mam:0'>
131 <x xmlns='jabber:x:data' type='submit'> 136 <x xmlns='jabber:x:data' type='submit'>
132 <field var='FORM_TYPE' type='hidden'> 137 <field var='FORM_TYPE' type='hidden'>
133 <value>urn:xmpp:mam:0</value> 138 <value>urn:xmpp:mam:0</value>
134 </field> 139 </field>
139 <set xmlns='http://jabber.org/protocol/rsm'> 144 <set xmlns='http://jabber.org/protocol/rsm'>
140 <max>10</max> 145 <max>10</max>
141 </set> 146 </set>
142 </query> 147 </query>
143 </iq> 148 </iq>
144 """ % ("H_%d" % domish.Element._idCounter) 149 """ % (("H_%d" % domish.Element._idCounter), SERVICE)
145 start = datetime.datetime(2010, 8, 7, 0, 0, 0, tzinfo=tzutc()) 150 start = datetime.datetime(2010, 8, 7, 0, 0, 0, tzinfo=tzutc())
146 form = self.plugin.buildForm(start=start) 151 form = buildForm(start=start)
147 rsm = RSMRequest(max=10) 152 rsm = RSMRequest(max=10)
148 d = self.plugin.queryArchive(form=form, rsm=rsm, profile_key=C.PROFILE[0]) 153 d = self.plugin.queryArchive(SERVICE_JID, form=form, rsm=rsm, profile_key=C.PROFILE[0])
149 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) 154 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
150 return d 155 return d
151 156
152 def test_queryArchiveRSMPaging(self): 157 def test_queryArchiveRSMPaging(self):
153 xml = """ 158 xml = """
154 <iq type='set' id='%s'> 159 <iq type='set' id='%s' to='%s'>
155 <query xmlns='urn:xmpp:mam:0'> 160 <query xmlns='urn:xmpp:mam:0'>
156 <x xmlns='jabber:x:data' type='submit'> 161 <x xmlns='jabber:x:data' type='submit'>
157 <field var='FORM_TYPE' type='hidden'><value>urn:xmpp:mam:0</value></field> 162 <field var='FORM_TYPE' type='hidden'><value>urn:xmpp:mam:0</value></field>
158 <field var='start' type='text-single'><value>2010-08-07T00:00:00Z</value></field> 163 <field var='start' type='text-single'><value>2010-08-07T00:00:00Z</value></field>
159 </x> 164 </x>
161 <max>10</max> 166 <max>10</max>
162 <after>09af3-cc343-b409f</after> 167 <after>09af3-cc343-b409f</after>
163 </set> 168 </set>
164 </query> 169 </query>
165 </iq> 170 </iq>
166 """ % ("H_%d" % domish.Element._idCounter) 171 """ % (("H_%d" % domish.Element._idCounter), SERVICE)
167 start = datetime.datetime(2010, 8, 7, 0, 0, 0, tzinfo=tzutc()) 172 start = datetime.datetime(2010, 8, 7, 0, 0, 0, tzinfo=tzutc())
168 form = self.plugin.buildForm(start=start) 173 form = buildForm(start=start)
169 rsm = RSMRequest(max=10, after=u'09af3-cc343-b409f') 174 rsm = RSMRequest(max=10, after=u'09af3-cc343-b409f')
170 d = self.plugin.queryArchive(form=form, rsm=rsm, profile_key=C.PROFILE[0]) 175 d = self.plugin.queryArchive(SERVICE_JID, form=form, rsm=rsm, profile_key=C.PROFILE[0])
171 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) 176 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
172 return d 177 return d
173 178
174 def test_queryFields(self): 179 def test_queryFields(self):
175 xml = """ 180 xml = """
176 <iq type='get' id="%s"> 181 <iq type='get' id="%s" to='%s'>
177 <query xmlns='urn:xmpp:mam:0'/> 182 <query xmlns='urn:xmpp:mam:0'/>
178 </iq> 183 </iq>
179 """ % ("H_%d" % domish.Element._idCounter) 184 """ % (("H_%d" % domish.Element._idCounter), SERVICE)
180 d = self.plugin.queryFields(C.PROFILE[0]) 185 d = self.plugin.queryFields(SERVICE_JID, C.PROFILE[0])
181 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) 186 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
182 return d 187 return d
183 188
184 def test_queryArchiveFields(self): 189 def test_queryArchiveFields(self):
185 xml = """ 190 xml = """
186 <iq type='set' id='%s'> 191 <iq type='set' id='%s' to='%s'>
187 <query xmlns='urn:xmpp:mam:0'> 192 <query xmlns='urn:xmpp:mam:0'>
188 <x xmlns='jabber:x:data' type='submit'> 193 <x xmlns='jabber:x:data' type='submit'>
189 <field type='hidden' var='FORM_TYPE'> 194 <field type='hidden' var='FORM_TYPE'>
190 <value>urn:xmpp:mam:0</value> 195 <value>urn:xmpp:mam:0</value>
191 </field> 196 </field>
196 <value>{http://jabber.org/protocol/mood}mood/lonely</value> 201 <value>{http://jabber.org/protocol/mood}mood/lonely</value>
197 </field> 202 </field>
198 </x> 203 </x>
199 </query> 204 </query>
200 </iq> 205 </iq>
201 """ % ("H_%d" % domish.Element._idCounter) 206 """ % (("H_%d" % domish.Element._idCounter), SERVICE)
202 extra = (('text-single', 'urn:example:xmpp:free-text-search', 207 extra = [{'fieldType': 'text-single',
203 'Where arth thou, my Juliet?'), 208 'var': 'urn:example:xmpp:free-text-search',
204 ('text-single', 'urn:example:xmpp:stanza-content', 209 'value': 'Where arth thou, my Juliet?'},
205 '{http://jabber.org/protocol/mood}mood/lonely')) 210 {'fieldType': 'text-single',
206 form = self.plugin.buildForm(extra=extra) 211 'var': 'urn:example:xmpp:stanza-content',
207 d = self.plugin.queryArchive(form=form, profile_key=C.PROFILE[0]) 212 'value': '{http://jabber.org/protocol/mood}mood/lonely'}]
213 form = buildForm(extra=extra)
214 d = self.plugin.queryArchive(SERVICE_JID, form=form, profile_key=C.PROFILE[0])
208 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) 215 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
209 return d 216 return d
210 217
211 def test_queryPrefs(self): 218 def test_queryPrefs(self):
212 xml = """ 219 xml = """
213 <iq type='get' id='%s'> 220 <iq type='get' id='%s' to='%s'>
214 <prefs xmlns='urn:xmpp:mam:0'/> 221 <prefs xmlns='urn:xmpp:mam:0'>
215 </iq> 222 <always/>
216 """ % ("H_%d" % domish.Element._idCounter) 223 <never/>
217 d = self.plugin.queryPrefs(profile_key=C.PROFILE[0]) 224 </prefs>
225 </iq>
226 """ % (("H_%d" % domish.Element._idCounter), SERVICE)
227 d = self.plugin.getPrefs(SERVICE_JID, profile_key=C.PROFILE[0])
218 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) 228 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
219 return d 229 return d
220 230
221 def test_setPrefs(self): 231 def test_setPrefs(self):
222 xml = """ 232 xml = """
223 <iq type='set' id='%s'> 233 <iq type='set' id='%s' to='%s'>
224 <prefs xmlns='urn:xmpp:mam:0' default='roster'> 234 <prefs xmlns='urn:xmpp:mam:0' default='roster'>
225 <always> 235 <always>
226 <jid>romeo@montague.lit</jid> 236 <jid>romeo@montague.lit</jid>
227 </always> 237 </always>
228 <never> 238 <never>
229 <jid>montague@montague.lit</jid> 239 <jid>montague@montague.lit</jid>
230 </never> 240 </never>
231 </prefs> 241 </prefs>
232 </iq> 242 </iq>
233 """ % ("H_%d" % domish.Element._idCounter) 243 """ % (("H_%d" % domish.Element._idCounter), SERVICE)
234 always = [JID('romeo@montague.lit')] 244 always = [JID('romeo@montague.lit')]
235 never = [JID('montague@montague.lit')] 245 never = [JID('montague@montague.lit')]
236 d = self.plugin.setPrefs(always=always, never=never, profile_key=C.PROFILE[0]) 246 d = self.plugin.setPrefs(SERVICE_JID, always=always, never=never, profile_key=C.PROFILE[0])
237 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) 247 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True))
238 return d 248 return d