changeset 32:cfee3d472359

test (RSM): fix according to modification in sat.tmp.wokkel.rsm in rev 1771 (54f834e40341)
author souliane <souliane@mailoo.org>
date Tue, 19 Jan 2016 14:59:13 +0100
parents e79eedd9c56a
children c0f71fd5ed6b
files wokkel/test/test_rsm.py
diffstat 1 files changed, 22 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/wokkel/test/test_rsm.py	Tue Jan 19 12:18:29 2016 +0100
+++ b/wokkel/test/test_rsm.py	Tue Jan 19 14:59:13 2016 +0100
@@ -22,6 +22,10 @@
 
 import uuid
 
+RSMResponse.__eq__ = lambda self, other: self.first == other.first and\
+    self.last == other.last and\
+    self.index == other.index and\
+    self.count == other.count
 
 class RSMRequestTest(unittest.TestCase):
     """
@@ -174,7 +178,7 @@
         element.addElement('items')['max_items'] = u'10'
         RSMRequest(3).render(element)
 
-        self.assertEqual(u'3', element.items['max_items'])  # changed
+        self.assertEqual(u'10', element.items['max_items'])  # not changed
 
         self.assertEqual(NS_RSM, element.set.uri)
         self.assertEqual(u'3', ''.join(element.set.max.children))
@@ -187,7 +191,7 @@
         Embed a page request in the element, specify items.
         """
         element = domish.Element(('jabber:iq:search', 'query'))
-        RSMRequest(5, 127).render(element)
+        RSMRequest(5, index=127).render(element)
         self.assertEqual(NS_RSM, element.set.uri)
         self.assertEqual(u'5', ''.join(element.set.max.children))
         self.assertIdentical(None, element.set.after)
@@ -228,16 +232,8 @@
         """
         Fail to initialize a RSMResponse with wrong attribute values.
         """
-        self.assertRaises(AssertionError, RSMResponse, count=u'1')
         self.assertRaises(AssertionError, RSMResponse, index=127, first=u'127')
         self.assertRaises(AssertionError, RSMResponse, index=127, last=u'351')
-        self.assertRaises(AssertionError, RSMResponse, first=u'127', last=u'351')
-        self.assertRaises(AssertionError, RSMResponse, index=u'127',
-                          first=u'127', last=u'351')
-        self.assertRaises(AssertionError, RSMResponse, index=127,
-                          first=127, last=u'351')
-        self.assertRaises(AssertionError, RSMResponse, index=127,
-                          first=u'127', last=351)
 
     def test_parse(self):
         """
@@ -280,8 +276,7 @@
         Embed a page response in the element.
         """
         element = domish.Element(('jabber:iq:search', 'query'))
-        RSMResponse(800, 20, u'stpeter@jabber.org',
-                    u'peterpan@neverland.lit').render(element)
+        RSMResponse(u'stpeter@jabber.org', u'peterpan@neverland.lit', 20, 800).render(element)
 
         self.assertEqual(NS_RSM, element.set.uri)
         self.assertEqual(u'800', ''.join(element.set.count.children))
