~djfroofy/storm/twisted-integration-tests

« back to all changes in this revision

Viewing changes to tests/twistorm.py

  • Committer: drew.smathers at gmail
  • Date: 2008-10-10 02:26:38 UTC
  • Revision ID: drew.smathers@gmail.com-20081010022638-1ajr3bsfjfhysju7
- More unit tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from storm.uri import URI
29
29
from storm.properties import Int, Unicode
30
30
 
31
 
from storm.twisted.store import DeferredStore, StoreThread, StorePool
 
31
from storm.twisted.store import (
 
32
        DeferredStore, StoreThread, StorePool, AlreadyStopped )
32
33
from storm.twisted.wrapper import DeferredReference, DeferredReferenceSet
33
34
 
34
35
from twisted.trial.unittest import TestCase
379
380
 
380
381
    def test_find_values(self):
381
382
        """
382
 
        Filter the fiels returned by a find using the values method.
 
383
        Filter the fields returned by a find using the values method.
383
384
        """
384
385
        def cb_find(results):
385
386
            return results.values(Bar.title).addCallback(cb_all)
400
401
            self.assertEquals(len(results), 2)
401
402
        return self.store.find(Egg).addCallback(cb_find)
402
403
 
 
404
    def test_find_offset_limit(self):
 
405
        """
 
406
        Put an offset and limit in the number of results of a find.
 
407
        """
 
408
        def cb_find(results):
 
409
            results.config(offset=1, limit=2)
 
410
            return results.all().addCallback(cb_all)
 
411
        def cb_all(results):
 
412
            self.assertEquals(len(results), 2)
 
413
        return self.store.find(Egg).addCallback(cb_find)
403
414
 
404
415
    def test_find_defgen(self):
405
416
        """
463
474
            self.assertEquals(titles, [u'Title 40', u'Title 50'])
464
475
        return self.store.find(Bar).addCallback(cb_find)
465
476
 
 
477
    def test_transaction_boundary(self):
 
478
        """
 
479
        This exposes a bug in transaction boundaries due (maybe) to making
 
480
        invalidate a noop.
 
481
        """
 
482
        otherStore = DeferredStore(self.database)
 
483
        d = otherStore.start()
 
484
        yield waitForDeferred(d)
 
485
        d = self.store.find(Bar, Bar.title==u'Title 50')
 
486
        wfd = waitForDeferred(d)
 
487
        yield wfd
 
488
        result = wfd.getResult()
 
489
        d = result.one()
 
490
        wfd = waitForDeferred(d)
 
491
        yield wfd
 
492
        barResult = wfd.getResult()
 
493
        barResult.title = u'Title 51'
 
494
        d = self.store.commit()
 
495
        yield waitForDeferred(d)
 
496
        d = otherStore.find(Bar, Bar.title==u'Title 51')
 
497
        wfd = waitForDeferred(d)
 
498
        yield wfd
 
499
        result = wfd.getResult()
 
500
        d = result.one()
 
501
        wfd = waitForDeferred(d)
 
502
        yield wfd
 
503
        barResult = wfd.getResult()
 
504
        barResult.title = u'Title 50'
 
505
        d = otherStore.commit()
 
506
        yield waitForDeferred(d)
 
507
        d = self.store.rollback()
 
508
        yield waitForDeferred(d)
 
509
        d = self.store.find(Bar, Bar.title==u'Title 50')
 
510
        wfd = waitForDeferred(d)
 
511
        yield wfd
 
512
        result = wfd.getResult()
 
513
        d = result.one()
 
514
        wfd = waitForDeferred(d)
 
515
        yield wfd
 
516
        barResult = wfd.getResult()
 
517
        self.assertEquals(barResult.title, u'Title 50')
 
518
 
 
519
    test_transaction_boundary = deferredGenerator(test_transaction_boundary)
466
520
 
467
521
    def test_reference(self):
468
522
        """
674
728
        self.thread.stop()
675
729
 
676
730
 
 
731
    def test_defer_after_stop(self):
 
732
        """
 
733
        Deferring calls after store is stopped raises AlreadyStopped.
 
734
        """
 
735
        def cb_stop(r):
 
736
            self.assertFailure(self.thread.defer_to_thread(lambda f : None),
 
737
                    AlreadyStopped)
 
738
        return self.thread.stop().addCallback(cb_stop)
 
739
 
677
740
    def test_callback(self):
678
741
        """
679
742
        Fire a simple function in a thread and check its result.
781
844
        return self.pool.adjust_size(1, 1).addCallback(cb)
782
845
 
783
846
 
 
847
    def test_adjust_size_minmax(self):
 
848
        """
 
849
        Test sanity check on min/max - i.e. min <= max. 
 
850
        """
 
851
        return self.assertFailure(self.pool.adjust_size(2,1), ValueError)
 
852
 
 
853
    def test_adjust_size_nonnegative(self):
 
854
        """
 
855
        Test sanity check for nonnegative min.
 
856
        """
 
857
        return self.assertFailure(self.pool.adjust_size(-1), ValueError)
 
858
    
 
859
 
784
860
    def test_concurrent_data(self):
785
861
        """
786
862
        Test that different stores have different states: if the first store