Mercurial > libervia-pubsub
comparison idavoll/test/test_storage.py @ 202:77c61e2b8c75
Use `domish.Element`s to represent items, instead of serialized XML.
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Wed, 25 Jun 2008 12:27:55 +0000 |
parents | e404775b12df |
children | b4bf0a5ce50d |
comparison
equal
deleted
inserted
replaced
201:d829db6095d6 | 202:77c61e2b8c75 |
---|---|
259 def test_storeItems(self): | 259 def test_storeItems(self): |
260 def cb1(void): | 260 def cb1(void): |
261 return self.node.getItemsById(['new']) | 261 return self.node.getItemsById(['new']) |
262 | 262 |
263 def cb2(result): | 263 def cb2(result): |
264 self.assertEqual(result[0], decode(ITEM_NEW.toXml())) | 264 self.assertEqual(ITEM_NEW.toXml(), result[0].toXml()) |
265 | 265 |
266 d = self.node.storeItems([ITEM_NEW], PUBLISHER) | 266 d = self.node.storeItems([ITEM_NEW], PUBLISHER) |
267 d.addCallback(cb1) | 267 d.addCallback(cb1) |
268 d.addCallback(cb2) | 268 d.addCallback(cb2) |
269 return d | 269 return d |
272 def test_storeUpdatedItems(self): | 272 def test_storeUpdatedItems(self): |
273 def cb1(void): | 273 def cb1(void): |
274 return self.node.getItemsById(['current']) | 274 return self.node.getItemsById(['current']) |
275 | 275 |
276 def cb2(result): | 276 def cb2(result): |
277 self.assertEqual(result[0], decode(ITEM_UPDATED.toXml())) | 277 self.assertEqual(ITEM_UPDATED.toXml(), result[0].toXml()) |
278 | 278 |
279 d = self.node.storeItems([ITEM_UPDATED], PUBLISHER) | 279 d = self.node.storeItems([ITEM_UPDATED], PUBLISHER) |
280 d.addCallback(cb1) | 280 d.addCallback(cb1) |
281 d.addCallback(cb2) | 281 d.addCallback(cb2) |
282 return d | 282 return d |
283 | 283 |
284 | 284 |
285 def test_removeItems(self): | 285 def test_removeItems(self): |
286 def cb1(result): | 286 def cb1(result): |
287 self.assertEqual(result, ['to-be-deleted']) | 287 self.assertEqual(['to-be-deleted'], result) |
288 return self.node.getItemsById(['to-be-deleted']) | 288 return self.node.getItemsById(['to-be-deleted']) |
289 | 289 |
290 def cb2(result): | 290 def cb2(result): |
291 self.assertEqual(len(result), 0) | 291 self.assertEqual(0, len(result)) |
292 | 292 |
293 d = self.node.removeItems(['to-be-deleted']) | 293 d = self.node.removeItems(['to-be-deleted']) |
294 d.addCallback(cb1) | 294 d.addCallback(cb1) |
295 d.addCallback(cb2) | 295 d.addCallback(cb2) |
296 return d | 296 return d |
297 | 297 |
298 | 298 |
299 def test_removeNonExistingItems(self): | 299 def test_removeNonExistingItems(self): |
300 def cb(result): | 300 def cb(result): |
301 self.assertEqual(result, []) | 301 self.assertEqual([], result) |
302 | 302 |
303 d = self.node.removeItems(['non-existing']) | 303 d = self.node.removeItems(['non-existing']) |
304 d.addCallback(cb) | 304 d.addCallback(cb) |
305 return d | 305 return d |
306 | 306 |
307 | 307 |
308 def test_getItems(self): | 308 def test_getItems(self): |
309 def cb(result): | 309 def cb(result): |
310 self.assertIn(decode(ITEM.toXml()), result) | 310 items = [item.toXml() for item in result] |
311 self.assertIn(ITEM.toXml(), items) | |
311 | 312 |
312 d = self.node.getItems() | 313 d = self.node.getItems() |
313 d.addCallback(cb) | 314 d.addCallback(cb) |
314 return d | 315 return d |
315 | 316 |
316 | 317 |
317 def test_lastItem(self): | 318 def test_lastItem(self): |
318 def cb(result): | 319 def cb(result): |
319 self.assertEqual([decode(ITEM.toXml())], result) | 320 self.assertEqual(1, len(result)) |
321 self.assertEqual(ITEM.toXml(), result[0].toXml()) | |
320 | 322 |
321 d = self.node.getItems(1) | 323 d = self.node.getItems(1) |
322 d.addCallback(cb) | 324 d.addCallback(cb) |
323 return d | 325 return d |
324 | 326 |
325 | 327 |
326 def test_getItemsById(self): | 328 def test_getItemsById(self): |
327 def cb(result): | 329 def cb(result): |
328 self.assertEqual(len(result), 1) | 330 self.assertEqual(1, len(result)) |
329 | 331 |
330 d = self.node.getItemsById(['current']) | 332 d = self.node.getItemsById(['current']) |
331 d.addCallback(cb) | 333 d.addCallback(cb) |
332 return d | 334 return d |
333 | 335 |
334 | 336 |
335 def test_getNonExistingItemsById(self): | 337 def test_getNonExistingItemsById(self): |
336 def cb(result): | 338 def cb(result): |
337 self.assertEqual(len(result), 0) | 339 self.assertEqual(0, len(result)) |
338 | 340 |
339 d = self.node.getItemsById(['non-existing']) | 341 d = self.node.getItemsById(['non-existing']) |
340 d.addCallback(cb) | 342 d.addCallback(cb) |
341 return d | 343 return d |
342 | 344 |
376 | 378 |
377 | 379 |
378 class MemoryStorageStorageTestCase(unittest.TestCase, StorageTests): | 380 class MemoryStorageStorageTestCase(unittest.TestCase, StorageTests): |
379 | 381 |
380 def setUp(self): | 382 def setUp(self): |
381 from idavoll.memory_storage import Storage, LeafNode, Subscription, \ | 383 from idavoll.memory_storage import Storage, PublishedItem, LeafNode |
382 defaultConfig | 384 from idavoll.memory_storage import Subscription, defaultConfig |
385 | |
383 self.s = Storage() | 386 self.s = Storage() |
384 self.s._nodes['pre-existing'] = \ | 387 self.s._nodes['pre-existing'] = \ |
385 LeafNode('pre-existing', OWNER, defaultConfig) | 388 LeafNode('pre-existing', OWNER, defaultConfig) |
386 self.s._nodes['to-be-deleted'] = \ | 389 self.s._nodes['to-be-deleted'] = \ |
387 LeafNode('to-be-deleted', OWNER, None) | 390 LeafNode('to-be-deleted', OWNER, None) |
395 subscriptions[SUBSCRIBER_TO_BE_DELETED.full()] = \ | 398 subscriptions[SUBSCRIBER_TO_BE_DELETED.full()] = \ |
396 Subscription('subscribed') | 399 Subscription('subscribed') |
397 subscriptions[SUBSCRIBER_PENDING.full()] = \ | 400 subscriptions[SUBSCRIBER_PENDING.full()] = \ |
398 Subscription('pending') | 401 Subscription('pending') |
399 | 402 |
400 item = (decode(ITEM_TO_BE_DELETED.toXml()), PUBLISHER) | 403 item = PublishedItem(ITEM_TO_BE_DELETED, PUBLISHER) |
401 self.s._nodes['pre-existing']._items['to-be-deleted'] = item | 404 self.s._nodes['pre-existing']._items['to-be-deleted'] = item |
402 self.s._nodes['pre-existing']._itemlist.append(item) | 405 self.s._nodes['pre-existing']._itemlist.append(item) |
403 self.s._nodes['to-be-purged']._items['to-be-deleted'] = item | 406 self.s._nodes['to-be-purged']._items['to-be-deleted'] = item |
404 self.s._nodes['to-be-purged']._itemlist.append(item) | 407 self.s._nodes['to-be-purged']._itemlist.append(item) |
405 item = (decode(ITEM.toXml()), PUBLISHER) | 408 item = PublishedItem(ITEM, PUBLISHER) |
406 self.s._nodes['pre-existing']._items['current'] = item | 409 self.s._nodes['pre-existing']._items['current'] = item |
407 self.s._nodes['pre-existing']._itemlist.append(item) | 410 self.s._nodes['pre-existing']._itemlist.append(item) |
408 | 411 |
409 return StorageTests.setUp(self) | 412 return StorageTests.setUp(self) |
410 | 413 |