changeset 172:9bfb00edd0cc

Fix Backend's getNodeInfo so that it properly adds its errback. Author: ralphm. Fixes #9.
author Ralph Meijer <ralphm@ik.nu>
date Tue, 15 Jan 2008 14:00:07 +0000
parents bc269696ef42
children 246911bcb699
files idavoll/backend.py idavoll/test/test_backend.py
diffstat 2 files changed, 45 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/idavoll/backend.py	Thu Jan 03 13:10:25 2008 +0000
+++ b/idavoll/backend.py	Tue Jan 15 14:00:07 2008 +0000
@@ -455,7 +455,7 @@
         d.addCallback(saveType)
         d.addCallback(self.backend.get_node_meta_data)
         d.addCallback(saveMetaData)
-        d.errback(self._mapErrors)
+        d.addErrback(self._mapErrors)
         return d
 
     def getNodes(self, requestor, service):
--- a/idavoll/test/test_backend.py	Thu Jan 03 13:10:25 2008 +0000
+++ b/idavoll/test/test_backend.py	Tue Jan 15 14:00:07 2008 +0000
@@ -107,6 +107,26 @@
         return d
 
 
+class BaseTestBackend(object):
+    """
+    Base class for backend stubs.
+    """
+
+    def supports_publisher_affiliation(self):
+        return True
+
+    def supports_outcast_affiliation(self):
+        return True
+
+    def supports_persistent_items(self):
+        return True
+
+    def supports_instant_nodes(self):
+        return True
+
+    def register_notifier(self, observerfn, *args, **kwargs):
+        return
+
 class PubSubServiceFromBackendTest(unittest.TestCase):
 
     def test_unsubscribeNotSubscribed(self):
@@ -114,22 +134,7 @@
         Test unsubscription request when not subscribed.
         """
 
-        class TestBackend(object):
-            def supports_publisher_affiliation(self):
-                return True
-
-            def supports_outcast_affiliation(self):
-                return True
-
-            def supports_persistent_items(self):
-                return True
-
-            def supports_instant_nodes(self):
-                return True
-
-            def register_notifier(self, observerfn, *args, **kwargs):
-                return
-
+        class TestBackend(BaseTestBackend):
             def unsubscribe(self, nodeIdentifier, subscriber, requestor):
                 return defer.fail(error.NotSubscribed())
 
@@ -141,3 +146,26 @@
         self.assertFailure(d, StanzaError)
         d.addCallback(cb)
         return d
+
+    def test_getNodeInfo(self):
+        """
+        Test retrieving node information.
+        """
+
+        class TestBackend(BaseTestBackend):
+            def get_node_type(self, nodeIdentifier):
+                return defer.succeed('leaf')
+
+            def get_node_meta_data(self, nodeIdentifier):
+                return defer.succeed({'pubsub#persist_items': True})
+
+        def cb(info):
+            self.assertIn('type', info)
+            self.assertEquals('leaf', info['type'])
+            self.assertIn('meta-data', info)
+            self.assertEquals({'pubsub#persist_items': True}, info['meta-data'])
+
+        s = backend.PubSubServiceFromBackend(TestBackend())
+        d = s.getNodeInfo(OWNER, 'test.example.org', 'test')
+        d.addCallback(cb)
+        return d