annotate src/tmp/wokkel/test/test_rsm.py @ 2215:5831e8fcc5f8

jp (invitation): invitation command first draft
author Goffi <goffi@goffi.org>
date Wed, 29 Mar 2017 19:42:44 +0200
parents 2a030a830ebd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
1 # Copyright (c) Adrien Cossa.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
2 # See LICENSE for details.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
3
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
4 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
5 Tests for L{wokkel.rsm}.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
6 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
7
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
8 from zope.interface import verify
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
9
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
10 from twisted.trial import unittest
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
11 from twisted.words.xish import domish
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
12 from twisted.words.protocols.jabber.jid import JID
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
13 from twisted.words.protocols.jabber.xmlstream import toResponse
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
14 from twisted.internet import defer
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
15
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
16 from wokkel.generic import parseXml
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
17 from wokkel import iwokkel
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
18 from wokkel.test.helpers import XmlStreamStub, TestableRequestHandlerMixin
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
19
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
20 from sat.tmp.wokkel import pubsub
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
21 from sat.tmp.wokkel.rsm import NS_RSM, RSMRequest, RSMResponse, PubSubClient, PubSubService
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
22
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
23 import uuid
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
24
1816
2a030a830ebd test (RSM): fix according to modification in sat.tmp.wokkel.rsm in rev 1771 (b77dc676a4df)
souliane <souliane@mailoo.org>
parents: 1815
diff changeset
25 RSMResponse.__eq__ = lambda self, other: self.first == other.first and\
2a030a830ebd test (RSM): fix according to modification in sat.tmp.wokkel.rsm in rev 1771 (b77dc676a4df)
souliane <souliane@mailoo.org>
parents: 1815
diff changeset
26 self.last == other.last and\
2a030a830ebd test (RSM): fix according to modification in sat.tmp.wokkel.rsm in rev 1771 (b77dc676a4df)
souliane <souliane@mailoo.org>
parents: 1815
diff changeset
27 self.index == other.index and\
2a030a830ebd test (RSM): fix according to modification in sat.tmp.wokkel.rsm in rev 1771 (b77dc676a4df)
souliane <souliane@mailoo.org>
parents: 1815
diff changeset
28 self.count == other.count
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
29
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
30 class RSMRequestTest(unittest.TestCase):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
31 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
32 Tests for L{rsm.RSMRequest}.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
33 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
34
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
35 def test___init__(self):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
36 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
37 Fail to initialize a RSMRequest with wrong attribute values.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
38 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
39 self.assertRaises(AssertionError, RSMRequest, index=371, after=u'test')
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
40 self.assertRaises(AssertionError, RSMRequest, index=371, before=u'test')
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
41 self.assertRaises(AssertionError, RSMRequest, before=117)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
42 self.assertRaises(AssertionError, RSMRequest, after=312)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
43 self.assertRaises(AssertionError, RSMRequest, after=u'117', before=u'312')
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
44
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
45 def test_parse(self):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
46 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
47 Parse a request element asking for the first page.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
48 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
49 xml = """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
50 <query xmlns='jabber:iq:search'>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
51 <nick>Pete</nick>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
52 <set xmlns='http://jabber.org/protocol/rsm'>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
53 <max>1</max>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
54 </set>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
55 </query>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
56 """
1815
ec764bfb146d test (RSM): fix according to modification in sat.tmp.wokkel:
souliane <souliane@mailoo.org>
parents: 1438
diff changeset
57 request = RSMRequest.fromElement(parseXml(xml))
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
58 self.assertEqual(1, request.max)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
59 self.assertIdentical(None, request.index)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
60 self.assertIdentical(None, request.after)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
61 self.assertIdentical(None, request.before)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
62
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
63 def test_parseSecondPage(self):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
64 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
65 Parse a request element asking for a next page.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
66 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
67 xml = """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
68 <query xmlns='jabber:iq:search'>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
69 <nick>Pete</nick>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
70 <set xmlns='http://jabber.org/protocol/rsm'>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
71 <max>3</max>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
72 <after>peterpan@neverland.lit</after>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
73 </set>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
74 </query>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
75 """
1815
ec764bfb146d test (RSM): fix according to modification in sat.tmp.wokkel:
souliane <souliane@mailoo.org>
parents: 1438
diff changeset
76 request = RSMRequest.fromElement(parseXml(xml))
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
77 self.assertEqual(3, request.max)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
78 self.assertIdentical(None, request.index)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
79 self.assertEqual(u'peterpan@neverland.lit', request.after)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
80 self.assertIdentical(None, request.before)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
81
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
82 def test_parsePreviousPage(self):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
83 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
84 Parse a request element asking for a previous page.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
85 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
86 xml = """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
87 <query xmlns='jabber:iq:search'>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
88 <nick>Pete</nick>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
89 <set xmlns='http://jabber.org/protocol/rsm'>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
90 <max>5</max>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
91 <before>peterpan@pixyland.org</before>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
92 </set>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
93 </query>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
94 """
1815
ec764bfb146d test (RSM): fix according to modification in sat.tmp.wokkel:
souliane <souliane@mailoo.org>
parents: 1438
diff changeset
95 request = RSMRequest.fromElement(parseXml(xml))
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
96 self.assertEqual(5, request.max)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
97 self.assertIdentical(None, request.index)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
98 self.assertIdentical(None, request.after)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
99 self.assertEqual(u'peterpan@pixyland.org', request.before)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
100
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
101 def test_parseLastPage(self):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
102 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
103 Parse a request element asking for the last page.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
104 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
105 xml = """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
106 <query xmlns='jabber:iq:search'>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
107 <nick>Pete</nick>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
108 <set xmlns='http://jabber.org/protocol/rsm'>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
109 <max>7</max>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
110 <before/>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
111 </set>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
112 </query>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
113 """
1815
ec764bfb146d test (RSM): fix according to modification in sat.tmp.wokkel:
souliane <souliane@mailoo.org>
parents: 1438
diff changeset
114 request = RSMRequest.fromElement(parseXml(xml))
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
115 self.assertEqual(7, request.max)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
116 self.assertIdentical(None, request.index)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
117 self.assertIdentical(None, request.after)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
118 self.assertEqual('', request.before)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
119
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
120 def test_parseOutOfOrderPage(self):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
121 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
122 Parse a request element asking for a page out of order.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
123 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
124 xml = """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
125 <query xmlns='jabber:iq:search'>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
126 <nick>Pete</nick>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
127 <set xmlns='http://jabber.org/protocol/rsm'>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
128 <max>9</max>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
129 <index>371</index>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
130 </set>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
131 </query>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
132 """
1815
ec764bfb146d test (RSM): fix according to modification in sat.tmp.wokkel:
souliane <souliane@mailoo.org>
parents: 1438
diff changeset
133 request = RSMRequest.fromElement(parseXml(xml))
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
134 self.assertEqual(9, request.max)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
135 self.assertEqual(371, request.index)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
136 self.assertIdentical(None, request.after)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
137 self.assertIdentical(None, request.before)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
138
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
139 def test_parseItemCount(self):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
140 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
141 Parse a request element asking for the items count.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
142 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
143 xml = """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
144 <query xmlns='jabber:iq:search'>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
145 <nick>Pete</nick>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
146 <set xmlns='http://jabber.org/protocol/rsm'>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
147 <max>0</max>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
148 </set>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
149 </query>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
150 """
1815
ec764bfb146d test (RSM): fix according to modification in sat.tmp.wokkel:
souliane <souliane@mailoo.org>
parents: 1438
diff changeset
151 request = RSMRequest.fromElement(parseXml(xml))
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
152 self.assertEqual(0, request.max)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
153 self.assertIdentical(None, request.index)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
154 self.assertIdentical(None, request.after)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
155 self.assertIdentical(None, request.before)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
156
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
157 def test_render(self):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
158 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
159 Embed a page request in the element.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
160 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
161 element = domish.Element(('jabber:iq:search', 'query'))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
162 element.addElement('items')['max_items'] = u'10'
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
163 RSMRequest(1).render(element)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
164
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
165 self.assertEqual(u'10', element.items['max_items']) # not changed
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
166
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
167 self.assertEqual(NS_RSM, element.set.uri)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
168 self.assertEqual(u'1', ''.join(element.set.max.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
169 self.assertIdentical(None, element.set.after)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
170 self.assertIdentical(None, element.set.before)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
171 self.assertIdentical(None, element.set.index)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
172
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
173 def test_renderPubSub(self):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
174 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
175 Embed a page request in the pubsub element.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
176 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
177 element = domish.Element((pubsub.NS_PUBSUB, 'pubsub'))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
178 element.addElement('items')['max_items'] = u'10'
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
179 RSMRequest(3).render(element)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
180
1816
2a030a830ebd test (RSM): fix according to modification in sat.tmp.wokkel.rsm in rev 1771 (b77dc676a4df)
souliane <souliane@mailoo.org>
parents: 1815
diff changeset
181 self.assertEqual(u'10', element.items['max_items']) # not changed
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
182
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
183 self.assertEqual(NS_RSM, element.set.uri)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
184 self.assertEqual(u'3', ''.join(element.set.max.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
185 self.assertIdentical(None, element.set.after)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
186 self.assertIdentical(None, element.set.before)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
187 self.assertIdentical(None, element.set.index)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
188
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
189 def test_renderItems(self):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
190 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
191 Embed a page request in the element, specify items.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
192 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
193 element = domish.Element(('jabber:iq:search', 'query'))
1816
2a030a830ebd test (RSM): fix according to modification in sat.tmp.wokkel.rsm in rev 1771 (b77dc676a4df)
souliane <souliane@mailoo.org>
parents: 1815
diff changeset
194 RSMRequest(5, index=127).render(element)
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
195 self.assertEqual(NS_RSM, element.set.uri)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
196 self.assertEqual(u'5', ''.join(element.set.max.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
197 self.assertIdentical(None, element.set.after)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
198 self.assertIdentical(None, element.set.before)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
199 self.assertEqual(u'127', ''.join(element.set.index.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
200
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
201 def test_renderAfter(self):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
202 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
203 Embed a page request in the element, specify after.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
204 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
205 element = domish.Element(('jabber:iq:search', 'query'))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
206 RSMRequest(5, after=u'test').render(element)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
207 self.assertEqual(NS_RSM, element.set.uri)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
208 self.assertEqual(u'5', ''.join(element.set.max.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
209 self.assertEqual(u'test', ''.join(element.set.after.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
210 self.assertIdentical(None, element.set.before)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
211 self.assertIdentical(None, element.set.index)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
212
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
213 def test_renderBefore(self):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
214 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
215 Embed a page request in the element, specify before.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
216 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
217 element = domish.Element(('jabber:iq:search', 'query'))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
218 RSMRequest(5, before=u'test').render(element)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
219 self.assertEqual(NS_RSM, element.set.uri)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
220 self.assertEqual(u'5', ''.join(element.set.max.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
221 self.assertIdentical(None, element.set.after)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
222 self.assertEqual(u'test', ''.join(element.set.before.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
223 self.assertIdentical(None, element.set.index)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
224
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
225
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
226 class RSMResponseTest(unittest.TestCase):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
227 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
228 Tests for L{rsm.RSMResponse}.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
229 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
230
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
231 def test___init__(self):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
232 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
233 Fail to initialize a RSMResponse with wrong attribute values.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
234 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
235 self.assertRaises(AssertionError, RSMResponse, index=127, first=u'127')
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
236 self.assertRaises(AssertionError, RSMResponse, index=127, last=u'351')
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
237
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
238 def test_parse(self):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
239 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
240 Parse a response element returning a page.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
241 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
242 xml = """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
243 <query xmlns='jabber:iq:search'>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
244 <set xmlns='http://jabber.org/protocol/rsm'>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
245 <first index='20'>stpeter@jabber.org</first>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
246 <last>peterpan@neverland.lit</last>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
247 <count>800</count>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
248 </set>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
249 </query>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
250 """
1815
ec764bfb146d test (RSM): fix according to modification in sat.tmp.wokkel:
souliane <souliane@mailoo.org>
parents: 1438
diff changeset
251 response = RSMResponse.fromElement(parseXml(xml))
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
252 self.assertEqual(800, response.count)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
253 self.assertEqual(20, response.index)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
254 self.assertEqual(u'stpeter@jabber.org', response.first)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
255 self.assertEqual(u'peterpan@neverland.lit', response.last)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
256
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
257 def test_parseEmptySet(self):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
258 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
259 Parse a response element returning an empty set.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
260 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
261 xml = """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
262 <query xmlns='jabber:iq:search'>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
263 <set xmlns='http://jabber.org/protocol/rsm'>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
264 <count>800</count>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
265 </set>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
266 </query>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
267 """
1815
ec764bfb146d test (RSM): fix according to modification in sat.tmp.wokkel:
souliane <souliane@mailoo.org>
parents: 1438
diff changeset
268 response = RSMResponse.fromElement(parseXml(xml))
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
269 self.assertEqual(800, response.count)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
270 self.assertIdentical(None, response.first)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
271 self.assertIdentical(None, response.last)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
272 self.assertIdentical(None, response.index)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
273
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
274 def test_render(self):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
275 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
276 Embed a page response in the element.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
277 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
278 element = domish.Element(('jabber:iq:search', 'query'))
1816
2a030a830ebd test (RSM): fix according to modification in sat.tmp.wokkel.rsm in rev 1771 (b77dc676a4df)
souliane <souliane@mailoo.org>
parents: 1815
diff changeset
279 RSMResponse(u'stpeter@jabber.org', u'peterpan@neverland.lit', 20, 800).render(element)
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
280
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
281 self.assertEqual(NS_RSM, element.set.uri)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
282 self.assertEqual(u'800', ''.join(element.set.count.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
283 self.assertEqual(u'stpeter@jabber.org',
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
284 ''.join(element.set.first.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
285 self.assertEqual(u'peterpan@neverland.lit',
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
286 ''.join(element.set.last.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
287 self.assertEqual(u'20', element.set.first['index'])
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
288
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
289 def test_renderEmptySet(self):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
290 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
291 Embed a page response in the element, for empty set.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
292 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
293 element = domish.Element(('jabber:iq:search', 'query'))
1816
2a030a830ebd test (RSM): fix according to modification in sat.tmp.wokkel.rsm in rev 1771 (b77dc676a4df)
souliane <souliane@mailoo.org>
parents: 1815
diff changeset
294 RSMResponse(count=800).render(element)
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
295
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
296 self.assertEqual(NS_RSM, element.set.uri)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
297 self.assertEqual(u'800', ''.join(element.set.count.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
298 self.assertIdentical(None, element.set.first)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
299 self.assertIdentical(None, element.set.last)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
300
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
301
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
302 class PubSubClientTest(unittest.TestCase):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
303 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
304 Tests for L{rsm.PubSubClient}.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
305 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
306 timeout = 2
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
307
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
308 def setUp(self):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
309 self.stub = XmlStreamStub()
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
310 self.protocol = PubSubClient()
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
311 self.protocol.xmlstream = self.stub.xmlstream
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
312 self.protocol.connectionInitialized()
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
313
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
314 def test_items(self):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
315 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
316 Test sending items request to get the first page.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
317 """
1815
ec764bfb146d test (RSM): fix according to modification in sat.tmp.wokkel:
souliane <souliane@mailoo.org>
parents: 1438
diff changeset
318 def cb(response):
ec764bfb146d test (RSM): fix according to modification in sat.tmp.wokkel:
souliane <souliane@mailoo.org>
parents: 1438
diff changeset
319 items, rsm = response
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
320 self.assertEquals(2, len(items))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
321 self.assertEquals([item1, item2], items)
1816
2a030a830ebd test (RSM): fix according to modification in sat.tmp.wokkel.rsm in rev 1771 (b77dc676a4df)
souliane <souliane@mailoo.org>
parents: 1815
diff changeset
322 self.assertEquals(rsm, RSMResponse('item1', 'item2', 0, 800))
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
323
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
324 d = self.protocol.items(JID('pubsub.example.org'), 'test',
1815
ec764bfb146d test (RSM): fix according to modification in sat.tmp.wokkel:
souliane <souliane@mailoo.org>
parents: 1438
diff changeset
325 rsm_request=RSMRequest(2))
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
326 d.addCallback(cb)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
327
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
328 iq = self.stub.output[-1]
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
329 self.assertEquals('pubsub.example.org', iq.getAttribute('to'))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
330 self.assertEquals('get', iq.getAttribute('type'))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
331 self.assertEquals('pubsub', iq.pubsub.name)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
332 self.assertEquals(pubsub.NS_PUBSUB, iq.pubsub.uri)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
333 children = list(domish.generateElementsQNamed(iq.pubsub.children,
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
334 'items', pubsub.NS_PUBSUB))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
335 self.assertEquals(1, len(children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
336 child = children[0]
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
337 self.assertEquals('test', child['node'])
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
338
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
339 set_elts = list(domish.generateElementsQNamed(iq.pubsub.children,
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
340 'set', NS_RSM))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
341 self.assertEquals(1, len(set_elts))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
342 set_elt = set_elts[0]
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
343 self.assertEquals(u'2', ''.join(set_elt.max.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
344
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
345 response = toResponse(iq, 'result')
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
346 items = response.addElement((pubsub.NS_PUBSUB,
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
347 'pubsub')).addElement('items')
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
348 items['node'] = 'test'
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
349 item1 = items.addElement('item')
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
350 item1['id'] = 'item1'
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
351 item2 = items.addElement('item')
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
352 item2['id'] = 'item2'
1816
2a030a830ebd test (RSM): fix according to modification in sat.tmp.wokkel.rsm in rev 1771 (b77dc676a4df)
souliane <souliane@mailoo.org>
parents: 1815
diff changeset
353 RSMResponse(u'item1', u'item2', 0, 800).render(response.pubsub)
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
354 self.stub.send(response)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
355
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
356 return d
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
357
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
358 def test_itemsAfter(self):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
359 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
360 Test sending items request to get the next page.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
361 """
1815
ec764bfb146d test (RSM): fix according to modification in sat.tmp.wokkel:
souliane <souliane@mailoo.org>
parents: 1438
diff changeset
362 def cb(response):
ec764bfb146d test (RSM): fix according to modification in sat.tmp.wokkel:
souliane <souliane@mailoo.org>
parents: 1438
diff changeset
363 items, rsm = response
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
364 self.assertEquals(2, len(items))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
365 self.assertEquals([item1, item2], items)
1816
2a030a830ebd test (RSM): fix according to modification in sat.tmp.wokkel.rsm in rev 1771 (b77dc676a4df)
souliane <souliane@mailoo.org>
parents: 1815
diff changeset
366 self.assertEquals(rsm, RSMResponse('item3', 'item4', 2, 800))
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
367
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
368 d = self.protocol.items(JID('pubsub.example.org'), 'test',
1815
ec764bfb146d test (RSM): fix according to modification in sat.tmp.wokkel:
souliane <souliane@mailoo.org>
parents: 1438
diff changeset
369 rsm_request=RSMRequest(2, after=u'item2'))
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
370 d.addCallback(cb)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
371
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
372 iq = self.stub.output[-1]
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
373 self.assertEquals('pubsub.example.org', iq.getAttribute('to'))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
374 self.assertEquals('get', iq.getAttribute('type'))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
375 self.assertEquals('pubsub', iq.pubsub.name)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
376 self.assertEquals(pubsub.NS_PUBSUB, iq.pubsub.uri)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
377 children = list(domish.generateElementsQNamed(iq.pubsub.children,
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
378 'items', pubsub.NS_PUBSUB))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
379 self.assertEquals(1, len(children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
380 child = children[0]
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
381 self.assertEquals('test', child['node'])
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
382
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
383 set_elts = list(domish.generateElementsQNamed(iq.pubsub.children,
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
384 'set', NS_RSM))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
385 self.assertEquals(1, len(set_elts))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
386 set_elt = set_elts[0]
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
387 self.assertEquals(u'2', ''.join(set_elt.max.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
388 self.assertEquals(u'item2', ''.join(set_elt.after.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
389
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
390 response = toResponse(iq, 'result')
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
391 items = response.addElement((pubsub.NS_PUBSUB,
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
392 'pubsub')).addElement('items')
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
393 items['node'] = 'test'
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
394 item1 = items.addElement('item')
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
395 item1['id'] = 'item3'
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
396 item2 = items.addElement('item')
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
397 item2['id'] = 'item4'
1816
2a030a830ebd test (RSM): fix according to modification in sat.tmp.wokkel.rsm in rev 1771 (b77dc676a4df)
souliane <souliane@mailoo.org>
parents: 1815
diff changeset
398 RSMResponse(u'item3', u'item4', 2, 800).render(response.pubsub)
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
399 self.stub.send(response)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
400
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
401 return d
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
402
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
403 def test_itemsBefore(self):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
404 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
405 Test sending items request to get the previous page.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
406 """
1815
ec764bfb146d test (RSM): fix according to modification in sat.tmp.wokkel:
souliane <souliane@mailoo.org>
parents: 1438
diff changeset
407 def cb(response):
ec764bfb146d test (RSM): fix according to modification in sat.tmp.wokkel:
souliane <souliane@mailoo.org>
parents: 1438
diff changeset
408 items, rsm = response
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
409 self.assertEquals(2, len(items))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
410 self.assertEquals([item1, item2], items)
1816
2a030a830ebd test (RSM): fix according to modification in sat.tmp.wokkel.rsm in rev 1771 (b77dc676a4df)
souliane <souliane@mailoo.org>
parents: 1815
diff changeset
411 self.assertEquals(rsm, RSMResponse('item1', 'item2', 0, 800))
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
412
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
413 d = self.protocol.items(JID('pubsub.example.org'), 'test',
1815
ec764bfb146d test (RSM): fix according to modification in sat.tmp.wokkel:
souliane <souliane@mailoo.org>
parents: 1438
diff changeset
414 rsm_request=RSMRequest(2, before=u'item3'))
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
415 d.addCallback(cb)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
416
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
417 iq = self.stub.output[-1]
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
418 self.assertEquals('pubsub.example.org', iq.getAttribute('to'))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
419 self.assertEquals('get', iq.getAttribute('type'))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
420 self.assertEquals('pubsub', iq.pubsub.name)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
421 self.assertEquals(pubsub.NS_PUBSUB, iq.pubsub.uri)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
422 children = list(domish.generateElementsQNamed(iq.pubsub.children,
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
423 'items', pubsub.NS_PUBSUB))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
424 self.assertEquals(1, len(children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
425 child = children[0]
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
426 self.assertEquals('test', child['node'])
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
427
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
428 set_elts = list(domish.generateElementsQNamed(iq.pubsub.children,
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
429 'set', NS_RSM))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
430 self.assertEquals(1, len(set_elts))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
431 set_elt = set_elts[0]
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
432 self.assertEquals(u'2', ''.join(set_elt.max.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
433 self.assertEquals(u'item3', ''.join(set_elt.before.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
434
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
435 response = toResponse(iq, 'result')
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
436 items = response.addElement((pubsub.NS_PUBSUB,
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
437 'pubsub')).addElement('items')
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
438 items['node'] = 'test'
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
439 item1 = items.addElement('item')
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
440 item1['id'] = 'item1'
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
441 item2 = items.addElement('item')
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
442 item2['id'] = 'item2'
1816
2a030a830ebd test (RSM): fix according to modification in sat.tmp.wokkel.rsm in rev 1771 (b77dc676a4df)
souliane <souliane@mailoo.org>
parents: 1815
diff changeset
443 RSMResponse(u'item1', u'item2', 0, 800).render(response.pubsub)
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
444 self.stub.send(response)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
445
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
446 return d
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
447
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
448 def test_itemsIndex(self):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
449 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
450 Test sending items request to get a page out of order.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
451 """
1815
ec764bfb146d test (RSM): fix according to modification in sat.tmp.wokkel:
souliane <souliane@mailoo.org>
parents: 1438
diff changeset
452 def cb(response):
ec764bfb146d test (RSM): fix according to modification in sat.tmp.wokkel:
souliane <souliane@mailoo.org>
parents: 1438
diff changeset
453 items, rsm = response
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
454 self.assertEquals(3, len(items))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
455 self.assertEquals([item1, item2, item3], items)
1816
2a030a830ebd test (RSM): fix according to modification in sat.tmp.wokkel.rsm in rev 1771 (b77dc676a4df)
souliane <souliane@mailoo.org>
parents: 1815
diff changeset
456 self.assertEquals(rsm, RSMResponse('item4', 'item6', 3, 800))
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
457
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
458 d = self.protocol.items(JID('pubsub.example.org'), 'test',
1816
2a030a830ebd test (RSM): fix according to modification in sat.tmp.wokkel.rsm in rev 1771 (b77dc676a4df)
souliane <souliane@mailoo.org>
parents: 1815
diff changeset
459 rsm_request=RSMRequest(3, index=3))
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
460 d.addCallback(cb)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
461
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
462 iq = self.stub.output[-1]
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
463 self.assertEquals('pubsub.example.org', iq.getAttribute('to'))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
464 self.assertEquals('get', iq.getAttribute('type'))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
465 self.assertEquals('pubsub', iq.pubsub.name)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
466 self.assertEquals(pubsub.NS_PUBSUB, iq.pubsub.uri)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
467 children = list(domish.generateElementsQNamed(iq.pubsub.children,
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
468 'items', pubsub.NS_PUBSUB))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
469 self.assertEquals(1, len(children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
470 child = children[0]
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
471 self.assertEquals('test', child['node'])
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
472
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
473 set_elts = list(domish.generateElementsQNamed(iq.pubsub.children,
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
474 'set', NS_RSM))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
475 self.assertEquals(1, len(set_elts))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
476 set_elt = set_elts[0]
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
477 self.assertEquals(u'3', ''.join(set_elt.max.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
478 self.assertEquals(u'3', ''.join(set_elt.index.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
479
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
480 response = toResponse(iq, 'result')
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
481 items = response.addElement((pubsub.NS_PUBSUB,
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
482 'pubsub')).addElement('items')
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
483 items['node'] = 'test'
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
484 item1 = items.addElement('item')
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
485 item1['id'] = 'item4'
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
486 item2 = items.addElement('item')
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
487 item2['id'] = 'item5'
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
488 item3 = items.addElement('item')
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
489 item3['id'] = 'item6'
1816
2a030a830ebd test (RSM): fix according to modification in sat.tmp.wokkel.rsm in rev 1771 (b77dc676a4df)
souliane <souliane@mailoo.org>
parents: 1815
diff changeset
490 RSMResponse(u'item4', u'item6', 3, 800).render(response.pubsub)
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
491 self.stub.send(response)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
492
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
493 return d
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
494
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
495 def test_itemsCount(self):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
496 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
497 Test sending items request to count them.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
498 """
1815
ec764bfb146d test (RSM): fix according to modification in sat.tmp.wokkel:
souliane <souliane@mailoo.org>
parents: 1438
diff changeset
499 def cb(response):
ec764bfb146d test (RSM): fix according to modification in sat.tmp.wokkel:
souliane <souliane@mailoo.org>
parents: 1438
diff changeset
500 items, rsm = response
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
501 self.assertEquals(0, len(items))
1816
2a030a830ebd test (RSM): fix according to modification in sat.tmp.wokkel.rsm in rev 1771 (b77dc676a4df)
souliane <souliane@mailoo.org>
parents: 1815
diff changeset
502 self.assertEquals(rsm, RSMResponse(count=800))
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
503
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
504 d = self.protocol.items(JID('pubsub.example.org'), 'test',
1815
ec764bfb146d test (RSM): fix according to modification in sat.tmp.wokkel:
souliane <souliane@mailoo.org>
parents: 1438
diff changeset
505 rsm_request=RSMRequest(0))
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
506 d.addCallback(cb)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
507
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
508 iq = self.stub.output[-1]
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
509 self.assertEquals('pubsub.example.org', iq.getAttribute('to'))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
510 self.assertEquals('get', iq.getAttribute('type'))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
511 self.assertEquals('pubsub', iq.pubsub.name)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
512 self.assertEquals(pubsub.NS_PUBSUB, iq.pubsub.uri)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
513 children = list(domish.generateElementsQNamed(iq.pubsub.children,
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
514 'items', pubsub.NS_PUBSUB))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
515 self.assertEquals(1, len(children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
516 child = children[0]
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
517 self.assertEquals('test', child['node'])
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
518
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
519 set_elts = list(domish.generateElementsQNamed(iq.pubsub.children,
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
520 'set', NS_RSM))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
521 self.assertEquals(1, len(set_elts))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
522 set_elt = set_elts[0]
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
523 self.assertEquals(u'0', ''.join(set_elt.max.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
524
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
525 response = toResponse(iq, 'result')
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
526 response.addElement((pubsub.NS_PUBSUB, 'pubsub'))
1816
2a030a830ebd test (RSM): fix according to modification in sat.tmp.wokkel.rsm in rev 1771 (b77dc676a4df)
souliane <souliane@mailoo.org>
parents: 1815
diff changeset
527 RSMResponse(count=800).render(response.pubsub)
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
528 self.stub.send(response)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
529
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
530 return d
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
531
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
532
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
533 class PubSubServiceTest(unittest.TestCase, TestableRequestHandlerMixin):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
534
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
535 def setUp(self):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
536 self.stub = XmlStreamStub()
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
537 self.resource = pubsub.PubSubResource()
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
538 self.service = PubSubService(self.resource)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
539 self.service.send = self.stub.xmlstream.send
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
540
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
541 def test_on_items(self):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
542 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
543 On a items request, return the first item for the given node.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
544 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
545 xml = """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
546 <iq type='get' to='pubsub.example.org'
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
547 from='user@example.org'>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
548 <pubsub xmlns='http://jabber.org/protocol/pubsub'>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
549 <items node='test'/>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
550 </pubsub>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
551 <set xmlns='http://jabber.org/protocol/rsm'>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
552 <max>1</max>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
553 </set>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
554 </iq>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
555 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
556
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
557 def items(request):
1816
2a030a830ebd test (RSM): fix according to modification in sat.tmp.wokkel.rsm in rev 1771 (b77dc676a4df)
souliane <souliane@mailoo.org>
parents: 1815
diff changeset
558 rsm = RSMResponse(u'item', u'item', 0, 800).toElement()
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
559 return defer.succeed([pubsub.Item('current'), rsm])
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
560
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
561 def cb(element):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
562 self.assertEqual(pubsub.NS_PUBSUB, element.uri)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
563 self.assertEqual(pubsub.NS_PUBSUB, element.items.uri)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
564 self.assertEqual(1, len(element.items.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
565 item = element.items.children[-1]
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
566 self.assertTrue(domish.IElement.providedBy(item))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
567 self.assertEqual('item', item.name)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
568 self.assertEqual(pubsub.NS_PUBSUB, item.uri)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
569 self.assertEqual('current', item['id'])
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
570 self.assertEqual(NS_RSM, element.set.uri)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
571 self.assertEqual('800', ''.join(element.set.count.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
572 self.assertEqual('0', element.set.first['index'])
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
573 self.assertEqual('item', ''.join(element.set.first.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
574 self.assertEqual('item', ''.join(element.set.last.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
575
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
576 self.resource.items = items
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
577 verify.verifyObject(iwokkel.IPubSubResource, self.resource)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
578 d = self.handleRequest(xml)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
579 d.addCallback(cb)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
580 return d
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
581
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
582 def test_on_itemsIndex(self):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
583 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
584 On a items request, return some items out of order for the given node.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
585 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
586 xml = """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
587 <iq type='get' to='pubsub.example.org'
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
588 from='user@example.org'>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
589 <pubsub xmlns='http://jabber.org/protocol/pubsub'>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
590 <items node='test'/>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
591 </pubsub>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
592 <set xmlns='http://jabber.org/protocol/rsm'>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
593 <max>2</max>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
594 <index>3</index>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
595 </set>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
596 </iq>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
597 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
598
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
599 def items(request):
1816
2a030a830ebd test (RSM): fix according to modification in sat.tmp.wokkel.rsm in rev 1771 (b77dc676a4df)
souliane <souliane@mailoo.org>
parents: 1815
diff changeset
600 rsm = RSMResponse(u'i1', u'i2', 3, 800).toElement()
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
601 return defer.succeed([pubsub.Item('i1'), pubsub.Item('i2'), rsm])
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
602
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
603 def cb(element):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
604 self.assertEqual(pubsub.NS_PUBSUB, element.uri)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
605 self.assertEqual(pubsub.NS_PUBSUB, element.items.uri)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
606 self.assertEqual(2, len(element.items.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
607 item = element.items.children[0]
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
608 self.assertTrue(domish.IElement.providedBy(item))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
609 self.assertEqual('item', item.name)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
610 self.assertEqual(pubsub.NS_PUBSUB, item.uri)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
611 self.assertEqual('i1', item['id'])
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
612 item = element.items.children[1]
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
613 self.assertTrue(domish.IElement.providedBy(item))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
614 self.assertEqual('item', item.name)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
615 self.assertEqual(pubsub.NS_PUBSUB, item.uri)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
616 self.assertEqual('i2', item['id'])
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
617 self.assertEqual(NS_RSM, element.set.uri)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
618 self.assertEqual('800', ''.join(element.set.count.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
619 self.assertEqual('3', element.set.first['index'])
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
620 self.assertEqual('i1', ''.join(element.set.first.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
621 self.assertEqual('i2', ''.join(element.set.last.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
622
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
623 self.resource.items = items
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
624 verify.verifyObject(iwokkel.IPubSubResource, self.resource)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
625 d = self.handleRequest(xml)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
626 d.addCallback(cb)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
627 return d
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
628
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
629 def test_on_itemsCount(self):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
630 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
631 On a items request, return the items count.
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
632 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
633 xml = """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
634 <iq type='get' to='pubsub.example.org'
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
635 from='user@example.org'>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
636 <pubsub xmlns='http://jabber.org/protocol/pubsub'>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
637 <items node='test'/>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
638 </pubsub>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
639 <set xmlns='http://jabber.org/protocol/rsm'>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
640 <max>0</max>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
641 </set>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
642 </iq>
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
643 """
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
644
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
645 def items(request):
1816
2a030a830ebd test (RSM): fix according to modification in sat.tmp.wokkel.rsm in rev 1771 (b77dc676a4df)
souliane <souliane@mailoo.org>
parents: 1815
diff changeset
646 rsm = RSMResponse(count=800).toElement()
1438
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
647 return defer.succeed([rsm])
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
648
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
649 def cb(element):
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
650 self.assertEqual(pubsub.NS_PUBSUB, element.uri)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
651 self.assertEqual(pubsub.NS_PUBSUB, element.items.uri)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
652 self.assertEqual(0, len(element.items.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
653 self.assertEqual(NS_RSM, element.set.uri)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
654 self.assertEqual('800', ''.join(element.set.count.children))
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
655 self.assertEqual(None, element.set.first)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
656 self.assertEqual(None, element.set.last)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
657
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
658 self.resource.items = items
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
659 verify.verifyObject(iwokkel.IPubSubResource, self.resource)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
660 d = self.handleRequest(xml)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
661 d.addCallback(cb)
0fb5785b4c63 add tests for sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
diff changeset
662 return d