~edoardo-serra/storm/select-for-update-support

« back to all changes in this revision

Viewing changes to tests/store/base.py

  • Committer: Edoardo Serra
  • Date: 2010-09-09 15:07:13 UTC
  • Revision ID: eserra@barbera-20100909150713-3f8v0gxosfcsrv4d
SELECT ... FOR UPDATE implemented in Store.get

Show diffs side-by-side

added added

removed removed

Lines of Context:
321
321
        foo = self.store.get(Foo, 40)
322
322
        self.assertEquals(foo, None)
323
323
 
 
324
    def test_get_for_update(self):
 
325
        stream = StringIO()
 
326
        self.addCleanup(debug, False)
 
327
        debug(True, stream)
 
328
 
 
329
        foo = self.store.get(Foo, 10, for_update=True)
 
330
        self.assertEquals(foo.id, 10)
 
331
        self.assertEquals(foo.title, "Title 30")
 
332
        if self.__class__.__name__.startswith("SQLite"):
 
333
            return
 
334
        self.assertIn("FOR UPDATE", stream.getvalue())
 
335
 
324
336
    def test_get_cached(self):
325
337
        foo = self.store.get(Foo, 10)
326
338
        self.assertTrue(self.store.get(Foo, 10) is foo)
332
344
        self.store.get(Foo, 10)
333
345
        self.store._connection = connection
334
346
 
 
347
    def test_wb_get_cached_for_update_needa_connection(self):
 
348
        foo = self.store.get(Foo, 10)
 
349
        connection = self.store._connection
 
350
        self.store._connection = None
 
351
        self.assertRaises(AttributeError, self.store.get, Foo, 10, for_update=True)
 
352
        self.store._connection = connection
 
353
 
335
354
    def test_cache_cleanup(self):
336
355
        # Disable the cache, which holds strong references.
337
356
        self.get_cache(self.store).set_size(0)