comparison idavoll/test/test_storage.py @ 142:812300cdbc22

Changed behaviour of retraction of items so that only the actually deleted item ids are returned, and no exception is raised for items that didn't actually exists.
author Ralph Meijer <ralphm@ik.nu>
date Tue, 12 Jul 2005 09:23:00 +0000
parents 8f6956b9a688
children f393bccec4bc
comparison
equal deleted inserted replaced
141:d2c18d88f618 142:812300cdbc22
23 ITEM_UPDATED.addElement(('testns', 'test'), content=u'Test \u2084 item') 23 ITEM_UPDATED.addElement(('testns', 'test'), content=u'Test \u2084 item')
24 ITEM_TO_BE_DELETED = domish.Element((pubsub.NS_PUBSUB, 'item'), 24 ITEM_TO_BE_DELETED = domish.Element((pubsub.NS_PUBSUB, 'item'),
25 pubsub.NS_PUBSUB) 25 pubsub.NS_PUBSUB)
26 ITEM_TO_BE_DELETED['id'] = 'to-be-deleted' 26 ITEM_TO_BE_DELETED['id'] = 'to-be-deleted'
27 ITEM_TO_BE_DELETED.addElement(('testns', 'test'), content=u'Test \u2083 item') 27 ITEM_TO_BE_DELETED.addElement(('testns', 'test'), content=u'Test \u2083 item')
28 ITEM_TO_NOT_BE_DELETED = domish.Element((pubsub.NS_PUBSUB, 'item'),
29 pubsub.NS_PUBSUB)
30 ITEM_TO_NOT_BE_DELETED['id'] = 'to-not-be-deleted'
31 ITEM_TO_NOT_BE_DELETED.addElement(('testns', 'test'),
32 content=u'Test \u2083 item')
33 28
34 def decode(object): 29 def decode(object):
35 if isinstance(object, str): 30 if isinstance(object, str):
36 object = object.decode('utf-8') 31 object = object.decode('utf-8')
37 return object 32 return object
248 d.addCallback(cb1) 243 d.addCallback(cb1)
249 d.addCallback(cb2) 244 d.addCallback(cb2)
250 return d 245 return d
251 246
252 def testRemoveItems(self): 247 def testRemoveItems(self):
253 def cb1(void): 248 def cb1(result):
249 assertEqual(result, ['to-be-deleted'])
254 return self.node.get_items_by_id(['to-be-deleted']) 250 return self.node.get_items_by_id(['to-be-deleted'])
255 251
256 def cb2(result): 252 def cb2(result):
257 assertEqual(len(result), 0) 253 assertEqual(len(result), 0)
258 254
260 d.addCallback(cb1) 256 d.addCallback(cb1)
261 d.addCallback(cb2) 257 d.addCallback(cb2)
262 return d 258 return d
263 259
264 def testRemoveNonExistingItems(self): 260 def testRemoveNonExistingItems(self):
265 d = self.node.remove_items(['to-not-be-deleted', 'non-existing']) 261 def cb(result):
266 assertFailure(d, storage.ItemNotFound) 262 assertEqual(result, [])
263
264 d = self.node.remove_items(['non-existing'])
265 d.addCallback(cb)
267 return d 266 return d
268 267
269 def testGetItems(self): 268 def testGetItems(self):
270 def cb(result): 269 def cb(result):
271 assertIn(decode(ITEM.toXml()), result) 270 assertIn(decode(ITEM.toXml()), result)
338 subscriptions[SUBSCRIBER_PENDING.full()] = \ 337 subscriptions[SUBSCRIBER_PENDING.full()] = \
339 Subscription('pending') 338 Subscription('pending')
340 339
341 item = (decode(ITEM_TO_BE_DELETED.toXml()), PUBLISHER) 340 item = (decode(ITEM_TO_BE_DELETED.toXml()), PUBLISHER)
342 self.s._nodes['pre-existing']._items['to-be-deleted'] = item 341 self.s._nodes['pre-existing']._items['to-be-deleted'] = item
343 self.s._nodes['pre-existing']._itemlist.append(item)
344 self.s._nodes['pre-existing']._items['to-not-be-deleted'] = item
345 self.s._nodes['pre-existing']._itemlist.append(item) 342 self.s._nodes['pre-existing']._itemlist.append(item)
346 self.s._nodes['to-be-purged']._items['to-be-deleted'] = item 343 self.s._nodes['to-be-purged']._items['to-be-deleted'] = item
347 self.s._nodes['to-be-purged']._itemlist.append(item) 344 self.s._nodes['to-be-purged']._itemlist.append(item)
348 item = (decode(ITEM.toXml()), PUBLISHER) 345 item = (decode(ITEM.toXml()), PUBLISHER)
349 self.s._nodes['pre-existing']._items['current'] = item 346 self.s._nodes['pre-existing']._items['current'] = item
416 now() - interval '1 day' 413 now() - interval '1 day'
417 FROM nodes 414 FROM nodes
418 WHERE node='pre-existing'""", 415 WHERE node='pre-existing'""",
419 (PUBLISHER.userhost(), 416 (PUBLISHER.userhost(),
420 ITEM_TO_BE_DELETED.toXml())) 417 ITEM_TO_BE_DELETED.toXml()))
421 cursor.execute("""INSERT INTO items
422 (node_id, publisher, item, data, date)
423 SELECT nodes.id, %s, 'to-not-be-deleted', %s,
424 now() - interval '1 day'
425 FROM nodes
426 WHERE node='pre-existing'""",
427 (PUBLISHER.userhost(),
428 ITEM_TO_NOT_BE_DELETED.toXml()))
429 cursor.execute("""INSERT INTO items (node_id, publisher, item, data) 418 cursor.execute("""INSERT INTO items (node_id, publisher, item, data)
430 SELECT nodes.id, %s, 'to-be-deleted', %s 419 SELECT nodes.id, %s, 'to-be-deleted', %s
431 FROM nodes 420 FROM nodes
432 WHERE node='to-be-purged'""", 421 WHERE node='to-be-purged'""",
433 (PUBLISHER.userhost(), 422 (PUBLISHER.userhost(),