changeset 221:a430976f2977

Make a copy of the config to prevent later modification.
author Ralph Meijer <ralphm@ik.nu>
date Sat, 16 Oct 2010 20:56:51 +0200
parents e59b48f3f636
children 698af5d720ad
files idavoll/memory_storage.py idavoll/test/test_storage.py
diffstat 2 files changed, 30 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/idavoll/memory_storage.py	Sat Oct 16 20:54:52 2010 +0200
+++ b/idavoll/memory_storage.py	Sat Oct 16 20:56:51 2010 +0200
@@ -100,7 +100,7 @@
         self.nodeIdentifier = nodeIdentifier
         self._affiliations = {owner.userhost(): 'owner'}
         self._subscriptions = {}
-        self._config = config
+        self._config = copy.copy(config)
 
 
     def getType(self):
--- a/idavoll/test/test_storage.py	Sat Oct 16 20:54:52 2010 +0200
+++ b/idavoll/test/test_storage.py	Sat Oct 16 20:56:51 2010 +0200
@@ -101,6 +101,35 @@
         return d
 
 
+    def test_createNodeChangingConfig(self):
+        """
+        The configuration passed to createNode must be free to be changed.
+        """
+        def cb(result):
+            node1, node2 = result
+            self.assertTrue(node1.getConfiguration()['pubsub#persist_items'])
+
+        config = {
+                "pubsub#persist_items": True,
+                "pubsub#deliver_payloads": True,
+                "pubsub#send_last_published_item": 'on_sub',
+                "pubsub#node_type": 'leaf',
+                }
+
+        def unsetPersistItems(_):
+            config["pubsub#persist_items"] = False
+
+        d = defer.succeed(None)
+        d.addCallback(lambda _: self.s.createNode('new 1', OWNER, config))
+        d.addCallback(unsetPersistItems)
+        d.addCallback(lambda _: self.s.createNode('new 2', OWNER, config))
+        d.addCallback(lambda _: defer.gatherResults([
+                                    self.s.getNode('new 1'),
+                                    self.s.getNode('new 2')]))
+        d.addCallback(cb)
+        return d
+
+
     def test_deleteNonExistingNode(self):
         d = self.s.deleteNode('non-existing')
         self.assertFailure(d, error.NodeNotFound)