annotate sat_pubsub/test/test_backend.py @ 277:e749401be529

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