Mercurial > libervia-pubsub
annotate idavoll/test/test_backend.py @ 167:ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Author: ralphm
Fixes: #4
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Wed, 03 Oct 2007 12:41:43 +0000 |
parents | 21fcfb86433f |
children | e2c2c2baf483 |
rev | line source |
---|---|
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
1 # Copyright (c) 2003-2007 Ralph Meijer |
155
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 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
4 """ |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
5 Tests for L{idavoll.backend}. |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
6 """ |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
7 |
143 | 8 from twisted.trial import unittest |
9 from zope.interface import implements | |
10 from twisted.internet import defer | |
11 from twisted.words.protocols.jabber import jid | |
12 | |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
13 from idavoll import backend, error, iidavoll |
143 | 14 |
15 OWNER = jid.JID('owner@example.com') | |
16 | |
17 class testNode: | |
18 id = 'to-be-deleted' | |
19 def get_affiliation(self, entity): | |
20 if entity is OWNER: | |
21 return defer.succeed('owner') | |
22 | |
23 class testStorage: | |
24 | |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
25 implements(iidavoll.IStorage) |
143 | 26 |
27 def get_node(self, node_id): | |
28 return defer.succeed(testNode()) | |
29 | |
30 def delete_node(self, node_id): | |
31 if node_id in ['to-be-deleted']: | |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
32 self.delete_called = True |
143 | 33 return defer.succeed(None) |
34 else: | |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
35 return defer.fail(error.NodeNotFound()) |
143 | 36 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
37 class BackendTest(unittest.TestCase): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
38 def setUp(self): |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
39 self.storage = testStorage() |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
40 self.backend = backend.BackendService(self.storage) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
41 self.storage.backend = self.backend |
143 | 42 |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
43 self.pre_delete_called = False |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
44 self.delete_called = False |
143 | 45 |
46 def testDeleteNode(self): | |
47 def pre_delete(node_id): | |
48 self.pre_delete_called = True | |
49 return defer.succeed(None) | |
50 | |
51 def cb(result): | |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
52 self.assertTrue(self.pre_delete_called) |
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
53 self.assertTrue(self.storage.delete_called) |
143 | 54 |
55 self.backend.register_pre_delete(pre_delete) | |
56 d = self.backend.delete_node('to-be-deleted', OWNER) | |
57 d.addCallback(cb) | |
167
ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents:
157
diff
changeset
|
58 return d |