annotate idavoll/test/test_backend.py @ 143:48244f3c0c93

Initial revision
author Ralph Meijer <ralphm@ik.nu>
date Tue, 12 Jul 2005 14:46:42 +0000
parents
children 5191ba7c4df8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
143
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
1 from twisted.trial import unittest
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
2 from twisted.trial.assertions import *
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
3 from zope.interface import implements
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
4 from twisted.internet import defer
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
5 from twisted.words.protocols.jabber import jid
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
6
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
7 from idavoll import backend, storage
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
8
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
9 OWNER = jid.JID('owner@example.com')
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
10
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
11 class testNode:
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
12 id = 'to-be-deleted'
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
13 def get_affiliation(self, entity):
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
14 if entity is OWNER:
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
15 return defer.succeed('owner')
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
16
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
17 class testStorage:
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
18
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
19 implements(storage.IStorage)
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
20
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
21 def get_node(self, node_id):
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
22 return defer.succeed(testNode())
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
23
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
24 def delete_node(self, node_id):
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
25 if node_id in ['to-be-deleted']:
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
26 self.backend.delete_called = True
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
27 return defer.succeed(None)
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
28 else:
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
29 return defer.fail(storage.NodeNotFound())
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
30
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
31 class NodeDeletionServiceTests:
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
32 pre_delete_called = False
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
33 delete_called = False
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
34
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
35 def setUpClass(self):
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
36 self.storage = testStorage()
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
37 self.storage.backend = self
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
38
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
39 def testDeleteNode(self):
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
40 def pre_delete(node_id):
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
41 self.pre_delete_called = True
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
42 return defer.succeed(None)
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
43
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
44 def cb(result):
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
45 assert_(self.pre_delete_called)
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
46 assert_(self.delete_called)
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
47
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
48 self.backend.register_pre_delete(pre_delete)
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
49 d = self.backend.delete_node('to-be-deleted', OWNER)
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
50 d.addCallback(cb)
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
51
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
52 class GenericNodeDeletionServiceTestCase(unittest.TestCase,
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
53 NodeDeletionServiceTests):
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
54
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
55 def setUpClass(self):
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
56 NodeDeletionServiceTests.setUpClass(self)
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
57 from idavoll.generic_backend import BackendService, NodeDeletionService
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
58 bs = BackendService(self.storage)
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
59 self.backend = NodeDeletionService()
48244f3c0c93 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
60 self.backend.setServiceParent(bs)