diff options
author | Aleksey Lim <alsroot@sugarlabs.org> | 2013-06-27 15:31:21 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@sugarlabs.org> | 2013-06-27 16:16:22 (GMT) |
commit | 704331c95659077f0c88570ddde3fec9cd745fa8 (patch) | |
tree | c8335f08794a448551f9337488b5a70d49204098 | |
parent | 729303a97cff64db18f70ad80d302f06dce1646d (diff) |
Test resetting prop values in setters
-rwxr-xr-x | tests/units/db/volume.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/units/db/volume.py b/tests/units/db/volume.py index b06c15a..70f3adf 100755 --- a/tests/units/db/volume.py +++ b/tests/units/db/volume.py @@ -943,6 +943,65 @@ class VolumeTest(tests.Test): self.assertEqual(4, self.call('GET', document='testdocument', guid=guid, prop='prop1')) self.assertEqual(1, self.call('GET', document='testdocument', guid=guid, prop='prop2')) + def test_properties_PopulateRequiredPropsInSetters(self): + + class TestDocument(db.Document): + + @db.indexed_property(slot=1, typecast=int) + def prop1(self, value): + return value + + @prop1.setter + def prop1(self, value): + self['prop2'] = value + 1 + return value + + @db.indexed_property(slot=2, typecast=int) + def prop2(self, value): + return value + + @db.blob_property() + def prop3(self, value): + return value + + @prop3.setter + def prop3(self, value): + self['prop1'] = -1 + self['prop2'] = -2 + return value + + self.volume = db.Volume(tests.tmpdir, [TestDocument]) + guid = self.call('POST', document='testdocument', content={'prop1': 1}) + self.assertEqual(1, self.call('GET', document='testdocument', guid=guid, prop='prop1')) + self.assertEqual(2, self.call('GET', document='testdocument', guid=guid, prop='prop2')) + + def test_properties_PopulateRequiredPropsInBlobSetter(self): + + class TestDocument(db.Document): + + @db.blob_property() + def blob(self, value): + return value + + @blob.setter + def blob(self, value): + self['prop1'] = 1 + self['prop2'] = 2 + return value + + @db.indexed_property(slot=1, typecast=int) + def prop1(self, value): + return value + + @db.indexed_property(slot=2, typecast=int) + def prop2(self, value): + return value + + self.volume = db.Volume(tests.tmpdir, [TestDocument]) + guid = self.call('POST', document='testdocument', content={'blob': ''}) + self.assertEqual(1, self.call('GET', document='testdocument', guid=guid, prop='prop1')) + self.assertEqual(2, self.call('GET', document='testdocument', guid=guid, prop='prop2')) + def test_SubCall(self): class TestDocument(db.Document): |