Mercurial > libervia-pubsub
changeset 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 | b4bf0a5ce50d |
children | 274a45d2a5ab |
files | idavoll/backend.py idavoll/test/test_backend.py |
diffstat | 2 files changed, 119 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/idavoll/backend.py Wed Jul 16 06:38:32 2008 +0000 +++ b/idavoll/backend.py Mon Aug 04 07:10:45 2008 +0000 @@ -268,7 +268,6 @@ def getDefaultConfiguration(self): d = defer.succeed(self.defaultConfig) - d.addCallback(self._makeConfig) return d @@ -278,36 +277,13 @@ d = self.storage.getNode(nodeIdentifier) d.addCallback(lambda node: node.getConfiguration()) - - d.addCallback(self._makeConfig) return d - def _makeConfig(self, config): - options = [] - for key, value in self.options.iteritems(): - option = {"var": key} - option.update(value) - if config.has_key(key): - option["value"] = config[key] - options.append(option) - - return options - - def setNodeConfiguration(self, nodeIdentifier, options, requestor): if not nodeIdentifier: return defer.fail(error.NoRootNode()) - for key, value in options.iteritems(): - if not self.options.has_key(key): - return defer.fail(error.InvalidConfigurationOption()) - if self.options[key]["type"] == 'boolean': - try: - options[key] = bool(int(value)) - except ValueError: - return defer.fail(error.InvalidConfigurationValue()) - d = self.storage.getNode(nodeIdentifier) d.addCallback(_getAffiliation, requestor) d.addCallback(self._doSetNodeConfiguration, options) @@ -609,6 +585,10 @@ return d.addErrback(self._mapErrors) + def getConfigurationOptions(self): + return self.backend.options + + def getDefaultConfiguration(self, requestor, service): d = self.backend.getDefaultConfiguration() return d.addErrback(self._mapErrors)
--- a/idavoll/test/test_backend.py Wed Jul 16 06:38:32 2008 +0000 +++ b/idavoll/test/test_backend.py Mon Aug 04 07:10:45 2008 +0000 @@ -79,6 +79,87 @@ return d + def test_getDefaultConfiguration(self): + """ + L{backend.BackendService.getDefaultConfiguration} should return + a deferred that fires a dictionary with configuration values. + """ + + def cb(options): + self.assertIn("pubsub#persist_items", options) + self.assertEqual(True, options["pubsub#persist_items"]) + + self.backend = backend.BackendService(None) + d = self.backend.getDefaultConfiguration() + d.addCallback(cb) + return d + + + def test_getNodeConfiguration(self): + class testNode: + nodeIdentifier = 'node' + def getConfiguration(self): + return {'pubsub#deliver_payloads': True, + 'pubsub#persist_items': False} + + class testStorage: + def getNode(self, nodeIdentifier): + return defer.succeed(testNode()) + + def cb(options): + self.assertIn("pubsub#deliver_payloads", options) + self.assertEqual(True, options["pubsub#deliver_payloads"]) + self.assertIn("pubsub#persist_items", options) + self.assertEqual(False, options["pubsub#persist_items"]) + + self.storage = testStorage() + self.backend = backend.BackendService(self.storage) + self.storage.backend = self.backend + + d = self.backend.getNodeConfiguration('node') + d.addCallback(cb) + return d + + + def test_setNodeConfiguration(self): + class testNode: + nodeIdentifier = 'node' + def getAffiliation(self, entity): + if entity is OWNER: + return defer.succeed('owner') + def setConfiguration(self, options): + self.options = options + + class testStorage: + def __init__(self): + self.nodes = {'node': testNode()} + def getNode(self, nodeIdentifier): + return defer.succeed(self.nodes[nodeIdentifier]) + + def checkOptions(node): + options = node.options + self.assertIn("pubsub#deliver_payloads", options) + self.assertEqual(True, options["pubsub#deliver_payloads"]) + self.assertIn("pubsub#persist_items", options) + self.assertEqual(False, options["pubsub#persist_items"]) + + def cb(result): + d = self.storage.getNode('node') + d.addCallback(checkOptions) + return d + + self.storage = testStorage() + self.backend = backend.BackendService(self.storage) + self.storage.backend = self.backend + + options = {'pubsub#deliver_payloads': True, + 'pubsub#persist_items': False} + + d = self.backend.setNodeConfiguration('node', options, OWNER) + d.addCallback(cb) + return d + + def test_publishNoID(self): """ Test publish request with an item without a node identifier. @@ -226,3 +307,37 @@ d = s.getNodeInfo(OWNER, 'test.example.org', 'test') d.addCallback(cb) return d + + + def test_getConfigurationOptions(self): + class TestBackend(BaseTestBackend): + options = { + "pubsub#persist_items": + {"type": "boolean", + "label": "Persist items to storage"}, + "pubsub#deliver_payloads": + {"type": "boolean", + "label": "Deliver payloads with event notifications"} + } + + s = backend.PubSubServiceFromBackend(TestBackend()) + options = s.getConfigurationOptions() + self.assertIn("pubsub#persist_items", options) + + + def test_getDefaultConfiguration(self): + class TestBackend(BaseTestBackend): + def getDefaultConfiguration(self): + options = {"pubsub#persist_items": True, + "pubsub#deliver_payloads": True, + "pubsub#send_last_published_item": 'on_sub', + } + return defer.succeed(options) + + def cb(options): + self.assertEquals(True, options["pubsub#persist_items"]) + + s = backend.PubSubServiceFromBackend(TestBackend()) + d = s.getDefaultConfiguration(OWNER, 'test.example.org') + d.addCallback(cb) + return d