annotate wokkel/test/test_rsm.py @ 43:78dd28b06fb0

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