Mercurial > libervia-pubsub
comparison idavoll/test/test_backend.py @ 205:e6b710bf2b24
Adjust node configuration to match wokkel API changes.
Author: ralphm.
Fixes #13.
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Mon, 04 Aug 2008 07:10:45 +0000 |
parents | e404775b12df |
children | 274a45d2a5ab |
comparison
equal
deleted
inserted
replaced
204:b4bf0a5ce50d | 205:e6b710bf2b24 |
---|---|
74 self.assertNotIdentical(None, nodeIdentifier) | 74 self.assertNotIdentical(None, nodeIdentifier) |
75 self.assertIdentical(self.storage.nodeIdentifier, nodeIdentifier) | 75 self.assertIdentical(self.storage.nodeIdentifier, nodeIdentifier) |
76 | 76 |
77 d = self.backend.createNode(None, OWNER) | 77 d = self.backend.createNode(None, OWNER) |
78 d.addCallback(checkID) | 78 d.addCallback(checkID) |
79 return d | |
80 | |
81 | |
82 def test_getDefaultConfiguration(self): | |
83 """ | |
84 L{backend.BackendService.getDefaultConfiguration} should return | |
85 a deferred that fires a dictionary with configuration values. | |
86 """ | |
87 | |
88 def cb(options): | |
89 self.assertIn("pubsub#persist_items", options) | |
90 self.assertEqual(True, options["pubsub#persist_items"]) | |
91 | |
92 self.backend = backend.BackendService(None) | |
93 d = self.backend.getDefaultConfiguration() | |
94 d.addCallback(cb) | |
95 return d | |
96 | |
97 | |
98 def test_getNodeConfiguration(self): | |
99 class testNode: | |
100 nodeIdentifier = 'node' | |
101 def getConfiguration(self): | |
102 return {'pubsub#deliver_payloads': True, | |
103 'pubsub#persist_items': False} | |
104 | |
105 class testStorage: | |
106 def getNode(self, nodeIdentifier): | |
107 return defer.succeed(testNode()) | |
108 | |
109 def cb(options): | |
110 self.assertIn("pubsub#deliver_payloads", options) | |
111 self.assertEqual(True, options["pubsub#deliver_payloads"]) | |
112 self.assertIn("pubsub#persist_items", options) | |
113 self.assertEqual(False, options["pubsub#persist_items"]) | |
114 | |
115 self.storage = testStorage() | |
116 self.backend = backend.BackendService(self.storage) | |
117 self.storage.backend = self.backend | |
118 | |
119 d = self.backend.getNodeConfiguration('node') | |
120 d.addCallback(cb) | |
121 return d | |
122 | |
123 | |
124 def test_setNodeConfiguration(self): | |
125 class testNode: | |
126 nodeIdentifier = 'node' | |
127 def getAffiliation(self, entity): | |
128 if entity is OWNER: | |
129 return defer.succeed('owner') | |
130 def setConfiguration(self, options): | |
131 self.options = options | |
132 | |
133 class testStorage: | |
134 def __init__(self): | |
135 self.nodes = {'node': testNode()} | |
136 def getNode(self, nodeIdentifier): | |
137 return defer.succeed(self.nodes[nodeIdentifier]) | |
138 | |
139 def checkOptions(node): | |
140 options = node.options | |
141 self.assertIn("pubsub#deliver_payloads", options) | |
142 self.assertEqual(True, options["pubsub#deliver_payloads"]) | |
143 self.assertIn("pubsub#persist_items", options) | |
144 self.assertEqual(False, options["pubsub#persist_items"]) | |
145 | |
146 def cb(result): | |
147 d = self.storage.getNode('node') | |
148 d.addCallback(checkOptions) | |
149 return d | |
150 | |
151 self.storage = testStorage() | |
152 self.backend = backend.BackendService(self.storage) | |
153 self.storage.backend = self.backend | |
154 | |
155 options = {'pubsub#deliver_payloads': True, | |
156 'pubsub#persist_items': False} | |
157 | |
158 d = self.backend.setNodeConfiguration('node', options, OWNER) | |
159 d.addCallback(cb) | |
79 return d | 160 return d |
80 | 161 |
81 | 162 |
82 def test_publishNoID(self): | 163 def test_publishNoID(self): |
83 """ | 164 """ |
224 | 305 |
225 s = backend.PubSubServiceFromBackend(TestBackend()) | 306 s = backend.PubSubServiceFromBackend(TestBackend()) |
226 d = s.getNodeInfo(OWNER, 'test.example.org', 'test') | 307 d = s.getNodeInfo(OWNER, 'test.example.org', 'test') |
227 d.addCallback(cb) | 308 d.addCallback(cb) |
228 return d | 309 return d |
310 | |
311 | |
312 def test_getConfigurationOptions(self): | |
313 class TestBackend(BaseTestBackend): | |
314 options = { | |
315 "pubsub#persist_items": | |
316 {"type": "boolean", | |
317 "label": "Persist items to storage"}, | |
318 "pubsub#deliver_payloads": | |
319 {"type": "boolean", | |
320 "label": "Deliver payloads with event notifications"} | |
321 } | |
322 | |
323 s = backend.PubSubServiceFromBackend(TestBackend()) | |
324 options = s.getConfigurationOptions() | |
325 self.assertIn("pubsub#persist_items", options) | |
326 | |
327 | |
328 def test_getDefaultConfiguration(self): | |
329 class TestBackend(BaseTestBackend): | |
330 def getDefaultConfiguration(self): | |
331 options = {"pubsub#persist_items": True, | |
332 "pubsub#deliver_payloads": True, | |
333 "pubsub#send_last_published_item": 'on_sub', | |
334 } | |
335 return defer.succeed(options) | |
336 | |
337 def cb(options): | |
338 self.assertEquals(True, options["pubsub#persist_items"]) | |
339 | |
340 s = backend.PubSubServiceFromBackend(TestBackend()) | |
341 d = s.getDefaultConfiguration(OWNER, 'test.example.org') | |
342 d.addCallback(cb) | |
343 return d |