annotate sat_pubsub/test/test_backend.py @ 476:1092bab8b3f3

doc: update names following global renaming
author Goffi <goffi@goffi.org>
date Mon, 03 Jan 2022 16:45:55 +0100
parents 074037832daf
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
233
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
1 #!/usr/bin/python
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
2 #-*- coding: utf-8 -*-
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
3
312
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
4 # Copyright (c) 2003-2011 Ralph Meijer
440
074037832daf dates update
Goffi <goffi@goffi.org>
parents: 414
diff changeset
5 # Copyright (c) 2012-2021 Jérôme Poisson
233
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
6
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
7
312
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
8 # This program is free software: you can redistribute it and/or modify
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
9 # it under the terms of the GNU Affero General Public License as published by
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
10 # the Free Software Foundation, either version 3 of the License, or
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
11 # (at your option) any later version.
233
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
12
312
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
13 # This program is distributed in the hope that it will be useful,
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
16 # GNU Affero General Public License for more details.
233
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
17
312
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
18 # You should have received a copy of the GNU Affero General Public License
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
20 # --
233
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
21
312
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
22 # This program is based on Idavoll (http://idavoll.ik.nu/),
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
23 # originaly written by Ralph Meijer (http://ralphm.net/blog/)
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
24 # It is sublicensed under AGPL v3 (or any later version) as allowed by the original
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
25 # license.
233
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
26
312
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
27 # --
233
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
28
312
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
29 # Here is a copy of the original license:
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
30
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
31 # Copyright (c) 2003-2011 Ralph Meijer
233
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
32
312
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
33 # Permission is hereby granted, free of charge, to any person obtaining
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
34 # a copy of this software and associated documentation files (the
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
35 # "Software"), to deal in the Software without restriction, including
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
36 # without limitation the rights to use, copy, modify, merge, publish,
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
37 # distribute, sublicense, and/or sell copies of the Software, and to
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
38 # permit persons to whom the Software is furnished to do so, subject to
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
39 # the following conditions:
233
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
40
312
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
41 # The above copyright notice and this permission notice shall be
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
42 # included in all copies or substantial portions of the Software.
233
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
43
312
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
44 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
45 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
46 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
47 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
48 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
49 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
5d7c3787672e fixed copyright put in docstring instead of comments
Goffi <goffi@goffi.org>
parents: 311
diff changeset
50 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
233
564ae55219e1 sublicensed under AGPL V3
Goffi <goffi@goffi.org>
parents: 232
diff changeset
51
155
5191ba7c4df8 Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents: 143
diff changeset
52
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 157
diff changeset
53 """
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 157
diff changeset
54 Tests for L{idavoll.backend}.
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 157
diff changeset
55 """
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 157
diff changeset
56
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
57 from zope.interface import implements
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
58 from zope.interface.verify import verifyObject
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
59
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
60 from twisted.internet import defer
143
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
61 from twisted.trial import unittest
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
62 from twisted.words.protocols.jabber import jid
171
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
63 from twisted.words.protocols.jabber.error import StanzaError
143
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
64
209
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
65 from wokkel import iwokkel, pubsub
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
66
266
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
67 from sat_pubsub import backend, error, iidavoll, const
143
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
68
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
69 OWNER = jid.JID('owner@example.com')
220
e59b48f3f636 Add tests for subscription and unsubscription JID checks in [53d2c0019458].
Ralph Meijer <ralphm@ik.nu>
parents: 211
diff changeset
70 OWNER_FULL = jid.JID('owner@example.com/home')
209
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
71 SERVICE = jid.JID('test.example.org')
178
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
72 NS_PUBSUB = 'http://jabber.org/protocol/pubsub'
143
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
73
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
74 class BackendTest(unittest.TestCase):
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
75
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
76 def test_interfaceIBackend(self):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
77 self.assertTrue(verifyObject(iidavoll.IBackendService,
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
78 backend.BackendService(None)))
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
79
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
80
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
81 def test_deleteNode(self):
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
82 class TestNode:
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
83 nodeIdentifier = 'to-be-deleted'
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
84 def getAffiliation(self, entity):
220
e59b48f3f636 Add tests for subscription and unsubscription JID checks in [53d2c0019458].
Ralph Meijer <ralphm@ik.nu>
parents: 211
diff changeset
85 if entity.userhostJID() == OWNER:
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
86 return defer.succeed('owner')
143
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
87
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
88 class TestStorage:
209
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
89 def __init__(self):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
90 self.deleteCalled = []
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
91
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
92 def getNode(self, nodeIdentifier):
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
93 return defer.succeed(TestNode())
143
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
94
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
95 def deleteNode(self, nodeIdentifier):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
96 if nodeIdentifier in ['to-be-deleted']:
209
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
97 self.deleteCalled.append(nodeIdentifier)
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
98 return defer.succeed(None)
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
99 else:
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
100 return defer.fail(error.NodeNotFound())
143
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
101
209
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
102 def preDelete(data):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
103 self.assertFalse(self.storage.deleteCalled)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
104 preDeleteCalled.append(data)
143
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
105 return defer.succeed(None)
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
106
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
107 def cb(result):
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
108 self.assertEqual(1, len(preDeleteCalled))
209
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
109 data = preDeleteCalled[-1]
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
110 self.assertEqual('to-be-deleted', data['node'].nodeIdentifier)
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
111 self.assertTrue(self.storage.deleteCalled)
143
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
112
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
113 self.storage = TestStorage()
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
114 self.backend = backend.BackendService(self.storage)
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
115
209
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
116 preDeleteCalled = []
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
117
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
118 self.backend.registerPreDelete(preDelete)
220
e59b48f3f636 Add tests for subscription and unsubscription JID checks in [53d2c0019458].
Ralph Meijer <ralphm@ik.nu>
parents: 211
diff changeset
119 d = self.backend.deleteNode('to-be-deleted', OWNER_FULL)
143
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
120 d.addCallback(cb)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 157
diff changeset
121 return d
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
122
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
123
209
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
124 def test_deleteNodeRedirect(self):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
125 uri = 'xmpp:%s?;node=test2' % (SERVICE.full(),)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
126
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
127 class TestNode:
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
128 nodeIdentifier = 'to-be-deleted'
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
129 def getAffiliation(self, entity):
220
e59b48f3f636 Add tests for subscription and unsubscription JID checks in [53d2c0019458].
Ralph Meijer <ralphm@ik.nu>
parents: 211
diff changeset
130 if entity.userhostJID() == OWNER:
209
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
131 return defer.succeed('owner')
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
132
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
133 class TestStorage:
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
134 def __init__(self):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
135 self.deleteCalled = []
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
136
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
137 def getNode(self, nodeIdentifier):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
138 return defer.succeed(TestNode())
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
139
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
140 def deleteNode(self, nodeIdentifier):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
141 if nodeIdentifier in ['to-be-deleted']:
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
142 self.deleteCalled.append(nodeIdentifier)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
143 return defer.succeed(None)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
144 else:
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
145 return defer.fail(error.NodeNotFound())
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
146
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
147 def preDelete(data):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
148 self.assertFalse(self.storage.deleteCalled)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
149 preDeleteCalled.append(data)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
150 return defer.succeed(None)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
151
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
152 def cb(result):
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
153 self.assertEqual(1, len(preDeleteCalled))
209
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
154 data = preDeleteCalled[-1]
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
155 self.assertEqual('to-be-deleted', data['node'].nodeIdentifier)
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
156 self.assertEqual(uri, data['redirectURI'])
209
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
157 self.assertTrue(self.storage.deleteCalled)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
158
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
159 self.storage = TestStorage()
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
160 self.backend = backend.BackendService(self.storage)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
161
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
162 preDeleteCalled = []
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
163
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
164 self.backend.registerPreDelete(preDelete)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
165 d = self.backend.deleteNode('to-be-deleted', OWNER, redirectURI=uri)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
166 d.addCallback(cb)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
167 return d
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
168
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
169
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
170 def test_createNodeNoID(self):
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
171 """
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
172 Test creation of a node without a given node identifier.
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
173 """
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
174 class TestStorage:
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
175 def getDefaultConfiguration(self, nodeType):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
176 return {}
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
177
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
178 def createNode(self, nodeIdentifier, requestor, config):
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
179 self.nodeIdentifier = nodeIdentifier
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
180 return defer.succeed(None)
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
181
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
182 self.storage = TestStorage()
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
183 self.backend = backend.BackendService(self.storage)
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
184 self.storage.backend = self.backend
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
185
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
186 def checkID(nodeIdentifier):
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
187 self.assertNotIdentical(None, nodeIdentifier)
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
188 self.assertIdentical(self.storage.nodeIdentifier, nodeIdentifier)
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
189
220
e59b48f3f636 Add tests for subscription and unsubscription JID checks in [53d2c0019458].
Ralph Meijer <ralphm@ik.nu>
parents: 211
diff changeset
190 d = self.backend.createNode(None, OWNER_FULL)
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
191 d.addCallback(checkID)
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
192 return d
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
193
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
194 class NodeStore:
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
195 """
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
196 I just store nodes to pose as an L{IStorage} implementation.
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
197 """
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
198 def __init__(self, nodes):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
199 self.nodes = nodes
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
200
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
201 def getNode(self, nodeIdentifier):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
202 try:
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
203 return defer.succeed(self.nodes[nodeIdentifier])
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
204 except KeyError:
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
205 return defer.fail(error.NodeNotFound())
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
207
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
208 def test_getNotifications(self):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
209 """
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
210 Ensure subscribers show up in the notification list.
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
211 """
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
212 item = pubsub.Item()
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
213 sub = pubsub.Subscription('test', OWNER, 'subscribed')
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
214
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
215 class TestNode:
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
216 def getSubscriptions(self, state=None):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
217 return [sub]
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
218
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
219 def cb(result):
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
220 self.assertEqual(1, len(result))
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
221 subscriber, subscriptions, items = result[-1]
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
222
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
223 self.assertEqual(OWNER, subscriber)
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
224 self.assertEqual({sub}, subscriptions)
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
225 self.assertEqual([item], items)
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
226
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
227 self.storage = self.NodeStore({'test': TestNode()})
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
228 self.backend = backend.BackendService(self.storage)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
229 d = self.backend.getNotifications('test', [item])
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
230 d.addCallback(cb)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
231 return d
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
232
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
233 def test_getNotificationsRoot(self):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
234 """
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
235 Ensure subscribers to the root node show up in the notification list
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
236 for leaf nodes.
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
237
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
238 This assumes a flat node relationship model with exactly one collection
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
239 node: the root node. Each leaf node is automatically a child node
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
240 of the root node.
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
241 """
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
242 item = pubsub.Item()
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
243 subRoot = pubsub.Subscription('', OWNER, 'subscribed')
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
244
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
245 class TestNode:
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
246 def getSubscriptions(self, state=None):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
247 return []
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
248
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
249 class TestRootNode:
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
250 def getSubscriptions(self, state=None):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
251 return [subRoot]
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
252
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
253 def cb(result):
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
254 self.assertEqual(1, len(result))
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
255 subscriber, subscriptions, items = result[-1]
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
256 self.assertEqual(OWNER, subscriber)
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
257 self.assertEqual({subRoot}, subscriptions)
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
258 self.assertEqual([item], items)
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
259
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
260 self.storage = self.NodeStore({'test': TestNode(),
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
261 '': TestRootNode()})
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
262 self.backend = backend.BackendService(self.storage)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
263 d = self.backend.getNotifications('test', [item])
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
264 d.addCallback(cb)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
265 return d
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
266
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
267
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
268 def test_getNotificationsMultipleNodes(self):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
269 """
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
270 Ensure that entities that subscribe to a leaf node as well as the
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
271 root node get exactly one notification.
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
272 """
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
273 item = pubsub.Item()
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
274 sub = pubsub.Subscription('test', OWNER, 'subscribed')
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
275 subRoot = pubsub.Subscription('', OWNER, 'subscribed')
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
276
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
277 class TestNode:
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
278 def getSubscriptions(self, state=None):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
279 return [sub]
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
280
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
281 class TestRootNode:
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
282 def getSubscriptions(self, state=None):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
283 return [subRoot]
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
284
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
285 def cb(result):
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
286 self.assertEqual(1, len(result))
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
287 subscriber, subscriptions, items = result[-1]
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
288
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
289 self.assertEqual(OWNER, subscriber)
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
290 self.assertEqual({sub, subRoot}, subscriptions)
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
291 self.assertEqual([item], items)
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
292
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
293 self.storage = self.NodeStore({'test': TestNode(),
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
294 '': TestRootNode()})
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
295 self.backend = backend.BackendService(self.storage)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
296 d = self.backend.getNotifications('test', [item])
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
297 d.addCallback(cb)
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
298 return d
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
299
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
300
205
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
301 def test_getDefaultConfiguration(self):
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
302 """
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
303 L{backend.BackendService.getDefaultConfiguration} should return
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
304 a deferred that fires a dictionary with configuration values.
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
305 """
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
306
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
307 class TestStorage:
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
308 def getDefaultConfiguration(self, nodeType):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
309 return {
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
310 "pubsub#persist_items": True,
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
311 "pubsub#deliver_payloads": True}
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
312
205
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
313 def cb(options):
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
314 self.assertIn("pubsub#persist_items", options)
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
315 self.assertEqual(True, options["pubsub#persist_items"])
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
316
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
317 self.backend = backend.BackendService(TestStorage())
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
318 d = self.backend.getDefaultConfiguration('leaf')
205
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
319 d.addCallback(cb)
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
320 return d
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
321
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
322
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
323 def test_getNodeConfiguration(self):
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
324 class testNode:
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
325 nodeIdentifier = 'node'
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
326 def getConfiguration(self):
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
327 return {'pubsub#deliver_payloads': True,
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
328 'pubsub#persist_items': False}
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
329
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
330 class testStorage:
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
331 def getNode(self, nodeIdentifier):
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
332 return defer.succeed(testNode())
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
333
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
334 def cb(options):
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
335 self.assertIn("pubsub#deliver_payloads", options)
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
336 self.assertEqual(True, options["pubsub#deliver_payloads"])
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
337 self.assertIn("pubsub#persist_items", options)
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
338 self.assertEqual(False, options["pubsub#persist_items"])
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
339
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
340 self.storage = testStorage()
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
341 self.backend = backend.BackendService(self.storage)
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
342 self.storage.backend = self.backend
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
343
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
344 d = self.backend.getNodeConfiguration('node')
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
345 d.addCallback(cb)
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
346 return d
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
347
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
348
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
349 def test_setNodeConfiguration(self):
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
350 class testNode:
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
351 nodeIdentifier = 'node'
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
352 def getAffiliation(self, entity):
220
e59b48f3f636 Add tests for subscription and unsubscription JID checks in [53d2c0019458].
Ralph Meijer <ralphm@ik.nu>
parents: 211
diff changeset
353 if entity.userhostJID() == OWNER:
205
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
354 return defer.succeed('owner')
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
355 def setConfiguration(self, options):
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
356 self.options = options
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
357
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
358 class testStorage:
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
359 def __init__(self):
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
360 self.nodes = {'node': testNode()}
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
361 def getNode(self, nodeIdentifier):
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
362 return defer.succeed(self.nodes[nodeIdentifier])
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
363
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
364 def checkOptions(node):
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
365 options = node.options
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
366 self.assertIn("pubsub#deliver_payloads", options)
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
367 self.assertEqual(True, options["pubsub#deliver_payloads"])
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
368 self.assertIn("pubsub#persist_items", options)
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
369 self.assertEqual(False, options["pubsub#persist_items"])
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
370
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
371 def cb(result):
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
372 d = self.storage.getNode('node')
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
373 d.addCallback(checkOptions)
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
374 return d
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
375
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
376 self.storage = testStorage()
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
377 self.backend = backend.BackendService(self.storage)
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
378 self.storage.backend = self.backend
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
379
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
380 options = {'pubsub#deliver_payloads': True,
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
381 'pubsub#persist_items': False}
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
382
220
e59b48f3f636 Add tests for subscription and unsubscription JID checks in [53d2c0019458].
Ralph Meijer <ralphm@ik.nu>
parents: 211
diff changeset
383 d = self.backend.setNodeConfiguration('node', options, OWNER_FULL)
205
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
384 d.addCallback(cb)
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
385 return d
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
386
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
387
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
388 def test_publishNoID(self):
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
389 """
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
390 Test publish request with an item without a node identifier.
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
391 """
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
392 class TestNode:
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
393 nodeType = 'leaf'
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
394 nodeIdentifier = 'node'
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
395 def getAffiliation(self, entity):
220
e59b48f3f636 Add tests for subscription and unsubscription JID checks in [53d2c0019458].
Ralph Meijer <ralphm@ik.nu>
parents: 211
diff changeset
396 if entity.userhostJID() == OWNER:
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
397 return defer.succeed('owner')
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
398 def getConfiguration(self):
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
399 return {'pubsub#deliver_payloads': True,
266
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
400 'pubsub#persist_items': False,
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
401 const.OPT_PUBLISH_MODEL: const.VAL_PMODEL_OPEN}
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
402
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
403 class TestStorage:
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
404 def getNode(self, nodeIdentifier):
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
405 return defer.succeed(TestNode())
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
406
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
407 def checkID(notification):
266
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
408 self.assertNotIdentical(None, notification['items'][0][2]['id'])
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
409
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
410 self.storage = TestStorage()
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
411 self.backend = backend.BackendService(self.storage)
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
412 self.storage.backend = self.backend
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
413
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
414 self.backend.registerNotifier(checkID)
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
415
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
416 items = [pubsub.Item()]
220
e59b48f3f636 Add tests for subscription and unsubscription JID checks in [53d2c0019458].
Ralph Meijer <ralphm@ik.nu>
parents: 211
diff changeset
417 d = self.backend.publish('node', items, OWNER_FULL)
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
418 return d
171
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
419
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
420
178
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
421 def test_notifyOnSubscription(self):
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
422 """
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
423 Test notification of last published item on subscription.
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
424 """
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
425 ITEM = "<item xmlns='%s' id='1'/>" % NS_PUBSUB
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
426
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
427 class TestNode:
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
428 implements(iidavoll.ILeafNode)
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
429 nodeIdentifier = 'node'
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
430 nodeType = 'leaf'
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
431 def getAffiliation(self, entity):
178
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
432 if entity is OWNER:
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
433 return defer.succeed('owner')
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
434 def getConfiguration(self):
178
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
435 return {'pubsub#deliver_payloads': True,
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
436 'pubsub#persist_items': False,
266
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
437 'pubsub#send_last_published_item': 'on_sub',
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
438 const.OPT_ACCESS_MODEL: const.VAL_AMODEL_OPEN}
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
439 def getItems(self, authorized_groups, unrestricted, maxItems):
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
440 return defer.succeed([(ITEM, const.VAL_AMODEL_OPEN, None)])
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
441 def addSubscription(self, subscriber, state, options):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
442 self.subscription = pubsub.Subscription('node', subscriber,
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
443 state, options)
178
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
444 return defer.succeed(None)
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
445 def getSubscription(self, subscriber):
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
446 return defer.succeed(self.subscription)
266
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
447 def getNodeOwner(self):
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
448 return defer.succeed(OWNER)
178
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
449
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
450 class TestStorage:
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
451 def getNode(self, nodeIdentifier):
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
452 return defer.succeed(TestNode())
178
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
453
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
454 def cb(data):
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
455 self.assertEqual('node', data['node'].nodeIdentifier)
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
456 self.assertEqual([ITEM], data['items'])
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
457 self.assertEqual(OWNER, data['subscription'].subscriber)
178
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
458
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
459 self.storage = TestStorage()
178
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
460 self.backend = backend.BackendService(self.storage)
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
461 self.storage.backend = self.backend
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
462
266
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
463 class Roster(object):
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
464 def getRoster(self, owner):
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
465 return {}
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
466 self.backend.roster = Roster()
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
467
178
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
468 d1 = defer.Deferred()
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
469 d1.addCallback(cb)
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
470 self.backend.registerNotifier(d1.callback)
220
e59b48f3f636 Add tests for subscription and unsubscription JID checks in [53d2c0019458].
Ralph Meijer <ralphm@ik.nu>
parents: 211
diff changeset
471 d2 = self.backend.subscribe('node', OWNER, OWNER_FULL)
178
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
472 return defer.gatherResults([d1, d2])
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
473
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
474 test_notifyOnSubscription.timeout = 2
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
475
171
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
476
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
477
172
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
478 class BaseTestBackend(object):
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
479 """
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
480 Base class for backend stubs.
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
481 """
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
482
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
483 def supportsPublisherAffiliation(self):
172
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
484 return True
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
485
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
486
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
487 def supportsOutcastAffiliation(self):
172
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
488 return True
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
489
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
490
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
491 def supportsPersistentItems(self):
172
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
492 return True
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
493
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
494
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
495 def supportsInstantNodes(self):
172
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
496 return True
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
497
238
a4511cb06352 fixed tests
Goffi <goffi@goffi.org>
parents: 235
diff changeset
498 def supportsItemAccess(self):
a4511cb06352 fixed tests
Goffi <goffi@goffi.org>
parents: 235
diff changeset
499 return True
a4511cb06352 fixed tests
Goffi <goffi@goffi.org>
parents: 235
diff changeset
500
a4511cb06352 fixed tests
Goffi <goffi@goffi.org>
parents: 235
diff changeset
501 def supportsAutoCreate(self):
a4511cb06352 fixed tests
Goffi <goffi@goffi.org>
parents: 235
diff changeset
502 return True
a4511cb06352 fixed tests
Goffi <goffi@goffi.org>
parents: 235
diff changeset
503
a4511cb06352 fixed tests
Goffi <goffi@goffi.org>
parents: 235
diff changeset
504 def supportsCreatorCheck(self):
a4511cb06352 fixed tests
Goffi <goffi@goffi.org>
parents: 235
diff changeset
505 return True
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
506
266
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
507 def supportsGroupBlog(self):
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
508 return True
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
509
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
510 def registerNotifier(self, observerfn, *args, **kwargs):
172
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
511 return
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
512
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
513
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
514 def registerPreDelete(self, preDeleteFn):
175
bd86f0c3fd39 Make test backend consistent with interface.
Ralph Meijer <ralphm@ik.nu>
parents: 172
diff changeset
515 return
bd86f0c3fd39 Make test backend consistent with interface.
Ralph Meijer <ralphm@ik.nu>
parents: 172
diff changeset
516
178
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 175
diff changeset
517
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
518
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
519 class PubSubResourceFromBackendTest(unittest.TestCase):
171
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
520
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
521 def test_interface(self):
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
522 resource = backend.PubSubResourceFromBackend(BaseTestBackend())
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
523 self.assertTrue(verifyObject(iwokkel.IPubSubResource, resource))
209
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
524
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
525
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
526 def test_preDelete(self):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
527 """
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
528 Test pre-delete sending out notifications to subscribers.
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
529 """
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
530
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
531 class TestBackend(BaseTestBackend):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
532 preDeleteFn = None
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
533
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
534 def registerPreDelete(self, preDeleteFn):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
535 self.preDeleteFn = preDeleteFn
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
536
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
537 def getSubscribers(self, nodeIdentifier):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
538 return defer.succeed([OWNER])
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
539
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
540 def notifyDelete(service, nodeIdentifier, subscribers,
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
541 redirectURI=None):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
542 self.assertEqual(SERVICE, service)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
543 self.assertEqual('test', nodeIdentifier)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
544 self.assertEqual([OWNER], subscribers)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
545 self.assertIdentical(None, redirectURI)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
546 d1.callback(None)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
547
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
548 d1 = defer.Deferred()
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
549 resource = backend.PubSubResourceFromBackend(TestBackend())
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
550 resource.serviceJID = SERVICE
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
551 resource.pubsubService = pubsub.PubSubService()
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
552 resource.pubsubService.notifyDelete = notifyDelete
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
553 self.assertTrue(verifyObject(iwokkel.IPubSubResource, resource))
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
554 self.assertNotIdentical(None, resource.backend.preDeleteFn)
266
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
555
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
556 class TestNode:
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
557 implements(iidavoll.ILeafNode)
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
558 nodeIdentifier = 'test'
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
559 nodeType = 'leaf'
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
560
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
561 data = {'node': TestNode()}
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
562 d2 = resource.backend.preDeleteFn(data)
209
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
563 return defer.DeferredList([d1, d2], fireOnOneErrback=1)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
564
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
565
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
566 def test_preDeleteRedirect(self):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
567 """
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
568 Test pre-delete sending out notifications to subscribers.
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
569 """
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
570
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
571 uri = 'xmpp:%s?;node=test2' % (SERVICE.full(),)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
572
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
573 class TestBackend(BaseTestBackend):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
574 preDeleteFn = None
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
575
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
576 def registerPreDelete(self, preDeleteFn):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
577 self.preDeleteFn = preDeleteFn
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
578
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
579 def getSubscribers(self, nodeIdentifier):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
580 return defer.succeed([OWNER])
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
581
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
582 def notifyDelete(service, nodeIdentifier, subscribers,
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
583 redirectURI=None):
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
584 self.assertEqual(SERVICE, service)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
585 self.assertEqual('test', nodeIdentifier)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
586 self.assertEqual([OWNER], subscribers)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
587 self.assertEqual(uri, redirectURI)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
588 d1.callback(None)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
589
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
590 d1 = defer.Deferred()
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
591 resource = backend.PubSubResourceFromBackend(TestBackend())
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
592 resource.serviceJID = SERVICE
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
593 resource.pubsubService = pubsub.PubSubService()
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
594 resource.pubsubService.notifyDelete = notifyDelete
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
595 self.assertTrue(verifyObject(iwokkel.IPubSubResource, resource))
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
596 self.assertNotIdentical(None, resource.backend.preDeleteFn)
266
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
597
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
598 class TestNode:
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
599 implements(iidavoll.ILeafNode)
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
600 nodeIdentifier = 'test'
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
601 nodeType = 'leaf'
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
602
560b6cdc50b2 fix the backend and storage tests
souliane <souliane@mailoo.org>
parents: 255
diff changeset
603 data = {'node': TestNode(),
209
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
604 'redirectURI': uri}
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
605 d2 = resource.backend.preDeleteFn(data)
209
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
606 return defer.DeferredList([d1, d2], fireOnOneErrback=1)
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
607
7f3ffb7a1a9e Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents: 206
diff changeset
608
171
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
609 def test_unsubscribeNotSubscribed(self):
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
610 """
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
611 Test unsubscription request when not subscribed.
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
612 """
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
613
172
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
614 class TestBackend(BaseTestBackend):
171
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
615 def unsubscribe(self, nodeIdentifier, subscriber, requestor):
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
616 return defer.fail(error.NotSubscribed())
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
617
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
618 def cb(e):
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
619 self.assertEqual('unexpected-request', e.condition)
171
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
620
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
621 resource = backend.PubSubResourceFromBackend(TestBackend())
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
622 request = pubsub.PubSubRequest()
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
623 request.sender = OWNER
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
624 request.recipient = SERVICE
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
625 request.nodeIdentifier = 'test'
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
626 request.subscriber = OWNER
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
627 d = resource.unsubscribe(request)
171
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
628 self.assertFailure(d, StanzaError)
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
629 d.addCallback(cb)
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
630 return d
172
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
631
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
632
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
633 def test_getInfo(self):
172
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
634 """
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
635 Test retrieving node information.
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
636 """
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
637
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
638 class TestBackend(BaseTestBackend):
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
639 def getNodeType(self, nodeIdentifier):
172
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
640 return defer.succeed('leaf')
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
641
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 187
diff changeset
642 def getNodeMetaData(self, nodeIdentifier):
172
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
643 return defer.succeed({'pubsub#persist_items': True})
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
644
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
645 def cb(info):
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
646 self.assertIn('type', info)
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
647 self.assertEqual('leaf', info['type'])
172
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
648 self.assertIn('meta-data', info)
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
649 self.assertEqual({'pubsub#persist_items': True}, info['meta-data'])
172
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
650
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
651 resource = backend.PubSubResourceFromBackend(TestBackend())
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
652 d = resource.getInfo(OWNER, SERVICE, 'test')
172
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
653 d.addCallback(cb)
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
654 return d
205
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
655
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
656
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
657 def test_getConfigurationOptions(self):
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
658 class TestBackend(BaseTestBackend):
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
659 nodeOptions = {
205
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
660 "pubsub#persist_items":
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
661 {"type": "boolean",
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
662 "label": "Persist items to storage"},
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
663 "pubsub#deliver_payloads":
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
664 {"type": "boolean",
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
665 "label": "Deliver payloads with event notifications"}
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
666 }
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
667
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
668 resource = backend.PubSubResourceFromBackend(TestBackend())
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
669 options = resource.getConfigurationOptions()
205
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
670 self.assertIn("pubsub#persist_items", options)
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
671
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
672
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
673 def test_default(self):
205
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
674 class TestBackend(BaseTestBackend):
206
274a45d2a5ab Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 205
diff changeset
675 def getDefaultConfiguration(self, nodeType):
205
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
676 options = {"pubsub#persist_items": True,
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
677 "pubsub#deliver_payloads": True,
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
678 "pubsub#send_last_published_item": 'on_sub',
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
679 }
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
680 return defer.succeed(options)
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
681
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
682 def cb(options):
414
ccb2a22ea0fc Python 3 port:
Goffi <goffi@goffi.org>
parents: 405
diff changeset
683 self.assertEqual(True, options["pubsub#persist_items"])
205
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
684
222
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
685 resource = backend.PubSubResourceFromBackend(TestBackend())
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
686 request = pubsub.PubSubRequest()
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
687 request.sender = OWNER
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
688 request.recipient = SERVICE
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
689 request.nodeType = 'leaf'
698af5d720ad Reshape Idavoll as a PubSubResource.
Ralph Meijer <ralphm@ik.nu>
parents: 220
diff changeset
690 d = resource.default(request)
205
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
691 d.addCallback(cb)
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
692 return d