diff idavoll/test/test_backend.py @ 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 bd86f0c3fd39
line wrap: on
line diff
--- 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