comparison sat/test/test_plugin_xep_0313.py @ 2624:56f94936df1e

code style reformatting using black
author Goffi <goffi@goffi.org>
date Wed, 27 Jun 2018 20:14:46 +0200
parents 26edcf3a30eb
children 378188abe941
comparison
equal deleted inserted replaced
2623:49533de4540b 2624:56f94936df1e
31 31
32 # TODO: change this when RSM and MAM are in wokkel 32 # TODO: change this when RSM and MAM are in wokkel
33 from sat_tmp.wokkel.rsm import RSMRequest 33 from sat_tmp.wokkel.rsm import RSMRequest
34 from sat_tmp.wokkel.mam import buildForm, MAMRequest 34 from sat_tmp.wokkel.mam import buildForm, MAMRequest
35 35
36 NS_PUBSUB = 'http://jabber.org/protocol/pubsub' 36 NS_PUBSUB = "http://jabber.org/protocol/pubsub"
37 SERVICE = 'sat-pubsub.tazar.int' 37 SERVICE = "sat-pubsub.tazar.int"
38 SERVICE_JID = JID(SERVICE) 38 SERVICE_JID = JID(SERVICE)
39 39
40 40
41 class XEP_0313Test(helpers.SatTestCase): 41 class XEP_0313Test(helpers.SatTestCase):
42
43 def setUp(self): 42 def setUp(self):
44 self.host = helpers.FakeSAT() 43 self.host = helpers.FakeSAT()
45 self.plugin = XEP_0313(self.host) 44 self.plugin = XEP_0313(self.host)
46 self.client = self.host.getClient(C.PROFILE[0]) 45 self.client = self.host.getClient(C.PROFILE[0])
47 mam_client = self.plugin.getHandler(C.PROFILE[0]) 46 mam_client = self.plugin.getHandler(C.PROFILE[0])
50 def test_queryArchive(self): 49 def test_queryArchive(self):
51 xml = """ 50 xml = """
52 <iq type='set' id='%s' to='%s'> 51 <iq type='set' id='%s' to='%s'>
53 <query xmlns='urn:xmpp:mam:1'/> 52 <query xmlns='urn:xmpp:mam:1'/>
54 </iq> 53 </iq>
55 """ % (("H_%d" % domish.Element._idCounter), SERVICE) 54 """ % (
55 ("H_%d" % domish.Element._idCounter),
56 SERVICE,
57 )
56 d = self.plugin.queryArchive(self.client, MAMRequest(), SERVICE_JID) 58 d = self.plugin.queryArchive(self.client, MAMRequest(), SERVICE_JID)
57 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) 59 d.addCallback(
60 lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)
61 )
58 return d 62 return d
59 63
60 def test_queryArchivePubsub(self): 64 def test_queryArchivePubsub(self):
61 xml = """ 65 xml = """
62 <iq type='set' id='%s' to='%s'> 66 <iq type='set' id='%s' to='%s'>
63 <query xmlns='urn:xmpp:mam:1' node='fdp/submitted/capulet.lit/sonnets' /> 67 <query xmlns='urn:xmpp:mam:1' node='fdp/submitted/capulet.lit/sonnets' />
64 </iq> 68 </iq>
65 """ % (("H_%d" % domish.Element._idCounter), SERVICE) 69 """ % (
66 d = self.plugin.queryArchive(self.client, MAMRequest(node="fdp/submitted/capulet.lit/sonnets"), SERVICE_JID) 70 ("H_%d" % domish.Element._idCounter),
67 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) 71 SERVICE,
72 )
73 d = self.plugin.queryArchive(
74 self.client, MAMRequest(node="fdp/submitted/capulet.lit/sonnets"), SERVICE_JID
75 )
76 d.addCallback(
77 lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)
78 )
68 return d 79 return d
69 80
70 def test_queryArchiveWith(self): 81 def test_queryArchiveWith(self):
71 xml = """ 82 xml = """
72 <iq type='set' id='%s' to='%s'> 83 <iq type='set' id='%s' to='%s'>
79 <value>juliet@capulet.lit</value> 90 <value>juliet@capulet.lit</value>
80 </field> 91 </field>
81 </x> 92 </x>
82 </query> 93 </query>
83 </iq> 94 </iq>
84 """ % (("H_%d" % domish.Element._idCounter), SERVICE) 95 """ % (
85 form = buildForm(with_jid=JID('juliet@capulet.lit')) 96 ("H_%d" % domish.Element._idCounter),
97 SERVICE,
98 )
99 form = buildForm(with_jid=JID("juliet@capulet.lit"))
86 d = self.plugin.queryArchive(self.client, MAMRequest(form), SERVICE_JID) 100 d = self.plugin.queryArchive(self.client, MAMRequest(form), SERVICE_JID)
87 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) 101 d.addCallback(
102 lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)
103 )
88 return d 104 return d
89 105
90 def test_queryArchiveStartEnd(self): 106 def test_queryArchiveStartEnd(self):
91 xml = """ 107 xml = """
92 <iq type='set' id='%s' to='%s'> 108 <iq type='set' id='%s' to='%s'>
102 <value>2010-07-07T13:23:54Z</value> 118 <value>2010-07-07T13:23:54Z</value>
103 </field> 119 </field>
104 </x> 120 </x>
105 </query> 121 </query>
106 </iq> 122 </iq>
107 """ % (("H_%d" % domish.Element._idCounter), SERVICE) 123 """ % (
124 ("H_%d" % domish.Element._idCounter),
125 SERVICE,
126 )
108 start = datetime.datetime(2010, 6, 7, 0, 0, 0, tzinfo=tzutc()) 127 start = datetime.datetime(2010, 6, 7, 0, 0, 0, tzinfo=tzutc())
109 end = datetime.datetime(2010, 7, 7, 13, 23, 54, tzinfo=tzutc()) 128 end = datetime.datetime(2010, 7, 7, 13, 23, 54, tzinfo=tzutc())
110 form = buildForm(start=start, end=end) 129 form = buildForm(start=start, end=end)
111 d = self.plugin.queryArchive(self.client, MAMRequest(form), SERVICE_JID) 130 d = self.plugin.queryArchive(self.client, MAMRequest(form), SERVICE_JID)
112 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) 131 d.addCallback(
132 lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)
133 )
113 return d 134 return d
114 135
115 def test_queryArchiveStart(self): 136 def test_queryArchiveStart(self):
116 xml = """ 137 xml = """
117 <iq type='set' id='%s' to='%s'> 138 <iq type='set' id='%s' to='%s'>
124 <value>2010-08-07T00:00:00Z</value> 145 <value>2010-08-07T00:00:00Z</value>
125 </field> 146 </field>
126 </x> 147 </x>
127 </query> 148 </query>
128 </iq> 149 </iq>
129 """ % (("H_%d" % domish.Element._idCounter), SERVICE) 150 """ % (
151 ("H_%d" % domish.Element._idCounter),
152 SERVICE,
153 )
130 start = datetime.datetime(2010, 8, 7, 0, 0, 0, tzinfo=tzutc()) 154 start = datetime.datetime(2010, 8, 7, 0, 0, 0, tzinfo=tzutc())
131 form = buildForm(start=start) 155 form = buildForm(start=start)
132 d = self.plugin.queryArchive(self.client, MAMRequest(form), SERVICE_JID) 156 d = self.plugin.queryArchive(self.client, MAMRequest(form), SERVICE_JID)
133 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) 157 d.addCallback(
158 lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)
159 )
134 return d 160 return d
135 161
136 def test_queryArchiveRSM(self): 162 def test_queryArchiveRSM(self):
137 xml = """ 163 xml = """
138 <iq type='set' id='%s' to='%s'> 164 <iq type='set' id='%s' to='%s'>
148 <set xmlns='http://jabber.org/protocol/rsm'> 174 <set xmlns='http://jabber.org/protocol/rsm'>
149 <max>10</max> 175 <max>10</max>
150 </set> 176 </set>
151 </query> 177 </query>
152 </iq> 178 </iq>
153 """ % (("H_%d" % domish.Element._idCounter), SERVICE) 179 """ % (
180 ("H_%d" % domish.Element._idCounter),
181 SERVICE,
182 )
154 start = datetime.datetime(2010, 8, 7, 0, 0, 0, tzinfo=tzutc()) 183 start = datetime.datetime(2010, 8, 7, 0, 0, 0, tzinfo=tzutc())
155 form = buildForm(start=start) 184 form = buildForm(start=start)
156 rsm = RSMRequest(max_=10) 185 rsm = RSMRequest(max_=10)
157 d = self.plugin.queryArchive(self.client, MAMRequest(form, rsm), SERVICE_JID) 186 d = self.plugin.queryArchive(self.client, MAMRequest(form, rsm), SERVICE_JID)
158 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) 187 d.addCallback(
188 lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)
189 )
159 return d 190 return d
160 191
161 def test_queryArchiveRSMPaging(self): 192 def test_queryArchiveRSMPaging(self):
162 xml = """ 193 xml = """
163 <iq type='set' id='%s' to='%s'> 194 <iq type='set' id='%s' to='%s'>
170 <max>10</max> 201 <max>10</max>
171 <after>09af3-cc343-b409f</after> 202 <after>09af3-cc343-b409f</after>
172 </set> 203 </set>
173 </query> 204 </query>
174 </iq> 205 </iq>
175 """ % (("H_%d" % domish.Element._idCounter), SERVICE) 206 """ % (
207 ("H_%d" % domish.Element._idCounter),
208 SERVICE,
209 )
176 start = datetime.datetime(2010, 8, 7, 0, 0, 0, tzinfo=tzutc()) 210 start = datetime.datetime(2010, 8, 7, 0, 0, 0, tzinfo=tzutc())
177 form = buildForm(start=start) 211 form = buildForm(start=start)
178 rsm = RSMRequest(max_=10, after=u'09af3-cc343-b409f') 212 rsm = RSMRequest(max_=10, after=u"09af3-cc343-b409f")
179 d = self.plugin.queryArchive(self.client, MAMRequest(form, rsm), SERVICE_JID) 213 d = self.plugin.queryArchive(self.client, MAMRequest(form, rsm), SERVICE_JID)
180 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) 214 d.addCallback(
215 lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)
216 )
181 return d 217 return d
182 218
183 def test_queryFields(self): 219 def test_queryFields(self):
184 xml = """ 220 xml = """
185 <iq type='get' id="%s" to='%s'> 221 <iq type='get' id="%s" to='%s'>
186 <query xmlns='urn:xmpp:mam:1'/> 222 <query xmlns='urn:xmpp:mam:1'/>
187 </iq> 223 </iq>
188 """ % (("H_%d" % domish.Element._idCounter), SERVICE) 224 """ % (
225 ("H_%d" % domish.Element._idCounter),
226 SERVICE,
227 )
189 d = self.plugin.queryFields(self.client, SERVICE_JID) 228 d = self.plugin.queryFields(self.client, SERVICE_JID)
190 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) 229 d.addCallback(
230 lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)
231 )
191 return d 232 return d
192 233
193 def test_queryArchiveFields(self): 234 def test_queryArchiveFields(self):
194 xml = """ 235 xml = """
195 <iq type='set' id='%s' to='%s'> 236 <iq type='set' id='%s' to='%s'>
205 <value>{http://jabber.org/protocol/mood}mood/lonely</value> 246 <value>{http://jabber.org/protocol/mood}mood/lonely</value>
206 </field> 247 </field>
207 </x> 248 </x>
208 </query> 249 </query>
209 </iq> 250 </iq>
210 """ % (("H_%d" % domish.Element._idCounter), SERVICE) 251 """ % (
211 extra_fields = [Field('text-single', 'urn:example:xmpp:free-text-search', 'Where arth thou, my Juliet?'), 252 ("H_%d" % domish.Element._idCounter),
212 Field('text-single', 'urn:example:xmpp:stanza-content', '{http://jabber.org/protocol/mood}mood/lonely') 253 SERVICE,
213 ] 254 )
255 extra_fields = [
256 Field(
257 "text-single",
258 "urn:example:xmpp:free-text-search",
259 "Where arth thou, my Juliet?",
260 ),
261 Field(
262 "text-single",
263 "urn:example:xmpp:stanza-content",
264 "{http://jabber.org/protocol/mood}mood/lonely",
265 ),
266 ]
214 form = buildForm(extra_fields=extra_fields) 267 form = buildForm(extra_fields=extra_fields)
215 d = self.plugin.queryArchive(self.client, MAMRequest(form), SERVICE_JID) 268 d = self.plugin.queryArchive(self.client, MAMRequest(form), SERVICE_JID)
216 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) 269 d.addCallback(
270 lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)
271 )
217 return d 272 return d
218 273
219 def test_queryPrefs(self): 274 def test_queryPrefs(self):
220 xml = """ 275 xml = """
221 <iq type='get' id='%s' to='%s'> 276 <iq type='get' id='%s' to='%s'>
222 <prefs xmlns='urn:xmpp:mam:1'> 277 <prefs xmlns='urn:xmpp:mam:1'>
223 <always/> 278 <always/>
224 <never/> 279 <never/>
225 </prefs> 280 </prefs>
226 </iq> 281 </iq>
227 """ % (("H_%d" % domish.Element._idCounter), SERVICE) 282 """ % (
283 ("H_%d" % domish.Element._idCounter),
284 SERVICE,
285 )
228 d = self.plugin.getPrefs(self.client, SERVICE_JID) 286 d = self.plugin.getPrefs(self.client, SERVICE_JID)
229 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) 287 d.addCallback(
288 lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)
289 )
230 return d 290 return d
231 291
232 def test_setPrefs(self): 292 def test_setPrefs(self):
233 xml = """ 293 xml = """
234 <iq type='set' id='%s' to='%s'> 294 <iq type='set' id='%s' to='%s'>
239 <never> 299 <never>
240 <jid>montague@montague.lit</jid> 300 <jid>montague@montague.lit</jid>
241 </never> 301 </never>
242 </prefs> 302 </prefs>
243 </iq> 303 </iq>
244 """ % (("H_%d" % domish.Element._idCounter), SERVICE) 304 """ % (
245 always = [JID('romeo@montague.lit')] 305 ("H_%d" % domish.Element._idCounter),
246 never = [JID('montague@montague.lit')] 306 SERVICE,
307 )
308 always = [JID("romeo@montague.lit")]
309 never = [JID("montague@montague.lit")]
247 d = self.plugin.setPrefs(self.client, SERVICE_JID, always=always, never=never) 310 d = self.plugin.setPrefs(self.client, SERVICE_JID, always=always, never=never)
248 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)) 311 d.addCallback(
249 return d 312 lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), xml, True)
313 )
314 return d