~jbaker/storm/nose_plugin

« back to all changes in this revision

Viewing changes to tests/store/base.py

  • Committer: Jamu Kakar
  • Date: 2009-11-24 18:34:34 UTC
  • mfrom: (340 storm.trunk)
  • mto: This revision was merged to the branch mainline in revision 341.
  • Revision ID: jkakar@kakar.ca-20091124183434-ambkvw9tp2byvjnc
- Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
421
421
        self.store.flush()
422
422
        self.assertEquals(len(events), 1)
423
423
 
 
424
    def test_wb_flush_event_with_deleted_object_before_flush(self):
 
425
        """
 
426
        When an object is deleted before flush and it contains mutable
 
427
        variables, those variables unhook from the global event system to
 
428
        prevent a leak.
 
429
        """
 
430
        class PickleBlob(Blob):
 
431
            bin = Pickle()
 
432
 
 
433
        # Disable the cache, which holds strong references.
 
434
        self.get_cache(self.store).set_size(0)
 
435
 
 
436
        blob = self.store.get(Blob, 20)
 
437
        blob.bin = "\x80\x02}q\x01U\x01aK\x01s."
 
438
        self.store.flush()
 
439
        del blob
 
440
        gc.collect()
 
441
 
 
442
        pickle_blob = self.store.get(PickleBlob, 20)
 
443
        pickle_blob.bin = "foobin"
 
444
        del pickle_blob
 
445
 
 
446
        self.store.flush()
 
447
        self.assertEquals(self.store._event._hooks["flush"], set())
 
448
 
 
449
 
424
450
    def test_obj_info_with_deleted_object_with_get(self):
425
451
        # Same thing, but using get rather than find.
426
452
 
894
920
        self.assertEquals(title, "Title 30")
895
921
        self.assertTrue(isinstance(title, unicode))
896
922
 
 
923
    def test_find_max_with_empty_result_and_disallow_none(self):
 
924
        class Bar(object):
 
925
            __storm_table__ = "bar"
 
926
            id = Int(primary=True)
 
927
            foo_id = Int(allow_none=False)
 
928
 
 
929
        result = self.store.find(Bar, Bar.id > 1000)
 
930
        self.assertTrue(result.is_empty())
 
931
        self.assertEquals(result.max(Bar.foo_id), None)
 
932
 
897
933
    def test_find_min(self):
898
934
        self.assertEquals(self.store.find(Foo).min(Foo.id), 10)
899
935
 
905
941
        self.assertEquals(title, "Title 10")
906
942
        self.assertTrue(isinstance(title, unicode))
907
943
 
 
944
    def test_find_min_with_empty_result_and_disallow_none(self):
 
945
        class Bar(object):
 
946
            __storm_table__ = "bar"
 
947
            id = Int(primary=True)
 
948
            foo_id = Int(allow_none=False)
 
949
 
 
950
        result = self.store.find(Bar, Bar.id > 1000)
 
951
        self.assertTrue(result.is_empty())
 
952
        self.assertEquals(result.min(Bar.foo_id), None)
 
953
 
908
954
    def test_find_avg(self):
909
955
        self.assertEquals(self.store.find(Foo).avg(Foo.id), 20)
910
956
 
924
970
    def test_find_sum_expr(self):
925
971
        self.assertEquals(self.store.find(Foo).sum(Foo.id * 2), 120)
926
972
 
 
973
    def test_find_sum_with_empty_result_and_disallow_none(self):
 
974
        class Bar(object):
 
975
            __storm_table__ = "bar"
 
976
            id = Int(primary=True)
 
977
            foo_id = Int(allow_none=False)
 
978
 
 
979
        result = self.store.find(Bar, Bar.id > 1000)
 
980
        self.assertTrue(result.is_empty())
 
981
        self.assertEquals(result.sum(Bar.foo_id), None)
 
982
 
927
983
    def test_find_max_order_by(self):
928
984
        """Interaction between order by and aggregation shouldn't break."""
929
985
        result = self.store.find(Foo)