Mercurial > libervia-pubsub
changeset 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 | 89493845d3dd |
children | 604a92be5288 |
files | sat_pubsub/test/test_backend.py sat_pubsub/test/test_storage.py |
diffstat | 2 files changed, 47 insertions(+), 23 deletions(-) [+] |
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)
--- a/sat_pubsub/test/test_storage.py Sat Feb 22 08:04:09 2014 +0100 +++ b/sat_pubsub/test/test_storage.py Sat Feb 22 08:05:03 2014 +0100 @@ -62,7 +62,7 @@ from twisted.internet import defer from twisted.words.xish import domish -from sat_pubsub import error, iidavoll +from sat_pubsub import error, iidavoll, const OWNER = jid.JID('owner@example.com/Work') SUBSCRIBER = jid.JID('subscriber@example.com/Home') @@ -166,6 +166,7 @@ "pubsub#send_last_published_item": 'on_sub', "pubsub#node_type": 'leaf', "pubsub#access_model": 'open', + const.OPT_PUBLISH_MODEL: const.VAL_PMODEL_OPEN } def unsetPersistItems(_): @@ -363,12 +364,12 @@ def test_storeItems(self): def cb1(void): - return self.node.getItemsById(['new']) + return self.node.getItemsById("", False, ['new']) def cb2(result): self.assertEqual(ITEM_NEW.toXml(), result[0].toXml()) - d = self.node.storeItems([ITEM_NEW], PUBLISHER) + d = self.node.storeItems([(const.VAL_AMODEL_DEFAULT, {}, ITEM_NEW)], PUBLISHER) d.addCallback(cb1) d.addCallback(cb2) return d @@ -376,12 +377,12 @@ def test_storeUpdatedItems(self): def cb1(void): - return self.node.getItemsById(['current']) + return self.node.getItemsById("", False, ['current']) def cb2(result): self.assertEqual(ITEM_UPDATED.toXml(), result[0].toXml()) - d = self.node.storeItems([ITEM_UPDATED], PUBLISHER) + d = self.node.storeItems([(const.VAL_AMODEL_DEFAULT, {}, ITEM_UPDATED)], PUBLISHER) d.addCallback(cb1) d.addCallback(cb2) return d @@ -390,7 +391,7 @@ def test_removeItems(self): def cb1(result): self.assertEqual(['to-be-deleted'], result) - return self.node.getItemsById(['to-be-deleted']) + return self.node.getItemsById("", False, ['to-be-deleted']) def cb2(result): self.assertEqual(0, len(result)) @@ -414,8 +415,7 @@ def cb(result): items = [item.toXml() for item in result] self.assertIn(ITEM.toXml(), items) - - d = self.node.getItems() + d = self.node.getItems("", False) d.addCallback(cb) return d @@ -425,7 +425,7 @@ self.assertEqual(1, len(result)) self.assertEqual(ITEM.toXml(), result[0].toXml()) - d = self.node.getItems(1) + d = self.node.getItems("", False, 1) d.addCallback(cb) return d @@ -434,7 +434,7 @@ def cb(result): self.assertEqual(1, len(result)) - d = self.node.getItemsById(['current']) + d = self.node.getItemsById("", False, ['current']) d.addCallback(cb) return d @@ -443,7 +443,7 @@ def cb(result): self.assertEqual(0, len(result)) - d = self.node.getItemsById(['non-existing']) + d = self.node.getItemsById("", False, ['non-existing']) d.addCallback(cb) return d @@ -455,7 +455,7 @@ return d def cb2(node): - return node.getItems() + return node.getItems("", False) def cb3(result): self.assertEqual([], result)