Пример #1
0
    def test_readwrite(self):
        s = SimpleStorage(name='Pre', descrip='Testing', age=-1)
        self.assertEquals('', s.id)
        self.assertEquals('Pre', s.name)
        self.assertEquals('Testing', s.descrip)
        self.assertEquals(-1, s.age)
        self.assertEquals({}, s.extra_data)

        s.extra_data['coolness'] = {'a': 123, 'b': 456}
        s.extra_data['list-thing'] = [1, 2, 3, 4, 5, 6]
        s.extra_data['oscar'] = 'grouch'
        s.extra_data['fp'] = 42.42

        self.assertTrue(orig_version(s) is None)

        s.save()
        self.assertTrue(len(s.id) > 0)
        self.assertReadable(s)
        # Saved - so should have a prev version that is identical
        self.assertObjEq(s, SimpleStorage.from_data(orig_version(s)))

        s2 = SimpleStorage(id=s.id, name='Post', descrip='AtItAgain', age=256)
        s2.save()
        self.assertEqual(s.id, s2.id)
        self.assertReadable(s2)

        all_recs = SimpleStorage.find_all()
        self.assertEqual(1, len(all_recs))
        self.assertObjEq(s2, all_recs[0])

        # Change the object we read and then insure that the previous version
        # saved on load is correct
        read_obj = all_recs[0]
        read_obj.name = 'Pre2'
        read_obj.descrip = 'Testing2'
        read_obj.age = -2

        s0 = SimpleStorage.from_data(orig_version(read_obj))
        self.assertEquals(s.id, s0.id)
        self.assertEquals('Post', s0.name)
        self.assertEquals('AtItAgain', s0.descrip)
        self.assertEquals(256, s0.age)
        self.assertEquals({}, s0.extra_data)
Пример #2
0
    def test_readwrite(self):
        s = SimpleStorage(name='Pre', descrip='Testing', age=-1)
        self.assertEquals('', s.id)
        self.assertEquals('Pre', s.name)
        self.assertEquals('Testing', s.descrip)
        self.assertEquals(-1, s.age)
        self.assertEquals({}, s.extra_data)

        s.extra_data['coolness'] = {'a': 123, 'b': 456}
        s.extra_data['list-thing'] = [1, 2, 3, 4, 5, 6]
        s.extra_data['oscar'] = 'grouch'
        s.extra_data['fp'] = 42.42

        self.assertTrue(orig_version(s) is None)

        s.save()
        self.assertTrue(len(s.id) > 0)
        self.assertReadable(s)
        # Saved - so should have a prev version that is identical
        self.assertObjEq(s, SimpleStorage.from_data(orig_version(s)))

        s2 = SimpleStorage(id=s.id, name='Post', descrip='AtItAgain', age=256)
        s2.save()
        self.assertEqual(s.id, s2.id)
        self.assertReadable(s2)

        all_recs = SimpleStorage.find_all()
        self.assertEqual(1, len(all_recs))
        self.assertObjEq(s2, all_recs[0])

        # Change the object we read and then insure that the previous version
        # saved on load is correct
        read_obj = all_recs[0]
        read_obj.name = 'Pre2'
        read_obj.descrip = 'Testing2'
        read_obj.age = -2

        s0 = SimpleStorage.from_data(orig_version(read_obj))
        self.assertEquals(s.id, s0.id)
        self.assertEquals('Post', s0.name)
        self.assertEquals('AtItAgain', s0.descrip)
        self.assertEquals(256, s0.age)
        self.assertEquals({}, s0.extra_data)
Пример #3
0
 def assertReadable(self, obj):
     read_back = obj.__class__.find_one(obj.id)
     self.assertObjEq(obj, read_back)
     orig_ver = obj.__class__.from_data(orig_version(read_back))
     self.assertObjEq(obj, orig_ver)
Пример #4
0
 def assertReadable(self, obj):
     read_back = obj.__class__.find_one(obj.id)
     self.assertObjEq(obj, read_back)
     orig_ver = obj.__class__.from_data(orig_version(read_back))
     self.assertObjEq(obj, orig_ver)