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