annotate wokkel/test/test_rsm.py @ 25:4816f7d55367

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