comparison src/test/test_plugin_xep_0313.py @ 1910:55440ee00905

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