@@ -296,7 +291,7 @@
         Embed a page response in the element, for empty set.
         """
         element = domish.Element(('jabber:iq:search', 'query'))
-        RSMResponse(800).render(element)
+        RSMResponse(count=800).render(element)
 
         self.assertEqual(NS_RSM, element.set.uri)
         self.assertEqual(u'800', ''.join(element.set.count.children))
@@ -324,8 +319,7 @@
             items, rsm = response
             self.assertEquals(2, len(items))
             self.assertEquals([item1, item2], items)
-            self.assertDictEqual(rsm, {'count': '800', 'index': '0',
-                                       'first': 'item1', 'last': 'item2'})
+            self.assertEquals(rsm, RSMResponse('item1', 'item2', 0, 800))
 
         d = self.protocol.items(JID('pubsub.example.org'), 'test',
                                 rsm_request=RSMRequest(2))
@@ -356,7 +350,7 @@
         item1['id'] = 'item1'
         item2 = items.addElement('item')
         item2['id'] = 'item2'
-        RSMResponse(800, 0, u'item1', u'item2').render(response.pubsub)
+        RSMResponse(u'item1', u'item2', 0, 800).render(response.pubsub)
         self.stub.send(response)
 
         return d
@@ -369,8 +363,7 @@
             items, rsm = response
             self.assertEquals(2, len(items))
             self.assertEquals([item1, item2], items)
-            self.assertDictEqual(rsm, {'count': '800', 'index': '2',
-                                       'first': 'item3', 'last': 'item4'})
+            self.assertEquals(rsm, RSMResponse('item3', 'item4', 2, 800))
 
         d = self.protocol.items(JID('pubsub.example.org'), 'test',
                                 rsm_request=RSMRequest(2, after=u'item2'))
@@ -402,7 +395,7 @@
         item1['id'] = 'item3'
         item2 = items.addElement('item')
         item2['id'] = 'item4'
-        RSMResponse(800, 2, u'item3', u'item4').render(response.pubsub)
+        RSMResponse(u'item3', u'item4', 2, 800).render(response.pubsub)
         self.stub.send(response)
 
         return d
@@ -415,8 +408,7 @@
             items, rsm = response
             self.assertEquals(2, len(items))
             self.assertEquals([item1, item2], items)
-            self.assertDictEqual(rsm, {'count': '800', 'index': '0',
-                                       'first': 'item1', 'last': 'item2'})
+            self.assertEquals(rsm, RSMResponse('item1', 'item2', 0, 800))
 
         d = self.protocol.items(JID('pubsub.example.org'), 'test',
                                 rsm_request=RSMRequest(2, before=u'item3'))
@@ -448,7 +440,7 @@
         item1['id'] = 'item1'
         item2 = items.addElement('item')
         item2['id'] = 'item2'
-        RSMResponse(800, 0, u'item1', u'item2').render(response.pubsub)
+        RSMResponse(u'item1', u'item2', 0, 800).render(response.pubsub)
         self.stub.send(response)
 
         return d
@@ -461,11 +453,10 @@
             items, rsm = response
             self.assertEquals(3, len(items))
             self.assertEquals([item1, item2, item3], items)
-            self.assertDictEqual(rsm, {'count': '800', 'index': '3',
-                                       'first': 'item4', 'last': 'item6'})
+            self.assertEquals(rsm, RSMResponse('item4', 'item6', 3, 800))
 
         d = self.protocol.items(JID('pubsub.example.org'), 'test',
-                                rsm_response=RSMRequest(3, 3))
+                                rsm_request=RSMRequest(3, index=3))
         d.addCallback(cb)
 
         iq = self.stub.output[-1]
@@ -496,7 +487,7 @@
         item2['id'] = 'item5'
         item3 = items.addElement('item')
         item3['id'] = 'item6'
-        RSMResponse(800, 3, u'item4', u'item6').render(response.pubsub)
+        RSMResponse(u'item4', u'item6', 3, 800).render(response.pubsub)
         self.stub.send(response)
 
         return d
@@ -508,7 +499,7 @@
         def cb(response):
             items, rsm = response
             self.assertEquals(0, len(items))
-            self.assertDictEqual(rsm, {'count': '800'})
+            self.assertEquals(rsm, RSMResponse(count=800))
 
         d = self.protocol.items(JID('pubsub.example.org'), 'test',
                                 rsm_request=RSMRequest(0))
@@ -533,7 +524,7 @@
 
         response = toResponse(iq, 'result')
         response.addElement((pubsub.NS_PUBSUB, 'pubsub'))
-        RSMResponse(800).render(response.pubsub)
+        RSMResponse(count=800).render(response.pubsub)
         self.stub.send(response)
 
         return d
@@ -564,7 +555,7 @@
         """
 
         def items(request):
-            rsm = RSMResponse(800, 0, u'item', u'item').toElement()
+            rsm = RSMResponse(u'item', u'item', 0, 800).toElement()
             return defer.succeed([pubsub.Item('current'), rsm])
 
         def cb(element):
@@ -606,7 +597,7 @@
         """
 
         def items(request):
-            rsm = RSMResponse(800, 3, u'i1', u'i2').toElement()
+            rsm = RSMResponse(u'i1', u'i2', 3, 800).toElement()
             return defer.succeed([pubsub.Item('i1'), pubsub.Item('i2'), rsm])
 
         def cb(element):
@@ -652,7 +643,7 @@
         """
 
         def items(request):
-            rsm = RSMResponse(800).toElement()
+            rsm = RSMResponse(count=800).toElement()
             return defer.succeed([rsm])
 
         def cb(element):