Mercurial > libervia-pubsub
comparison 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 |
comparison
equal
deleted
inserted
replaced
265:89493845d3dd | 266:560b6cdc50b2 |
---|---|
64 from twisted.words.protocols.jabber import jid | 64 from twisted.words.protocols.jabber import jid |
65 from twisted.words.protocols.jabber.error import StanzaError | 65 from twisted.words.protocols.jabber.error import StanzaError |
66 | 66 |
67 from wokkel import iwokkel, pubsub | 67 from wokkel import iwokkel, pubsub |
68 | 68 |
69 from sat_pubsub import backend, error, iidavoll | 69 from sat_pubsub import backend, error, iidavoll, const |
70 | 70 |
71 OWNER = jid.JID('owner@example.com') | 71 OWNER = jid.JID('owner@example.com') |
72 OWNER_FULL = jid.JID('owner@example.com/home') | 72 OWNER_FULL = jid.JID('owner@example.com/home') |
73 SERVICE = jid.JID('test.example.org') | 73 SERVICE = jid.JID('test.example.org') |
74 NS_PUBSUB = 'http://jabber.org/protocol/pubsub' | 74 NS_PUBSUB = 'http://jabber.org/protocol/pubsub' |
107 return defer.succeed(None) | 107 return defer.succeed(None) |
108 | 108 |
109 def cb(result): | 109 def cb(result): |
110 self.assertEquals(1, len(preDeleteCalled)) | 110 self.assertEquals(1, len(preDeleteCalled)) |
111 data = preDeleteCalled[-1] | 111 data = preDeleteCalled[-1] |
112 self.assertEquals('to-be-deleted', data['nodeIdentifier']) | 112 self.assertEquals('to-be-deleted', data['node'].nodeIdentifier) |
113 self.assertTrue(self.storage.deleteCalled) | 113 self.assertTrue(self.storage.deleteCalled) |
114 | 114 |
115 self.storage = TestStorage() | 115 self.storage = TestStorage() |
116 self.backend = backend.BackendService(self.storage) | 116 self.backend = backend.BackendService(self.storage) |
117 | 117 |
152 return defer.succeed(None) | 152 return defer.succeed(None) |
153 | 153 |
154 def cb(result): | 154 def cb(result): |
155 self.assertEquals(1, len(preDeleteCalled)) | 155 self.assertEquals(1, len(preDeleteCalled)) |
156 data = preDeleteCalled[-1] | 156 data = preDeleteCalled[-1] |
157 self.assertEquals('to-be-deleted', data['nodeIdentifier']) | 157 self.assertEquals('to-be-deleted', data['node'].nodeIdentifier) |
158 self.assertEquals(uri, data['redirectURI']) | 158 self.assertEquals(uri, data['redirectURI']) |
159 self.assertTrue(self.storage.deleteCalled) | 159 self.assertTrue(self.storage.deleteCalled) |
160 | 160 |
161 self.storage = TestStorage() | 161 self.storage = TestStorage() |
162 self.backend = backend.BackendService(self.storage) | 162 self.backend = backend.BackendService(self.storage) |
397 def getAffiliation(self, entity): | 397 def getAffiliation(self, entity): |
398 if entity.userhostJID() == OWNER: | 398 if entity.userhostJID() == OWNER: |
399 return defer.succeed('owner') | 399 return defer.succeed('owner') |
400 def getConfiguration(self): | 400 def getConfiguration(self): |
401 return {'pubsub#deliver_payloads': True, | 401 return {'pubsub#deliver_payloads': True, |
402 'pubsub#persist_items': False} | 402 'pubsub#persist_items': False, |
403 const.OPT_PUBLISH_MODEL: const.VAL_PMODEL_OPEN} | |
403 | 404 |
404 class TestStorage: | 405 class TestStorage: |
405 def getNode(self, nodeIdentifier): | 406 def getNode(self, nodeIdentifier): |
406 return defer.succeed(TestNode()) | 407 return defer.succeed(TestNode()) |
407 | 408 |
408 def checkID(notification): | 409 def checkID(notification): |
409 self.assertNotIdentical(None, notification['items'][0]['id']) | 410 self.assertNotIdentical(None, notification['items'][0][2]['id']) |
410 | 411 |
411 self.storage = TestStorage() | 412 self.storage = TestStorage() |
412 self.backend = backend.BackendService(self.storage) | 413 self.backend = backend.BackendService(self.storage) |
413 self.storage.backend = self.backend | 414 self.storage.backend = self.backend |
414 | 415 |
433 if entity is OWNER: | 434 if entity is OWNER: |
434 return defer.succeed('owner') | 435 return defer.succeed('owner') |
435 def getConfiguration(self): | 436 def getConfiguration(self): |
436 return {'pubsub#deliver_payloads': True, | 437 return {'pubsub#deliver_payloads': True, |
437 'pubsub#persist_items': False, | 438 'pubsub#persist_items': False, |
438 'pubsub#send_last_published_item': 'on_sub'} | 439 'pubsub#send_last_published_item': 'on_sub', |
439 def getItems(self, maxItems): | 440 const.OPT_ACCESS_MODEL: const.VAL_AMODEL_OPEN} |
440 return [ITEM] | 441 def getItems(self, authorized_groups, unrestricted, maxItems): |
442 return defer.succeed([(ITEM, const.VAL_AMODEL_OPEN, None)]) | |
441 def addSubscription(self, subscriber, state, options): | 443 def addSubscription(self, subscriber, state, options): |
442 self.subscription = pubsub.Subscription('node', subscriber, | 444 self.subscription = pubsub.Subscription('node', subscriber, |
443 state, options) | 445 state, options) |
444 return defer.succeed(None) | 446 return defer.succeed(None) |
445 def getSubscription(self, subscriber): | 447 def getSubscription(self, subscriber): |
446 return defer.succeed(self.subscription) | 448 return defer.succeed(self.subscription) |
449 def getNodeOwner(self): | |
450 return defer.succeed(OWNER) | |
447 | 451 |
448 class TestStorage: | 452 class TestStorage: |
449 def getNode(self, nodeIdentifier): | 453 def getNode(self, nodeIdentifier): |
450 return defer.succeed(TestNode()) | 454 return defer.succeed(TestNode()) |
451 | 455 |
452 def cb(data): | 456 def cb(data): |
453 self.assertEquals('node', data['nodeIdentifier']) | 457 self.assertEquals('node', data['node'].nodeIdentifier) |
454 self.assertEquals([ITEM], data['items']) | 458 self.assertEquals([ITEM], data['items']) |
455 self.assertEquals(OWNER, data['subscription'].subscriber) | 459 self.assertEquals(OWNER, data['subscription'].subscriber) |
456 | 460 |
457 self.storage = TestStorage() | 461 self.storage = TestStorage() |
458 self.backend = backend.BackendService(self.storage) | 462 self.backend = backend.BackendService(self.storage) |
459 self.storage.backend = self.backend | 463 self.storage.backend = self.backend |
464 | |
465 class Roster(object): | |
466 def getRoster(self, owner): | |
467 return {} | |
468 self.backend.roster = Roster() | |
460 | 469 |
461 d1 = defer.Deferred() | 470 d1 = defer.Deferred() |
462 d1.addCallback(cb) | 471 d1.addCallback(cb) |
463 self.backend.registerNotifier(d1.callback) | 472 self.backend.registerNotifier(d1.callback) |
464 d2 = self.backend.subscribe('node', OWNER, OWNER_FULL) | 473 d2 = self.backend.subscribe('node', OWNER, OWNER_FULL) |
493 | 502 |
494 def supportsAutoCreate(self): | 503 def supportsAutoCreate(self): |
495 return True | 504 return True |
496 | 505 |
497 def supportsCreatorCheck(self): | 506 def supportsCreatorCheck(self): |
507 return True | |
508 | |
509 def supportsGroupBlog(self): | |
498 return True | 510 return True |
499 | 511 |
500 def registerNotifier(self, observerfn, *args, **kwargs): | 512 def registerNotifier(self, observerfn, *args, **kwargs): |
501 return | 513 return |
502 | 514 |
540 resource.serviceJID = SERVICE | 552 resource.serviceJID = SERVICE |
541 resource.pubsubService = pubsub.PubSubService() | 553 resource.pubsubService = pubsub.PubSubService() |
542 resource.pubsubService.notifyDelete = notifyDelete | 554 resource.pubsubService.notifyDelete = notifyDelete |
543 self.assertTrue(verifyObject(iwokkel.IPubSubResource, resource)) | 555 self.assertTrue(verifyObject(iwokkel.IPubSubResource, resource)) |
544 self.assertNotIdentical(None, resource.backend.preDeleteFn) | 556 self.assertNotIdentical(None, resource.backend.preDeleteFn) |
545 data = {'nodeIdentifier': 'test'} | 557 |
558 class TestNode: | |
559 implements(iidavoll.ILeafNode) | |
560 nodeIdentifier = 'test' | |
561 nodeType = 'leaf' | |
562 | |
563 data = {'node': TestNode()} | |
546 d2 = resource.backend.preDeleteFn(data) | 564 d2 = resource.backend.preDeleteFn(data) |
547 return defer.DeferredList([d1, d2], fireOnOneErrback=1) | 565 return defer.DeferredList([d1, d2], fireOnOneErrback=1) |
548 | 566 |
549 | 567 |
550 def test_preDeleteRedirect(self): | 568 def test_preDeleteRedirect(self): |
576 resource.serviceJID = SERVICE | 594 resource.serviceJID = SERVICE |
577 resource.pubsubService = pubsub.PubSubService() | 595 resource.pubsubService = pubsub.PubSubService() |
578 resource.pubsubService.notifyDelete = notifyDelete | 596 resource.pubsubService.notifyDelete = notifyDelete |
579 self.assertTrue(verifyObject(iwokkel.IPubSubResource, resource)) | 597 self.assertTrue(verifyObject(iwokkel.IPubSubResource, resource)) |
580 self.assertNotIdentical(None, resource.backend.preDeleteFn) | 598 self.assertNotIdentical(None, resource.backend.preDeleteFn) |
581 data = {'nodeIdentifier': 'test', | 599 |
600 class TestNode: | |
601 implements(iidavoll.ILeafNode) | |
602 nodeIdentifier = 'test' | |
603 nodeType = 'leaf' | |
604 | |
605 data = {'node': TestNode(), | |
582 'redirectURI': uri} | 606 'redirectURI': uri} |
583 d2 = resource.backend.preDeleteFn(data) | 607 d2 = resource.backend.preDeleteFn(data) |
584 return defer.DeferredList([d1, d2], fireOnOneErrback=1) | 608 return defer.DeferredList([d1, d2], fireOnOneErrback=1) |
585 | 609 |
586 | 610 |