~fluiddb-dev/storm/trunk

« back to all changes in this revision

Viewing changes to tests/properties.py

  • Committer: Jamu Kakar
  • Date: 2011-02-28 21:25:44 UTC
  • mfrom: (386.1.2 json-property)
  • Revision ID: jkakar@kakar.ca-20110228212544-rm0wpjhqzi3i09fs
- Merged json-property.

Show diffs side-by-side

added added

removed removed

Lines of Context:
693
693
        del self.obj
694
694
        self.assertEquals(changes, [(self.variable1, None, ["a"], False)])
695
695
 
 
696
    def test_json(self):
 
697
        self.setup(JSON, default_factory=dict, allow_none=False)
 
698
 
 
699
        self.assertTrue(isinstance(self.column1, Column))
 
700
        self.assertTrue(isinstance(self.column2, Column))
 
701
        self.assertEquals(self.column1.name, "column1")
 
702
        self.assertEquals(self.column1.table, self.SubClass)
 
703
        self.assertEquals(self.column2.name, "prop2")
 
704
        self.assertEquals(self.column2.table, self.SubClass)
 
705
        self.assertTrue(isinstance(self.variable1, JSONVariable))
 
706
        self.assertTrue(isinstance(self.variable2, JSONVariable))
 
707
 
 
708
        self.assertEquals(self.obj.prop1, {})
 
709
        self.assertRaises(NoneError, setattr, self.obj, "prop1", None)
 
710
        self.obj.prop2 = None
 
711
        self.assertEquals(self.obj.prop2, None)
 
712
 
 
713
        self.obj.prop1 = []
 
714
        self.assertEquals(self.obj.prop1, [])
 
715
        self.obj.prop1.append("a")
 
716
        self.assertEquals(self.obj.prop1, ["a"])
 
717
 
 
718
    def test_json_events(self):
 
719
        self.setup(JSON, default_factory=list, allow_none=False)
 
720
 
 
721
        changes = []
 
722
        def changed(owner, variable, old_value, new_value, fromdb):
 
723
            changes.append((variable, old_value, new_value, fromdb))
 
724
 
 
725
        # Can't checkpoint Undef.
 
726
        self.obj.prop2 = []
 
727
 
 
728
        self.obj_info.checkpoint()
 
729
        self.obj_info.event.emit("start-tracking-changes", self.obj_info.event)
 
730
        self.obj_info.event.hook("changed", changed)
 
731
 
 
732
        self.assertEquals(self.obj.prop1, [])
 
733
        self.assertEquals(changes, [])
 
734
        self.obj.prop1.append("a")
 
735
        self.assertEquals(changes, [])
 
736
 
 
737
        # Check "flush" event. Notice that the other variable wasn't
 
738
        # listed, since it wasn't changed.
 
739
        self.obj_info.event.emit("flush")
 
740
        self.assertEquals(changes, [(self.variable1, None, ["a"], False)])
 
741
 
 
742
        del changes[:]
 
743
 
 
744
        # Check "object-deleted" event. Notice that the other variable
 
745
        # wasn't listed again, since it wasn't changed.
 
746
        del self.obj
 
747
        self.assertEquals(changes, [(self.variable1, None, ["a"], False)])
 
748
 
696
749
    def test_list(self):
697
750
        self.setup(List, default_factory=list, allow_none=False)
698
751