comparison idavoll/test/test_storage.py @ 171:bc269696ef42

Reply with the correct error condition on subscription when not subscribed. Author: ralphm. Fixes #7.
author Ralph Meijer <ralphm@ik.nu>
date Thu, 03 Jan 2008 13:10:25 +0000
parents ef22e4150caa
children e404775b12df
comparison
equal deleted inserted replaced
170:958e69630e52 171:bc269696ef42
1 # Copyright (c) 2003-2007 Ralph Meijer 1 # Copyright (c) 2003-2008 Ralph Meijer
2 # See LICENSE for details. 2 # See LICENSE for details.
3 3
4 """ 4 """
5 Tests for L{idavoll.memory_storage} and L{idavoll.pgsql_storage}. 5 Tests for L{idavoll.memory_storage} and L{idavoll.pgsql_storage}.
6 """ 6 """
37 def decode(object): 37 def decode(object):
38 if isinstance(object, str): 38 if isinstance(object, str):
39 object = object.decode('utf-8') 39 object = object.decode('utf-8')
40 return object 40 return object
41 41
42
42 class StorageTests: 43 class StorageTests:
43 44
44 def _assignTestNode(self, node): 45 def _assignTestNode(self, node):
45 self.node = node 46 self.node = node
46 47
201 def testRemoveSubscription(self): 202 def testRemoveSubscription(self):
202 return self.node.remove_subscription(SUBSCRIBER_TO_BE_DELETED) 203 return self.node.remove_subscription(SUBSCRIBER_TO_BE_DELETED)
203 204
204 def testRemoveNonExistingSubscription(self): 205 def testRemoveNonExistingSubscription(self):
205 d = self.node.remove_subscription(OWNER) 206 d = self.node.remove_subscription(OWNER)
206 self.assertFailure(d, error.SubscriptionNotFound) 207 self.assertFailure(d, error.NotSubscribed)
207 return d 208 return d
208 209
209 def testGetSubscribers(self): 210 def testGetSubscribers(self):
210 def cb(subscribers): 211 def cb(subscribers):
211 self.assertIn(SUBSCRIBER, subscribers) 212 self.assertIn(SUBSCRIBER, subscribers)
335 336
336 d = self.s.get_node('pre-existing') 337 d = self.s.get_node('pre-existing')
337 d.addCallback(cb1) 338 d.addCallback(cb1)
338 d.addCallback(cb2) 339 d.addCallback(cb2)
339 return d 340 return d
341
340 342
341 class MemoryStorageStorageTestCase(unittest.TestCase, StorageTests): 343 class MemoryStorageStorageTestCase(unittest.TestCase, StorageTests):
342 344
343 def setUp(self): 345 def setUp(self):
344 from idavoll.memory_storage import Storage, LeafNode, Subscription, \ 346 from idavoll.memory_storage import Storage, LeafNode, Subscription, \
368 item = (decode(ITEM.toXml()), PUBLISHER) 370 item = (decode(ITEM.toXml()), PUBLISHER)
369 self.s._nodes['pre-existing']._items['current'] = item 371 self.s._nodes['pre-existing']._items['current'] = item
370 self.s._nodes['pre-existing']._itemlist.append(item) 372 self.s._nodes['pre-existing']._itemlist.append(item)
371 373
372 return StorageTests.setUp(self) 374 return StorageTests.setUp(self)
375
373 376
374 class PgsqlStorageStorageTestCase(unittest.TestCase, StorageTests): 377 class PgsqlStorageStorageTestCase(unittest.TestCase, StorageTests):
375 def _callSuperSetUp(self, void): 378 def _callSuperSetUp(self, void):
376 return StorageTests.setUp(self) 379 return StorageTests.setUp(self)
377 380