comparison 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
comparison
equal deleted inserted replaced
166:5abb017bd687 167:ef22e4150caa
1 # Copyright (c) 2003-2006 Ralph Meijer 1 # Copyright (c) 2003-2007 Ralph Meijer
2 # See LICENSE for details. 2 # See LICENSE for details.
3
4 """
5 Tests for L{idavoll.backend}.
6 """
3 7
4 from twisted.trial import unittest 8 from twisted.trial import unittest
5 from zope.interface import implements 9 from zope.interface import implements
6 from twisted.internet import defer 10 from twisted.internet import defer
7 from twisted.words.protocols.jabber import jid 11 from twisted.words.protocols.jabber import jid
8 12
9 from idavoll import backend, storage 13 from idavoll import backend, error, iidavoll
10 14
11 OWNER = jid.JID('owner@example.com') 15 OWNER = jid.JID('owner@example.com')
12 16
13 class testNode: 17 class testNode:
14 id = 'to-be-deleted' 18 id = 'to-be-deleted'
16 if entity is OWNER: 20 if entity is OWNER:
17 return defer.succeed('owner') 21 return defer.succeed('owner')
18 22
19 class testStorage: 23 class testStorage:
20 24
21 implements(storage.IStorage) 25 implements(iidavoll.IStorage)
22 26
23 def get_node(self, node_id): 27 def get_node(self, node_id):
24 return defer.succeed(testNode()) 28 return defer.succeed(testNode())
25 29
26 def delete_node(self, node_id): 30 def delete_node(self, node_id):
27 if node_id in ['to-be-deleted']: 31 if node_id in ['to-be-deleted']:
28 self.backend.delete_called = True 32 self.delete_called = True
29 return defer.succeed(None) 33 return defer.succeed(None)
30 else: 34 else:
31 return defer.fail(storage.NodeNotFound()) 35 return defer.fail(error.NodeNotFound())
32 36
33 class NodeDeletionServiceTests: 37 class BackendTest(unittest.TestCase):
34 pre_delete_called = False 38 def setUp(self):
35 delete_called = False 39 self.storage = testStorage()
40 self.backend = backend.BackendService(self.storage)
41 self.storage.backend = self.backend
36 42
37 def setUpClass(self): 43 self.pre_delete_called = False
38 self.storage = testStorage() 44 self.delete_called = False
39 self.storage.backend = self
40 45
41 def testDeleteNode(self): 46 def testDeleteNode(self):
42 def pre_delete(node_id): 47 def pre_delete(node_id):
43 self.pre_delete_called = True 48 self.pre_delete_called = True
44 return defer.succeed(None) 49 return defer.succeed(None)
45 50
46 def cb(result): 51 def cb(result):
47 self.assert_(self.pre_delete_called) 52 self.assertTrue(self.pre_delete_called)
48 self.assert_(self.delete_called) 53 self.assertTrue(self.storage.delete_called)
49 54
50 self.backend.register_pre_delete(pre_delete) 55 self.backend.register_pre_delete(pre_delete)
51 d = self.backend.delete_node('to-be-deleted', OWNER) 56 d = self.backend.delete_node('to-be-deleted', OWNER)
52 d.addCallback(cb) 57 d.addCallback(cb)
53 58 return d
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)