Mercurial > libervia-pubsub
annotate idavoll/test/test_backend.py @ 164:40d931ed15b9
Make imports work with Twisted 0.5.0.
Author: ralphm
Fixes #3
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Thu, 18 Jan 2007 13:52:39 +0000 |
parents | 21fcfb86433f |
children | ef22e4150caa |
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 zope.interface import implements | |
6 from twisted.internet import defer | |
7 from twisted.words.protocols.jabber import jid | |
8 | |
9 from idavoll import backend, storage | |
10 | |
11 OWNER = jid.JID('owner@example.com') | |
12 | |
13 class testNode: | |
14 id = 'to-be-deleted' | |
15 def get_affiliation(self, entity): | |
16 if entity is OWNER: | |
17 return defer.succeed('owner') | |
18 | |
19 class testStorage: | |
20 | |
21 implements(storage.IStorage) | |
22 | |
23 def get_node(self, node_id): | |
24 return defer.succeed(testNode()) | |
25 | |
26 def delete_node(self, node_id): | |
27 if node_id in ['to-be-deleted']: | |
28 self.backend.delete_called = True | |
29 return defer.succeed(None) | |
30 else: | |
31 return defer.fail(storage.NodeNotFound()) | |
32 | |
33 class NodeDeletionServiceTests: | |
34 pre_delete_called = False | |
35 delete_called = False | |
36 | |
37 def setUpClass(self): | |
38 self.storage = testStorage() | |
39 self.storage.backend = self | |
40 | |
41 def testDeleteNode(self): | |
42 def pre_delete(node_id): | |
43 self.pre_delete_called = True | |
44 return defer.succeed(None) | |
45 | |
46 def cb(result): | |
157
21fcfb86433f
Fix tests to work with current Twisted. Really do 0.5.0 release.
Ralph Meijer <ralphm@ik.nu>
parents:
155
diff
changeset
|
47 self.assert_(self.pre_delete_called) |
21fcfb86433f
Fix tests to work with current Twisted. Really do 0.5.0 release.
Ralph Meijer <ralphm@ik.nu>
parents:
155
diff
changeset
|
48 self.assert_(self.delete_called) |
143 | 49 |
50 self.backend.register_pre_delete(pre_delete) | |
51 d = self.backend.delete_node('to-be-deleted', OWNER) | |
52 d.addCallback(cb) | |
53 | |
54 class GenericNodeDeletionServiceTestCase(unittest.TestCase, | |
55 NodeDeletionServiceTests): | |
56 | |
57 def setUpClass(self): | |
58 NodeDeletionServiceTests.setUpClass(self) | |
59 from idavoll.generic_backend import BackendService, NodeDeletionService | |
60 bs = BackendService(self.storage) | |
61 self.backend = NodeDeletionService() | |
62 self.backend.setServiceParent(bs) |