Mercurial > libervia-pubsub
annotate idavoll/test/test_backend.py @ 155:5191ba7c4df8
Work towards first release 0.5.0.
- Add licensing information (MIT)
- Improve installation instructions.
- Use new plugins framework in twisted.
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Mon, 21 Aug 2006 16:05:35 +0000 |
parents | 48244f3c0c93 |
children | 21fcfb86433f |
rev | line source |
---|---|
155
5191ba7c4df8
Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents:
143
diff
changeset
|
1 # Copyright (c) 2003-2006 Ralph Meijer |
5191ba7c4df8
Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents:
143
diff
changeset
|
2 # See LICENSE for details. |
5191ba7c4df8
Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents:
143
diff
changeset
|
3 |
143 | 4 from twisted.trial import unittest |
5 from twisted.trial.assertions import * | |
6 from zope.interface import implements | |
7 from twisted.internet import defer | |
8 from twisted.words.protocols.jabber import jid | |
9 | |
10 from idavoll import backend, storage | |
11 | |
12 OWNER = jid.JID('owner@example.com') | |
13 | |
14 class testNode: | |
15 id = 'to-be-deleted' | |
16 def get_affiliation(self, entity): | |
17 if entity is OWNER: | |
18 return defer.succeed('owner') | |
19 | |
20 class testStorage: | |
21 | |
22 implements(storage.IStorage) | |
23 | |
24 def get_node(self, node_id): | |
25 return defer.succeed(testNode()) | |
26 | |
27 def delete_node(self, node_id): | |
28 if node_id in ['to-be-deleted']: | |
29 self.backend.delete_called = True | |
30 return defer.succeed(None) | |
31 else: | |
32 return defer.fail(storage.NodeNotFound()) | |
33 | |
34 class NodeDeletionServiceTests: | |
35 pre_delete_called = False | |
36 delete_called = False | |
37 | |
38 def setUpClass(self): | |
39 self.storage = testStorage() | |
40 self.storage.backend = self | |
41 | |
42 def testDeleteNode(self): | |
43 def pre_delete(node_id): | |
44 self.pre_delete_called = True | |
45 return defer.succeed(None) | |
46 | |
47 def cb(result): | |
48 assert_(self.pre_delete_called) | |
49 assert_(self.delete_called) | |
50 | |
51 self.backend.register_pre_delete(pre_delete) | |
52 d = self.backend.delete_node('to-be-deleted', OWNER) | |
53 d.addCallback(cb) | |
54 | |
55 class GenericNodeDeletionServiceTestCase(unittest.TestCase, | |
56 NodeDeletionServiceTests): | |
57 | |
58 def setUpClass(self): | |
59 NodeDeletionServiceTests.setUpClass(self) | |
60 from idavoll.generic_backend import BackendService, NodeDeletionService | |
61 bs = BackendService(self.storage) | |
62 self.backend = NodeDeletionService() | |
63 self.backend.setServiceParent(bs) |