diff sat_pubsub/test/test_backend.py @ 266:560b6cdc50b2 0.1.0

fix the backend and storage tests
author souliane <souliane@mailoo.org>
date Sat, 22 Feb 2014 08:05:03 +0100
parents d55620ceafed
children 002c59dbc23f
line wrap: on
line diff
--- a/sat_pubsub/test/test_backend.py	Sat Feb 22 08:04:09 2014 +0100
+++ b/sat_pubsub/test/test_backend.py	Sat Feb 22 08:05:03 2014 +0100
@@ -66,7 +66,7 @@
 
 from wokkel import iwokkel, pubsub
 
-from sat_pubsub import backend, error, iidavoll
+from sat_pubsub import backend, error, iidavoll, const
 
 OWNER = jid.JID('owner@example.com')
 OWNER_FULL = jid.JID('owner@example.com/home')
@@ -109,7 +109,7 @@
         def cb(result):
             self.assertEquals(1, len(preDeleteCalled))
             data = preDeleteCalled[-1]
-            self.assertEquals('to-be-deleted', data['nodeIdentifier'])
+            self.assertEquals('to-be-deleted', data['node'].nodeIdentifier)
             self.assertTrue(self.storage.deleteCalled)
 
         self.storage = TestStorage()
@@ -154,7 +154,7 @@
         def cb(result):
             self.assertEquals(1, len(preDeleteCalled))
             data = preDeleteCalled[-1]
-            self.assertEquals('to-be-deleted', data['nodeIdentifier'])
+            self.assertEquals('to-be-deleted', data['node'].nodeIdentifier)
             self.assertEquals(uri, data['redirectURI'])
             self.assertTrue(self.storage.deleteCalled)
 
@@ -399,14 +399,15 @@
                     return defer.succeed('owner')
             def getConfiguration(self):
                 return {'pubsub#deliver_payloads': True,
-                        'pubsub#persist_items': False}
+                        'pubsub#persist_items': False,
+                        const.OPT_PUBLISH_MODEL: const.VAL_PMODEL_OPEN}
 
         class TestStorage:
             def getNode(self, nodeIdentifier):
                 return defer.succeed(TestNode())
 
         def checkID(notification):
-            self.assertNotIdentical(None, notification['items'][0]['id'])
+            self.assertNotIdentical(None, notification['items'][0][2]['id'])
 
         self.storage = TestStorage()
         self.backend = backend.BackendService(self.storage)
@@ -435,22 +436,25 @@
             def getConfiguration(self):
                 return {'pubsub#deliver_payloads': True,
                         'pubsub#persist_items': False,
-                        'pubsub#send_last_published_item': 'on_sub'}
-            def getItems(self, maxItems):
-                return [ITEM]
+                        'pubsub#send_last_published_item': 'on_sub',
+                        const.OPT_ACCESS_MODEL: const.VAL_AMODEL_OPEN}
+            def getItems(self, authorized_groups, unrestricted, maxItems):
+                return defer.succeed([(ITEM, const.VAL_AMODEL_OPEN, None)])
             def addSubscription(self, subscriber, state, options):
                 self.subscription = pubsub.Subscription('node', subscriber,
                                                         state, options)
                 return defer.succeed(None)
             def getSubscription(self, subscriber):
                 return defer.succeed(self.subscription)
+            def getNodeOwner(self):
+                return defer.succeed(OWNER)
 
         class TestStorage:
             def getNode(self, nodeIdentifier):
                 return defer.succeed(TestNode())
 
         def cb(data):
-            self.assertEquals('node', data['nodeIdentifier'])
+            self.assertEquals('node', data['node'].nodeIdentifier)
             self.assertEquals([ITEM], data['items'])
             self.assertEquals(OWNER, data['subscription'].subscriber)
 
@@ -458,6 +462,11 @@
         self.backend = backend.BackendService(self.storage)
         self.storage.backend = self.backend
 
+        class Roster(object):
+            def getRoster(self, owner):
+                return {}
+        self.backend.roster = Roster()
+
         d1 = defer.Deferred()
         d1.addCallback(cb)
         self.backend.registerNotifier(d1.callback)
@@ -497,6 +506,9 @@
     def supportsCreatorCheck(self):
         return True
 
+    def supportsGroupBlog(self):
+        return True
+
     def registerNotifier(self, observerfn, *args, **kwargs):
         return
 
@@ -542,7 +554,13 @@
         resource.pubsubService.notifyDelete = notifyDelete
         self.assertTrue(verifyObject(iwokkel.IPubSubResource, resource))
         self.assertNotIdentical(None, resource.backend.preDeleteFn)
-        data = {'nodeIdentifier': 'test'}
+        
+        class TestNode:
+            implements(iidavoll.ILeafNode)
+            nodeIdentifier = 'test'
+            nodeType = 'leaf'
+
+        data = {'node': TestNode()}
         d2 = resource.backend.preDeleteFn(data)
         return defer.DeferredList([d1, d2], fireOnOneErrback=1)
 
@@ -578,7 +596,13 @@
         resource.pubsubService.notifyDelete = notifyDelete
         self.assertTrue(verifyObject(iwokkel.IPubSubResource, resource))
         self.assertNotIdentical(None, resource.backend.preDeleteFn)
-        data = {'nodeIdentifier': 'test',
+
+        class TestNode:
+            implements(iidavoll.ILeafNode)
+            nodeIdentifier = 'test'
+            nodeType = 'leaf'
+
+        data = {'node': TestNode(),
                 'redirectURI': uri}
         d2 = resource.backend.preDeleteFn(data)
         return defer.DeferredList([d1, d2], fireOnOneErrback=1)