Mercurial > libervia-pubsub
annotate idavoll/test/test_backend.py @ 213:a321f9300054
Actually log requests if verbose.
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Thu, 18 Jun 2009 10:27:11 +0000 |
parents | bfc198af5d27 |
children | e59b48f3f636 |
rev | line source |
---|---|
211 | 1 # Copyright (c) 2003-2009 Ralph Meijer |
155
5191ba7c4df8
Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents:
143
diff
changeset
|
2 # See LICENSE for details. |
5191ba7c4df8
Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents:
143
diff
changeset
|
3 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
4 """ |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
5 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
|
6 """ |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
7 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
8 from zope.interface import implements |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
9 from zope.interface.verify import verifyObject |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
10 |
168
e2c2c2baf483
Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
11 from twisted.internet import defer |
143 | 12 from twisted.trial import unittest |
13 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
|
14 from twisted.words.protocols.jabber.error import StanzaError |
143 | 15 |
209
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
16 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
|
17 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
18 from idavoll import backend, error, iidavoll |
143 | 19 |
20 OWNER = jid.JID('owner@example.com') | |
209
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
21 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
|
22 NS_PUBSUB = 'http://jabber.org/protocol/pubsub' |
143 | 23 |
168
e2c2c2baf483
Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
24 class BackendTest(unittest.TestCase): |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
25 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
26 def test_interfaceIBackend(self): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
27 self.assertTrue(verifyObject(iidavoll.IBackendService, |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
28 backend.BackendService(None))) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
29 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
30 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
31 def test_deleteNode(self): |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
32 class TestNode: |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
33 nodeIdentifier = 'to-be-deleted' |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
34 def getAffiliation(self, entity): |
168
e2c2c2baf483
Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
35 if entity is OWNER: |
e2c2c2baf483
Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
36 return defer.succeed('owner') |
143 | 37 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
38 class TestStorage: |
209
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
39 def __init__(self): |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
40 self.deleteCalled = [] |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
41 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
42 def getNode(self, nodeIdentifier): |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
43 return defer.succeed(TestNode()) |
143 | 44 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
45 def deleteNode(self, nodeIdentifier): |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
46 if nodeIdentifier in ['to-be-deleted']: |
209
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
47 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
|
48 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
|
49 else: |
e2c2c2baf483
Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
50 return defer.fail(error.NodeNotFound()) |
143 | 51 |
209
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
52 def preDelete(data): |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
53 self.assertFalse(self.storage.deleteCalled) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
54 preDeleteCalled.append(data) |
143 | 55 return defer.succeed(None) |
56 | |
57 def cb(result): | |
209
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
58 self.assertEquals(1, len(preDeleteCalled)) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
59 data = preDeleteCalled[-1] |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
60 self.assertEquals('to-be-deleted', data['nodeIdentifier']) |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
61 self.assertTrue(self.storage.deleteCalled) |
143 | 62 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
63 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
|
64 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
|
65 |
209
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
66 preDeleteCalled = [] |
168
e2c2c2baf483
Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
67 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
68 self.backend.registerPreDelete(preDelete) |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
69 d = self.backend.deleteNode('to-be-deleted', OWNER) |
143 | 70 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
|
71 return d |
168
e2c2c2baf483
Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
72 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
73 |
209
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
74 def test_deleteNodeRedirect(self): |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
75 uri = 'xmpp:%s?;node=test2' % (SERVICE.full(),) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
76 |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
77 class TestNode: |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
78 nodeIdentifier = 'to-be-deleted' |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
79 def getAffiliation(self, entity): |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
80 if entity is OWNER: |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
81 return defer.succeed('owner') |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
82 |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
83 class TestStorage: |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
84 def __init__(self): |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
85 self.deleteCalled = [] |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
86 |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
87 def getNode(self, nodeIdentifier): |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
88 return defer.succeed(TestNode()) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
89 |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
90 def deleteNode(self, nodeIdentifier): |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
91 if nodeIdentifier in ['to-be-deleted']: |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
92 self.deleteCalled.append(nodeIdentifier) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
93 return defer.succeed(None) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
94 else: |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
95 return defer.fail(error.NodeNotFound()) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
96 |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
97 def preDelete(data): |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
98 self.assertFalse(self.storage.deleteCalled) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
99 preDeleteCalled.append(data) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
100 return defer.succeed(None) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
101 |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
102 def cb(result): |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
103 self.assertEquals(1, len(preDeleteCalled)) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
104 data = preDeleteCalled[-1] |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
105 self.assertEquals('to-be-deleted', data['nodeIdentifier']) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
106 self.assertEquals(uri, data['redirectURI']) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
107 self.assertTrue(self.storage.deleteCalled) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
108 |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
109 self.storage = TestStorage() |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
110 self.backend = backend.BackendService(self.storage) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
111 |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
112 preDeleteCalled = [] |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
113 |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
114 self.backend.registerPreDelete(preDelete) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
115 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
|
116 d.addCallback(cb) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
117 return d |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
118 |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
119 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
120 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
|
121 """ |
e2c2c2baf483
Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
122 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
|
123 """ |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
124 class TestStorage: |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
125 def getDefaultConfiguration(self, nodeType): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
126 return {} |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
127 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
128 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
|
129 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
|
130 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
|
131 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
132 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
|
133 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
|
134 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
|
135 |
e2c2c2baf483
Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
136 def checkID(nodeIdentifier): |
e2c2c2baf483
Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
137 self.assertNotIdentical(None, nodeIdentifier) |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
138 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
|
139 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
140 d = self.backend.createNode(None, OWNER) |
168
e2c2c2baf483
Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
141 d.addCallback(checkID) |
e2c2c2baf483
Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
142 return d |
e2c2c2baf483
Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
143 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
144 class NodeStore: |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
145 """ |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
146 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
|
147 """ |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
148 def __init__(self, nodes): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
149 self.nodes = nodes |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
150 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
151 def getNode(self, nodeIdentifier): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
152 try: |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
153 return defer.succeed(self.nodes[nodeIdentifier]) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
154 except KeyError: |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
155 return defer.fail(error.NodeNotFound()) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
156 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
157 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
158 def test_getNotifications(self): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
159 """ |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
160 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
|
161 """ |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
162 item = pubsub.Item() |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
163 sub = pubsub.Subscription('test', OWNER, 'subscribed') |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
164 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
165 class TestNode: |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
166 def getSubscriptions(self, state=None): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
167 return [sub] |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
168 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
169 def cb(result): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
170 self.assertEquals(1, len(result)) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
171 subscriber, subscriptions, items = result[-1] |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
172 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
173 self.assertEquals(OWNER, subscriber) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
174 self.assertEquals(set([sub]), subscriptions) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
175 self.assertEquals([item], items) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
176 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
177 self.storage = self.NodeStore({'test': TestNode()}) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
178 self.backend = backend.BackendService(self.storage) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
179 d = self.backend.getNotifications('test', [item]) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
180 d.addCallback(cb) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
181 return d |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
182 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
183 def test_getNotificationsRoot(self): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
184 """ |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
185 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
|
186 for leaf nodes. |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
187 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
188 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
|
189 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
|
190 of the root node. |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
191 """ |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
192 item = pubsub.Item() |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
193 subRoot = pubsub.Subscription('', OWNER, 'subscribed') |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
194 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
195 class TestNode: |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
196 def getSubscriptions(self, state=None): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
197 return [] |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
198 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
199 class TestRootNode: |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
200 def getSubscriptions(self, state=None): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
201 return [subRoot] |
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 cb(result): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
204 self.assertEquals(1, len(result)) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
205 subscriber, subscriptions, items = result[-1] |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
206 self.assertEquals(OWNER, subscriber) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
207 self.assertEquals(set([subRoot]), subscriptions) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
208 self.assertEquals([item], items) |
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 self.storage = self.NodeStore({'test': TestNode(), |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
211 '': TestRootNode()}) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
212 self.backend = backend.BackendService(self.storage) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
213 d = self.backend.getNotifications('test', [item]) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
214 d.addCallback(cb) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
215 return d |
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 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
218 def test_getNotificationsMultipleNodes(self): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
219 """ |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
220 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
|
221 root node get exactly one notification. |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
222 """ |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
223 item = pubsub.Item() |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
224 sub = pubsub.Subscription('test', OWNER, 'subscribed') |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
225 subRoot = pubsub.Subscription('', OWNER, 'subscribed') |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
226 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
227 class TestNode: |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
228 def getSubscriptions(self, state=None): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
229 return [sub] |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
230 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
231 class TestRootNode: |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
232 def getSubscriptions(self, state=None): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
233 return [subRoot] |
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 cb(result): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
236 self.assertEquals(1, len(result)) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
237 subscriber, subscriptions, items = result[-1] |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
238 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
239 self.assertEquals(OWNER, subscriber) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
240 self.assertEquals(set([sub, subRoot]), subscriptions) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
241 self.assertEquals([item], items) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
242 |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
243 self.storage = self.NodeStore({'test': TestNode(), |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
244 '': TestRootNode()}) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
245 self.backend = backend.BackendService(self.storage) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
246 d = self.backend.getNotifications('test', [item]) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
247 d.addCallback(cb) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
248 return d |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
249 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
250 |
205
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
251 def test_getDefaultConfiguration(self): |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
252 """ |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
253 L{backend.BackendService.getDefaultConfiguration} should return |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
254 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
|
255 """ |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
256 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
257 class TestStorage: |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
258 def getDefaultConfiguration(self, nodeType): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
259 return { |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
260 "pubsub#persist_items": True, |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
261 "pubsub#deliver_payloads": True} |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
262 |
205
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
263 def cb(options): |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
264 self.assertIn("pubsub#persist_items", options) |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
265 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
|
266 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
267 self.backend = backend.BackendService(TestStorage()) |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
268 d = self.backend.getDefaultConfiguration('leaf') |
205
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
269 d.addCallback(cb) |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
270 return d |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
271 |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
272 |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
273 def test_getNodeConfiguration(self): |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
274 class testNode: |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
275 nodeIdentifier = 'node' |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
276 def getConfiguration(self): |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
277 return {'pubsub#deliver_payloads': True, |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
278 'pubsub#persist_items': False} |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
279 |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
280 class testStorage: |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
281 def getNode(self, nodeIdentifier): |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
282 return defer.succeed(testNode()) |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
283 |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
284 def cb(options): |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
285 self.assertIn("pubsub#deliver_payloads", options) |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
286 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
|
287 self.assertIn("pubsub#persist_items", options) |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
288 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
|
289 |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
290 self.storage = testStorage() |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
291 self.backend = backend.BackendService(self.storage) |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
292 self.storage.backend = self.backend |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
293 |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
294 d = self.backend.getNodeConfiguration('node') |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
295 d.addCallback(cb) |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
296 return d |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
297 |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
298 |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
299 def test_setNodeConfiguration(self): |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
300 class testNode: |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
301 nodeIdentifier = 'node' |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
302 def getAffiliation(self, entity): |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
303 if entity is OWNER: |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
304 return defer.succeed('owner') |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
305 def setConfiguration(self, options): |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
306 self.options = options |
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 class testStorage: |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
309 def __init__(self): |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
310 self.nodes = {'node': testNode()} |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
311 def getNode(self, nodeIdentifier): |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
312 return defer.succeed(self.nodes[nodeIdentifier]) |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
313 |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
314 def checkOptions(node): |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
315 options = node.options |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
316 self.assertIn("pubsub#deliver_payloads", 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#deliver_payloads"]) |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
318 self.assertIn("pubsub#persist_items", options) |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
319 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
|
320 |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
321 def cb(result): |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
322 d = self.storage.getNode('node') |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
323 d.addCallback(checkOptions) |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
324 return d |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
325 |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
326 self.storage = testStorage() |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
327 self.backend = backend.BackendService(self.storage) |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
328 self.storage.backend = self.backend |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
329 |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
330 options = {'pubsub#deliver_payloads': True, |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
331 'pubsub#persist_items': False} |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
332 |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
333 d = self.backend.setNodeConfiguration('node', options, OWNER) |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
334 d.addCallback(cb) |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
335 return d |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
336 |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
337 |
168
e2c2c2baf483
Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
338 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
|
339 """ |
e2c2c2baf483
Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
340 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
|
341 """ |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
342 class TestNode: |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
343 nodeType = 'leaf' |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
344 nodeIdentifier = 'node' |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
345 def getAffiliation(self, entity): |
168
e2c2c2baf483
Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
346 if entity is OWNER: |
e2c2c2baf483
Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
347 return defer.succeed('owner') |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
348 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
|
349 return {'pubsub#deliver_payloads': True, |
e2c2c2baf483
Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
350 'pubsub#persist_items': False} |
e2c2c2baf483
Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
351 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
352 class TestStorage: |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
353 def getNode(self, nodeIdentifier): |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
354 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
|
355 |
e2c2c2baf483
Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
356 def checkID(notification): |
e2c2c2baf483
Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
357 self.assertNotIdentical(None, notification['items'][0]['id']) |
e2c2c2baf483
Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
358 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
359 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
|
360 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
|
361 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
|
362 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
363 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
|
364 |
e2c2c2baf483
Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
365 items = [pubsub.Item()] |
e2c2c2baf483
Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
366 d = self.backend.publish('node', items, OWNER) |
e2c2c2baf483
Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents:
167
diff
changeset
|
367 return d |
171
bc269696ef42
Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents:
168
diff
changeset
|
368 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
369 |
178
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
175
diff
changeset
|
370 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
|
371 """ |
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
175
diff
changeset
|
372 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
|
373 """ |
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
175
diff
changeset
|
374 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
|
375 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
376 class TestNode: |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
377 implements(iidavoll.ILeafNode) |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
378 nodeIdentifier = 'node' |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
379 nodeType = 'leaf' |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
380 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
|
381 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
|
382 return defer.succeed('owner') |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
383 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
|
384 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
|
385 'pubsub#persist_items': False, |
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
175
diff
changeset
|
386 'pubsub#send_last_published_item': 'on_sub'} |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
387 def getItems(self, maxItems): |
178
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
175
diff
changeset
|
388 return [ITEM] |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
389 def addSubscription(self, subscriber, state, options): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
390 self.subscription = pubsub.Subscription('node', subscriber, |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
391 state, options) |
178
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
175
diff
changeset
|
392 return defer.succeed(None) |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
393 def getSubscription(self, subscriber): |
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
394 return defer.succeed(self.subscription) |
178
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
175
diff
changeset
|
395 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
396 class TestStorage: |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
397 def getNode(self, nodeIdentifier): |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
398 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
|
399 |
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
175
diff
changeset
|
400 def cb(data): |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
401 self.assertEquals('node', data['nodeIdentifier']) |
178
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
175
diff
changeset
|
402 self.assertEquals([ITEM], data['items']) |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
403 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
|
404 |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
405 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
|
406 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
|
407 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
|
408 |
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
175
diff
changeset
|
409 d1 = defer.Deferred() |
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
175
diff
changeset
|
410 d1.addCallback(cb) |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
411 self.backend.registerNotifier(d1.callback) |
178
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
175
diff
changeset
|
412 d2 = self.backend.subscribe('node', OWNER, OWNER) |
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
175
diff
changeset
|
413 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
|
414 |
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
175
diff
changeset
|
415 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
|
416 |
171
bc269696ef42
Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents:
168
diff
changeset
|
417 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
418 |
172
9bfb00edd0cc
Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
419 class BaseTestBackend(object): |
9bfb00edd0cc
Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
420 """ |
9bfb00edd0cc
Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
421 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
|
422 """ |
9bfb00edd0cc
Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
423 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
424 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
|
425 return True |
9bfb00edd0cc
Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
426 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
427 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
428 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
|
429 return True |
9bfb00edd0cc
Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
430 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
431 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
432 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
|
433 return True |
9bfb00edd0cc
Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
434 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
435 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
436 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
|
437 return True |
9bfb00edd0cc
Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
438 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
439 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
440 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
|
441 return |
9bfb00edd0cc
Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
442 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
443 |
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
444 def registerPreDelete(self, preDeleteFn): |
175
bd86f0c3fd39
Make test backend consistent with interface.
Ralph Meijer <ralphm@ik.nu>
parents:
172
diff
changeset
|
445 return |
bd86f0c3fd39
Make test backend consistent with interface.
Ralph Meijer <ralphm@ik.nu>
parents:
172
diff
changeset
|
446 |
178
07114105885a
Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents:
175
diff
changeset
|
447 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
448 |
171
bc269696ef42
Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents:
168
diff
changeset
|
449 class PubSubServiceFromBackendTest(unittest.TestCase): |
bc269696ef42
Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents:
168
diff
changeset
|
450 |
209
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
451 def test_interfaceIBackend(self): |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
452 s = backend.PubSubServiceFromBackend(BaseTestBackend()) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
453 self.assertTrue(verifyObject(iwokkel.IPubSubService, s)) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
454 |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
455 |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
456 def test_preDelete(self): |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
457 """ |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
458 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
|
459 """ |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
460 |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
461 class TestBackend(BaseTestBackend): |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
462 preDeleteFn = None |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
463 |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
464 def registerPreDelete(self, preDeleteFn): |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
465 self.preDeleteFn = preDeleteFn |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
466 |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
467 def getSubscribers(self, nodeIdentifier): |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
468 return defer.succeed([OWNER]) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
469 |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
470 def notifyDelete(service, nodeIdentifier, subscribers, |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
471 redirectURI=None): |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
472 self.assertEqual(SERVICE, service) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
473 self.assertEqual('test', nodeIdentifier) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
474 self.assertEqual([OWNER], subscribers) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
475 self.assertIdentical(None, redirectURI) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
476 d1.callback(None) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
477 |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
478 d1 = defer.Deferred() |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
479 s = backend.PubSubServiceFromBackend(TestBackend()) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
480 s.serviceJID = SERVICE |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
481 s.notifyDelete = notifyDelete |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
482 self.assertTrue(verifyObject(iwokkel.IPubSubService, s)) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
483 self.assertNotIdentical(None, s.backend.preDeleteFn) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
484 data = {'nodeIdentifier': 'test'} |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
485 d2 = s.backend.preDeleteFn(data) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
486 return defer.DeferredList([d1, d2], fireOnOneErrback=1) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
487 |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
488 |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
489 def test_preDeleteRedirect(self): |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
490 """ |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
491 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
|
492 """ |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
493 |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
494 uri = 'xmpp:%s?;node=test2' % (SERVICE.full(),) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
495 |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
496 class TestBackend(BaseTestBackend): |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
497 preDeleteFn = None |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
498 |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
499 def registerPreDelete(self, preDeleteFn): |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
500 self.preDeleteFn = preDeleteFn |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
501 |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
502 def getSubscribers(self, nodeIdentifier): |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
503 return defer.succeed([OWNER]) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
504 |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
505 def notifyDelete(service, nodeIdentifier, subscribers, |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
506 redirectURI=None): |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
507 self.assertEqual(SERVICE, service) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
508 self.assertEqual('test', nodeIdentifier) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
509 self.assertEqual([OWNER], subscribers) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
510 self.assertEqual(uri, redirectURI) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
511 d1.callback(None) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
512 |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
513 d1 = defer.Deferred() |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
514 s = backend.PubSubServiceFromBackend(TestBackend()) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
515 s.serviceJID = SERVICE |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
516 s.notifyDelete = notifyDelete |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
517 self.assertTrue(verifyObject(iwokkel.IPubSubService, s)) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
518 self.assertNotIdentical(None, s.backend.preDeleteFn) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
519 data = {'nodeIdentifier': 'test', |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
520 'redirectURI': uri} |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
521 d2 = s.backend.preDeleteFn(data) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
522 return defer.DeferredList([d1, d2], fireOnOneErrback=1) |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
523 |
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
524 |
171
bc269696ef42
Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents:
168
diff
changeset
|
525 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
|
526 """ |
bc269696ef42
Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents:
168
diff
changeset
|
527 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
|
528 """ |
bc269696ef42
Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents:
168
diff
changeset
|
529 |
172
9bfb00edd0cc
Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
530 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
|
531 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
|
532 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
|
533 |
bc269696ef42
Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents:
168
diff
changeset
|
534 def cb(e): |
bc269696ef42
Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents:
168
diff
changeset
|
535 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
|
536 |
bc269696ef42
Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents:
168
diff
changeset
|
537 s = backend.PubSubServiceFromBackend(TestBackend()) |
209
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
538 d = s.unsubscribe(OWNER, SERVICE, 'test', OWNER) |
171
bc269696ef42
Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents:
168
diff
changeset
|
539 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
|
540 d.addCallback(cb) |
bc269696ef42
Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents:
168
diff
changeset
|
541 return d |
172
9bfb00edd0cc
Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
542 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
543 |
172
9bfb00edd0cc
Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
544 def test_getNodeInfo(self): |
9bfb00edd0cc
Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
545 """ |
9bfb00edd0cc
Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
546 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
|
547 """ |
9bfb00edd0cc
Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
548 |
9bfb00edd0cc
Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
549 class TestBackend(BaseTestBackend): |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
550 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
|
551 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
|
552 |
198
e404775b12df
Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents:
187
diff
changeset
|
553 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
|
554 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
|
555 |
9bfb00edd0cc
Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
556 def cb(info): |
9bfb00edd0cc
Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
557 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
|
558 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
|
559 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
|
560 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
|
561 |
9bfb00edd0cc
Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
562 s = backend.PubSubServiceFromBackend(TestBackend()) |
209
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
563 d = s.getNodeInfo(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
|
564 d.addCallback(cb) |
9bfb00edd0cc
Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents:
171
diff
changeset
|
565 return d |
205
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
566 |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
567 |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
568 def test_getConfigurationOptions(self): |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
569 class TestBackend(BaseTestBackend): |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
570 nodeOptions = { |
205
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
571 "pubsub#persist_items": |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
572 {"type": "boolean", |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
573 "label": "Persist items to storage"}, |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
574 "pubsub#deliver_payloads": |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
575 {"type": "boolean", |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
576 "label": "Deliver payloads with event notifications"} |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
577 } |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
578 |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
579 s = backend.PubSubServiceFromBackend(TestBackend()) |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
580 options = s.getConfigurationOptions() |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
581 self.assertIn("pubsub#persist_items", options) |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
582 |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
583 |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
584 def test_getDefaultConfiguration(self): |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
585 class TestBackend(BaseTestBackend): |
206
274a45d2a5ab
Implement root collection that includes all leaf nodes.
Ralph Meijer <ralphm@ik.nu>
parents:
205
diff
changeset
|
586 def getDefaultConfiguration(self, nodeType): |
205
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
587 options = {"pubsub#persist_items": True, |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
588 "pubsub#deliver_payloads": True, |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
589 "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
|
590 } |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
591 return defer.succeed(options) |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
592 |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
593 def cb(options): |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
594 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
|
595 |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
596 s = backend.PubSubServiceFromBackend(TestBackend()) |
209
7f3ffb7a1a9e
Add support for node deletion with redirect.
Ralph Meijer <ralphm@ik.nu>
parents:
206
diff
changeset
|
597 d = s.getDefaultConfiguration(OWNER, SERVICE, 'leaf') |
205
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
598 d.addCallback(cb) |
e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents:
198
diff
changeset
|
599 return d |