comparison wokkel/test/test_rsm.py @ 31:e79eedd9c56a

test (RSM): fix according to modification in sat.tmp.wokkel: - parse has been renamed to fromElement in rev 1771 (54f834e40341) - use RSMResponse directly instead of ext_data in rev 1773 (777b4e63fc8a)
author souliane <souliane@mailoo.org>
date Tue, 19 Jan 2016 12:18:29 +0100
parents 2cd4f0ab9ad1
children cfee3d472359
comparison
equal deleted inserted replaced
30:73465c020455 31:e79eedd9c56a
48 <set xmlns='http://jabber.org/protocol/rsm'> 48 <set xmlns='http://jabber.org/protocol/rsm'>
49 <max>1</max> 49 <max>1</max>
50 </set> 50 </set>
51 </query> 51 </query>
52 """ 52 """
53 request = RSMRequest.parse(parseXml(xml)) 53 request = RSMRequest.fromElement(parseXml(xml))
54 self.assertEqual(1, request.max) 54 self.assertEqual(1, request.max)
55 self.assertIdentical(None, request.index) 55 self.assertIdentical(None, request.index)
56 self.assertIdentical(None, request.after) 56 self.assertIdentical(None, request.after)
57 self.assertIdentical(None, request.before) 57 self.assertIdentical(None, request.before)
58 58
67 <max>3</max> 67 <max>3</max>
68 <after>peterpan@neverland.lit</after> 68 <after>peterpan@neverland.lit</after>
69 </set> 69 </set>
70 </query> 70 </query>
71 """ 71 """
72 request = RSMRequest.parse(parseXml(xml)) 72 request = RSMRequest.fromElement(parseXml(xml))
73 self.assertEqual(3, request.max) 73 self.assertEqual(3, request.max)
74 self.assertIdentical(None, request.index) 74 self.assertIdentical(None, request.index)
75 self.assertEqual(u'peterpan@neverland.lit', request.after) 75 self.assertEqual(u'peterpan@neverland.lit', request.after)
76 self.assertIdentical(None, request.before) 76 self.assertIdentical(None, request.before)
77 77
86 <max>5</max> 86 <max>5</max>
87 <before>peterpan@pixyland.org</before> 87 <before>peterpan@pixyland.org</before>
88 </set> 88 </set>
89 </query> 89 </query>
90 """ 90 """
91 request = RSMRequest.parse(parseXml(xml)) 91 request = RSMRequest.fromElement(parseXml(xml))
92 self.assertEqual(5, request.max) 92 self.assertEqual(5, request.max)
93 self.assertIdentical(None, request.index) 93 self.assertIdentical(None, request.index)
94 self.assertIdentical(None, request.after) 94 self.assertIdentical(None, request.after)
95 self.assertEqual(u'peterpan@pixyland.org', request.before) 95 self.assertEqual(u'peterpan@pixyland.org', request.before)
96 96
105 <max>7</max> 105 <max>7</max>
106 <before/> 106 <before/>
107 </set> 107 </set>
108 </query> 108 </query>
109 """ 109 """
110 request = RSMRequest.parse(parseXml(xml)) 110 request = RSMRequest.fromElement(parseXml(xml))
111 self.assertEqual(7, request.max) 111 self.assertEqual(7, request.max)
112 self.assertIdentical(None, request.index) 112 self.assertIdentical(None, request.index)
113 self.assertIdentical(None, request.after) 113 self.assertIdentical(None, request.after)
114 self.assertEqual('', request.before) 114 self.assertEqual('', request.before)
115 115
124 <max>9</max> 124 <max>9</max>
125 <index>371</index> 125 <index>371</index>
126 </set> 126 </set>
127 </query> 127 </query>
128 """ 128 """
129 request = RSMRequest.parse(parseXml(xml)) 129 request = RSMRequest.fromElement(parseXml(xml))
130 self.assertEqual(9, request.max) 130 self.assertEqual(9, request.max)
131 self.assertEqual(371, request.index) 131 self.assertEqual(371, request.index)
132 self.assertIdentical(None, request.after) 132 self.assertIdentical(None, request.after)
133 self.assertIdentical(None, request.before) 133 self.assertIdentical(None, request.before)
134 134
142 <set xmlns='http://jabber.org/protocol/rsm'> 142 <set xmlns='http://jabber.org/protocol/rsm'>
143 <max>0</max> 143 <max>0</max>
144 </set> 144 </set>
145 </query> 145 </query>
146 """ 146 """
147 request = RSMRequest.parse(parseXml(xml)) 147 request = RSMRequest.fromElement(parseXml(xml))
148 self.assertEqual(0, request.max) 148 self.assertEqual(0, request.max)
149 self.assertIdentical(None, request.index) 149 self.assertIdentical(None, request.index)
150 self.assertIdentical(None, request.after) 150 self.assertIdentical(None, request.after)
151 self.assertIdentical(None, request.before) 151 self.assertIdentical(None, request.before)
152 152
250 <last>peterpan@neverland.lit</last> 250 <last>peterpan@neverland.lit</last>
251 <count>800</count> 251 <count>800</count>
252 </set> 252 </set>
253 </query> 253 </query>
254 """ 254 """
255 response = RSMResponse.parse(parseXml(xml)) 255 response = RSMResponse.fromElement(parseXml(xml))
256 self.assertEqual(800, response.count) 256 self.assertEqual(800, response.count)
257 self.assertEqual(20, response.index) 257 self.assertEqual(20, response.index)
258 self.assertEqual(u'stpeter@jabber.org', response.first) 258 self.assertEqual(u'stpeter@jabber.org', response.first)
259 self.assertEqual(u'peterpan@neverland.lit', response.last) 259 self.assertEqual(u'peterpan@neverland.lit', response.last)
260 260
267 <set xmlns='http://jabber.org/protocol/rsm'> 267 <set xmlns='http://jabber.org/protocol/rsm'>
268 <count>800</count> 268 <count>800</count>
269 </set> 269 </set>
270 </query> 270 </query>
271 """ 271 """
272 response = RSMResponse.parse(parseXml(xml)) 272 response = RSMResponse.fromElement(parseXml(xml))
273 self.assertEqual(800, response.count) 273 self.assertEqual(800, response.count)
274 self.assertIdentical(None, response.first) 274 self.assertIdentical(None, response.first)
275 self.assertIdentical(None, response.last) 275 self.assertIdentical(None, response.last)
276 self.assertIdentical(None, response.index) 276 self.assertIdentical(None, response.index)
277 277
318 318
319 def test_items(self): 319 def test_items(self):
320 """ 320 """
321 Test sending items request to get the first page. 321 Test sending items request to get the first page.
322 """ 322 """
323 def cb(items): 323 def cb(response):
324 items, rsm = response
324 self.assertEquals(2, len(items)) 325 self.assertEquals(2, len(items))
325 self.assertEquals([item1, item2], items) 326 self.assertEquals([item1, item2], items)
326 rsm = self.protocol.getRSMResponse(ext_data['id'])
327 self.assertDictEqual(rsm, {'count': '800', 'index': '0', 327 self.assertDictEqual(rsm, {'count': '800', 'index': '0',
328 'first': 'item1', 'last': 'item2'}) 328 'first': 'item1', 'last': 'item2'})
329 329
330 ext_data = {'id': unicode(uuid.uuid4()), 'rsm': RSMRequest(2)}
331 d = self.protocol.items(JID('pubsub.example.org'), 'test', 330 d = self.protocol.items(JID('pubsub.example.org'), 'test',
332 ext_data=ext_data) 331 rsm_request=RSMRequest(2))
333 d.addCallback(cb) 332 d.addCallback(cb)
334 333
335 iq = self.stub.output[-1] 334 iq = self.stub.output[-1]
336 self.assertEquals('pubsub.example.org', iq.getAttribute('to')) 335 self.assertEquals('pubsub.example.org', iq.getAttribute('to'))
337 self.assertEquals('get', iq.getAttribute('type')) 336 self.assertEquals('get', iq.getAttribute('type'))
364 363
365 def test_itemsAfter(self): 364 def test_itemsAfter(self):
366 """ 365 """
367 Test sending items request to get the next page. 366 Test sending items request to get the next page.
368 """ 367 """
369 def cb(items): 368 def cb(response):
369 items, rsm = response
370 self.assertEquals(2, len(items)) 370 self.assertEquals(2, len(items))
371 self.assertEquals([item1, item2], items) 371 self.assertEquals([item1, item2], items)
372 rsm = self.protocol.getRSMResponse(ext_data['id'])
373 self.assertDictEqual(rsm, {'count': '800', 'index': '2', 372 self.assertDictEqual(rsm, {'count': '800', 'index': '2',
374 'first': 'item3', 'last': 'item4'}) 373 'first': 'item3', 'last': 'item4'})
375 374
376 ext_data = {'id': unicode(uuid.uuid4()),
377 'rsm': RSMRequest(2, after=u'item2')}
378 d = self.protocol.items(JID('pubsub.example.org'), 'test', 375 d = self.protocol.items(JID('pubsub.example.org'), 'test',
379 ext_data=ext_data) 376 rsm_request=RSMRequest(2, after=u'item2'))
380 d.addCallback(cb) 377 d.addCallback(cb)
381 378
382 iq = self.stub.output[-1] 379 iq = self.stub.output[-1]
383 self.assertEquals('pubsub.example.org', iq.getAttribute('to')) 380 self.assertEquals('pubsub.example.org', iq.getAttribute('to'))
384 self.assertEquals('get', iq.getAttribute('type')) 381 self.assertEquals('get', iq.getAttribute('type'))
412 409
413 def test_itemsBefore(self): 410 def test_itemsBefore(self):
414 """ 411 """
415 Test sending items request to get the previous page. 412 Test sending items request to get the previous page.
416 """ 413 """
417 def cb(items): 414 def cb(response):
415 items, rsm = response
418 self.assertEquals(2, len(items)) 416 self.assertEquals(2, len(items))
419 self.assertEquals([item1, item2], items) 417 self.assertEquals([item1, item2], items)
420 rsm = self.protocol.getRSMResponse(ext_data['id'])
421 self.assertDictEqual(rsm, {'count': '800', 'index': '0', 418 self.assertDictEqual(rsm, {'count': '800', 'index': '0',
422 'first': 'item1', 'last': 'item2'}) 419 'first': 'item1', 'last': 'item2'})
423 420
424 ext_data = {'id': unicode(uuid.uuid4()),
425 'rsm': RSMRequest(2, before=u'item3')}
426 d = self.protocol.items(JID('pubsub.example.org'), 'test', 421 d = self.protocol.items(JID('pubsub.example.org'), 'test',
427 ext_data=ext_data) 422 rsm_request=RSMRequest(2, before=u'item3'))
428 d.addCallback(cb) 423 d.addCallback(cb)
429 424
430 iq = self.stub.output[-1] 425 iq = self.stub.output[-1]
431 self.assertEquals('pubsub.example.org', iq.getAttribute('to')) 426 self.assertEquals('pubsub.example.org', iq.getAttribute('to'))
432 self.assertEquals('get', iq.getAttribute('type')) 427 self.assertEquals('get', iq.getAttribute('type'))
460 455
461 def test_itemsIndex(self): 456 def test_itemsIndex(self):
462 """ 457 """
463 Test sending items request to get a page out of order. 458 Test sending items request to get a page out of order.
464 """ 459 """
465 def cb(items): 460 def cb(response):
461 items, rsm = response
466 self.assertEquals(3, len(items)) 462 self.assertEquals(3, len(items))
467 self.assertEquals([item1, item2, item3], items) 463 self.assertEquals([item1, item2, item3], items)
468 rsm = self.protocol.getRSMResponse(ext_data['id'])
469 self.assertDictEqual(rsm, {'count': '800', 'index': '3', 464 self.assertDictEqual(rsm, {'count': '800', 'index': '3',
470 'first': 'item4', 'last': 'item6'}) 465 'first': 'item4', 'last': 'item6'})
471 466
472 ext_data = {'id': unicode(uuid.uuid4()), 'rsm': RSMRequest(3, 3)}
473 d = self.protocol.items(JID('pubsub.example.org'), 'test', 467 d = self.protocol.items(JID('pubsub.example.org'), 'test',
474 ext_data=ext_data) 468 rsm_response=RSMRequest(3, 3))
475 d.addCallback(cb) 469 d.addCallback(cb)
476 470
477 iq = self.stub.output[-1] 471 iq = self.stub.output[-1]
478 self.assertEquals('pubsub.example.org', iq.getAttribute('to')) 472 self.assertEquals('pubsub.example.org', iq.getAttribute('to'))
479 self.assertEquals('get', iq.getAttribute('type')) 473 self.assertEquals('get', iq.getAttribute('type'))
509 503
510 def test_itemsCount(self): 504 def test_itemsCount(self):
511 """ 505 """
512 Test sending items request to count them. 506 Test sending items request to count them.
513 """ 507 """
514 def cb(items): 508 def cb(response):
509 items, rsm = response
515 self.assertEquals(0, len(items)) 510 self.assertEquals(0, len(items))
516 rsm = self.protocol.getRSMResponse(ext_data['id'])
517 self.assertDictEqual(rsm, {'count': '800'}) 511 self.assertDictEqual(rsm, {'count': '800'})
518 512
519 ext_data = {'id': unicode(uuid.uuid4()), 'rsm': RSMRequest(0)}
520 d = self.protocol.items(JID('pubsub.example.org'), 'test', 513 d = self.protocol.items(JID('pubsub.example.org'), 'test',
521 ext_data=ext_data) 514 rsm_request=RSMRequest(0))
522 d.addCallback(cb) 515 d.addCallback(cb)
523 516
524 iq = self.stub.output[-1] 517 iq = self.stub.output[-1]
525 self.assertEquals('pubsub.example.org', iq.getAttribute('to')) 518 self.assertEquals('pubsub.example.org', iq.getAttribute('to'))
526 self.assertEquals('get', iq.getAttribute('type')) 519 self.assertEquals('get', iq.getAttribute('type'))