comparison idavoll/test/test_storage.py @ 139:8f6956b9a688

Follow API change in Twisted Xish, while still being compatible with Twisted Xish 0.1.0.
author Ralph Meijer <ralphm@ik.nu>
date Wed, 27 Apr 2005 19:45:41 +0000
parents 635e433810ef
children 812300cdbc22
comparison
equal deleted inserted replaced
138:635e433810ef 139:8f6956b9a688
29 pubsub.NS_PUBSUB) 29 pubsub.NS_PUBSUB)
30 ITEM_TO_NOT_BE_DELETED['id'] = 'to-not-be-deleted' 30 ITEM_TO_NOT_BE_DELETED['id'] = 'to-not-be-deleted'
31 ITEM_TO_NOT_BE_DELETED.addElement(('testns', 'test'), 31 ITEM_TO_NOT_BE_DELETED.addElement(('testns', 'test'),
32 content=u'Test \u2083 item') 32 content=u'Test \u2083 item')
33 33
34 def decode(object):
35 if isinstance(object, str):
36 object = object.decode('utf-8')
37 return object
38
34 class StorageTests: 39 class StorageTests:
35 40
36 def _assignTestNode(self, node): 41 def _assignTestNode(self, node):
37 self.node = node 42 self.node = node
38 43
223 def testStoreItems(self): 228 def testStoreItems(self):
224 def cb1(void): 229 def cb1(void):
225 return self.node.get_items_by_id(['new']) 230 return self.node.get_items_by_id(['new'])
226 231
227 def cb2(result): 232 def cb2(result):
228 assertEqual(result[0], unicode(ITEM_NEW.toXml(), 'utf-8')) 233 assertEqual(result[0], decode(ITEM_NEW.toXml()))
229 234
230 d = self.node.store_items([ITEM_NEW], PUBLISHER) 235 d = self.node.store_items([ITEM_NEW], PUBLISHER)
231 d.addCallback(cb1) 236 d.addCallback(cb1)
232 d.addCallback(cb2) 237 d.addCallback(cb2)
233 return d 238 return d
235 def testStoreUpdatedItems(self): 240 def testStoreUpdatedItems(self):
236 def cb1(void): 241 def cb1(void):
237 return self.node.get_items_by_id(['current']) 242 return self.node.get_items_by_id(['current'])
238 243
239 def cb2(result): 244 def cb2(result):
240 assertEqual(result[0], unicode(ITEM_UPDATED.toXml(), 'utf-8')) 245 assertEqual(result[0], decode(ITEM_UPDATED.toXml()))
241 246
242 d = self.node.store_items([ITEM_UPDATED], PUBLISHER) 247 d = self.node.store_items([ITEM_UPDATED], PUBLISHER)
243 d.addCallback(cb1) 248 d.addCallback(cb1)
244 d.addCallback(cb2) 249 d.addCallback(cb2)
245 return d 250 return d
261 assertFailure(d, storage.ItemNotFound) 266 assertFailure(d, storage.ItemNotFound)
262 return d 267 return d
263 268
264 def testGetItems(self): 269 def testGetItems(self):
265 def cb(result): 270 def cb(result):
266 assertIn(unicode(ITEM.toXml(), 'utf-8'), result) 271 assertIn(decode(ITEM.toXml()), result)
267 272
268 d = self.node.get_items() 273 d = self.node.get_items()
269 d.addCallback(cb) 274 d.addCallback(cb)
270 return d 275 return d
271 276
272 def testLastItem(self): 277 def testLastItem(self):
273 def cb(result): 278 def cb(result):
274 assertEqual([unicode(ITEM.toXml(), 'utf-8')], result) 279 assertEqual([decode(ITEM.toXml())], result)
275 280
276 d = self.node.get_items(1) 281 d = self.node.get_items(1)
277 d.addCallback(cb) 282 d.addCallback(cb)
278 return d 283 return d
279 284
331 subscriptions[SUBSCRIBER_TO_BE_DELETED.full()] = \ 336 subscriptions[SUBSCRIBER_TO_BE_DELETED.full()] = \
332 Subscription('subscribed') 337 Subscription('subscribed')
333 subscriptions[SUBSCRIBER_PENDING.full()] = \ 338 subscriptions[SUBSCRIBER_PENDING.full()] = \
334 Subscription('pending') 339 Subscription('pending')
335 340
336 item = (ITEM_TO_BE_DELETED.toXml(), PUBLISHER) 341 item = (decode(ITEM_TO_BE_DELETED.toXml()), PUBLISHER)
337 self.s._nodes['pre-existing']._items['to-be-deleted'] = item 342 self.s._nodes['pre-existing']._items['to-be-deleted'] = item
338 self.s._nodes['pre-existing']._itemlist.append(item) 343 self.s._nodes['pre-existing']._itemlist.append(item)
339 self.s._nodes['pre-existing']._items['to-not-be-deleted'] = item 344 self.s._nodes['pre-existing']._items['to-not-be-deleted'] = item
340 self.s._nodes['pre-existing']._itemlist.append(item) 345 self.s._nodes['pre-existing']._itemlist.append(item)
341 self.s._nodes['to-be-purged']._items['to-be-deleted'] = item 346 self.s._nodes['to-be-purged']._items['to-be-deleted'] = item
342 self.s._nodes['to-be-purged']._itemlist.append(item) 347 self.s._nodes['to-be-purged']._itemlist.append(item)
343 item = (ITEM.toXml(), PUBLISHER) 348 item = (decode(ITEM.toXml()), PUBLISHER)
344 self.s._nodes['pre-existing']._items['current'] = item 349 self.s._nodes['pre-existing']._items['current'] = item
345 self.s._nodes['pre-existing']._itemlist.append(item) 350 self.s._nodes['pre-existing']._itemlist.append(item)
346 351
347 return StorageTests.setUpClass(self) 352 return StorageTests.setUpClass(self)
348 353