Esempio n. 1
0
    def test_versions_saved(self):
        expected = []

        d = VersionedData()

        def do_save():
            d.save()
            expected.append(d.to_data())

        do_save()

        d.name = 'first new name'
        d.descrip = 'Changed named once'
        d.age = 1
        do_save()

        d.name = 'last new name'
        d.descrip = 'Changed named twice'
        d.age = 2
        do_save()

        obj_hist = list(parse_diff_hist(d.to_data(), d.get_version_hist()))
        self.assertEquals(3, len(obj_hist))
        self.assertEquals(len(expected), len(obj_hist))

        for exp, act in zip(reversed(expected), obj_hist):
            exp = VersionedData.from_data(json.dumps(cmpfilt(exp)))

            actobj, actdate = act
            actobj = VersionedData.from_data(json.dumps(cmpfilt(actobj)))

            self.assertTrue(compare_data_objects(exp, actobj))

        print((type(obj_hist[0][0]), obj_hist[0][0]))
        obj_hist_dct = [json.loads(o) for o, _ in obj_hist]

        # a little sanity checking
        self.assertEquals("last new name", obj_hist_dct[0]['name'])
        self.assertEquals("first new name", obj_hist_dct[1]['name'])
        self.assertEquals("default name", obj_hist_dct[2]['name'])
    def test_versions_saved(self):
        expected = []

        d = VersionedData()

        def do_save():
            d.save()
            expected.append(d.to_data())

        do_save()

        d.name = 'first new name'
        d.descrip = 'Changed named once'
        d.age = 1
        do_save()

        d.name = 'last new name'
        d.descrip = 'Changed named twice'
        d.age = 2
        do_save()

        obj_hist = list(parse_diff_hist(d.to_data(), d.get_version_hist()))
        self.assertEquals(3, len(obj_hist))
        self.assertEquals(len(expected), len(obj_hist))

        for exp, act in zip(reversed(expected), obj_hist):
            exp = VersionedData.from_data(json.dumps(cmpfilt(exp)))

            actobj, actdate = act
            actobj = VersionedData.from_data(json.dumps(cmpfilt(actobj)))

            self.assertTrue(compare_data_objects(exp, actobj))

        print(type(obj_hist[0][0]), obj_hist[0][0])
        obj_hist_dct = [json.loads(o) for o, _ in obj_hist]

        # a little sanity checking
        self.assertEquals("last new name", obj_hist_dct[0]['name'])
        self.assertEquals("first new name", obj_hist_dct[1]['name'])
        self.assertEquals("default name", obj_hist_dct[2]['name'])
Esempio n. 3
0
 def assertObjEq(self, obj1, obj2):
     self.assertTrue(compare_data_objects(obj1, obj2))