示例#1
0
    def test_empty_history(self):
        diff_hist = []
        obj_hist = list(parse_diff_hist(self.start, diff_hist))

        self.assertEquals(1, len(obj_hist))
        self.assertEquals(self.start, json.loads(obj_hist[0][0]))
        self.assertIsNone(obj_hist[0][1])
    def test_empty_history(self):
        diff_hist = []
        obj_hist = list(parse_diff_hist(self.start, diff_hist))

        self.assertEquals(1, len(obj_hist))
        self.assertEquals(self.start, json.loads(obj_hist[0][0]))
        self.assertIsNone(obj_hist[0][1])
示例#3
0
    def test_full_history(self):
        diff_hist = []
        last_obj = self.series[0]
        for obj in self.series[1:]:
            diff = record_diff(last_obj, obj)
            diff_hist = append_diff_hist(diff, diff_hist)
            last_obj = obj

        obj_hist = list(parse_diff_hist(self.final, diff_hist))
        self.assertEquals(4, len(obj_hist))
        obj_list = list(reversed([json.loads(ver) for ver, _ in obj_hist]))
        self.assertEquals(self.series, obj_list)
    def test_full_history(self):
        diff_hist = []
        last_obj = self.series[0]
        for obj in self.series[1:]:
            diff = record_diff(last_obj, obj)
            diff_hist = append_diff_hist(diff, diff_hist)
            last_obj = obj

        obj_hist = list(parse_diff_hist(self.final, diff_hist))
        self.assertEquals(4, len(obj_hist))
        obj_list = list(reversed([json.loads(ver) for ver, _ in obj_hist]))
        self.assertEquals(self.series, obj_list)
示例#5
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'])