143
|
1 from twisted.trial import unittest |
|
2 from twisted.trial.assertions import * |
|
3 from zope.interface import implements |
|
4 from twisted.internet import defer |
|
5 from twisted.words.protocols.jabber import jid |
|
6 |
|
7 from idavoll import backend, storage |
|
8 |
|
9 OWNER = jid.JID('owner@example.com') |
|
10 |
|
11 class testNode: |
|
12 id = 'to-be-deleted' |
|
13 def get_affiliation(self, entity): |
|
14 if entity is OWNER: |
|
15 return defer.succeed('owner') |
|
16 |
|
17 class testStorage: |
|
18 |
|
19 implements(storage.IStorage) |
|
20 |
|
21 def get_node(self, node_id): |
|
22 return defer.succeed(testNode()) |
|
23 |
|
24 def delete_node(self, node_id): |
|
25 if node_id in ['to-be-deleted']: |
|
26 self.backend.delete_called = True |
|
27 return defer.succeed(None) |
|
28 else: |
|
29 return defer.fail(storage.NodeNotFound()) |
|
30 |
|
31 class NodeDeletionServiceTests: |
|
32 pre_delete_called = False |
|
33 delete_called = False |
|
34 |
|
35 def setUpClass(self): |
|
36 self.storage = testStorage() |
|
37 self.storage.backend = self |
|
38 |
|
39 def testDeleteNode(self): |
|
40 def pre_delete(node_id): |
|
41 self.pre_delete_called = True |
|
42 return defer.succeed(None) |
|
43 |
|
44 def cb(result): |
|
45 assert_(self.pre_delete_called) |
|
46 assert_(self.delete_called) |
|
47 |
|
48 self.backend.register_pre_delete(pre_delete) |
|
49 d = self.backend.delete_node('to-be-deleted', OWNER) |
|
50 d.addCallback(cb) |
|
51 |
|
52 class GenericNodeDeletionServiceTestCase(unittest.TestCase, |
|
53 NodeDeletionServiceTests): |
|
54 |
|
55 def setUpClass(self): |
|
56 NodeDeletionServiceTests.setUpClass(self) |
|
57 from idavoll.generic_backend import BackendService, NodeDeletionService |
|
58 bs = BackendService(self.storage) |
|
59 self.backend = NodeDeletionService() |
|
60 self.backend.setServiceParent(bs) |