diff options
author | Aleksey Lim <alsroot@sugarlabs.org> | 2012-09-27 08:08:56 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@sugarlabs.org> | 2012-09-27 08:08:56 (GMT) |
commit | 94c5d8c90b10e696d5ec74369acbf2c6e1bbbe3b (patch) | |
tree | 88f3b93be71e36e97d4fd0f81be620e77eafaa1b | |
parent | 998621ce83ead499970cbe7a23799a7c73d078de (diff) |
Return empty meta for missed blobs to differentiate it from other None values
-rw-r--r-- | active_document/document.py | 10 | ||||
-rwxr-xr-x | tests/units/document.py | 3 | ||||
-rwxr-xr-x | tests/units/volume.py | 7 |
3 files changed, 10 insertions, 10 deletions
diff --git a/active_document/document.py b/active_document/document.py index 2eab567..0646593 100644 --- a/active_document/document.py +++ b/active_document/document.py @@ -16,7 +16,7 @@ import logging from active_document import env -from active_document.metadata import StoredProperty +from active_document.metadata import StoredProperty, PropertyMeta from active_document.metadata import active_property @@ -63,11 +63,11 @@ class Document(object): value = self.props.get(prop.name) if value is None and self._record is not None: meta = self._record.get(prop.name) - if meta is not None: - if isinstance(prop, StoredProperty): + if isinstance(prop, StoredProperty): + if meta is not None: value = meta.get('value') - else: - value = meta + else: + value = meta or PropertyMeta() self.props[prop.name] = value if value is not None and accept_language: diff --git a/tests/units/document.py b/tests/units/document.py index d2e8492..b47203e 100755 --- a/tests/units/document.py +++ b/tests/units/document.py @@ -16,6 +16,7 @@ import gobject from __init__ import tests +import active_document as ad from active_document import document, storage, env, index from active_document import directory as directory_ from active_document.directory import Directory @@ -172,7 +173,7 @@ class DocumentTest(tests.Test): guid = directory.create({}) blob_path = join(tests.tmpdir, guid[:2], guid, 'blob') - self.assertEqual(None, directory.get(guid).blob) + self.assertEqual(ad.PropertyMeta(), directory.get(guid).blob) self.assertRaises(RuntimeError, directory.update, guid, {'blob': 'foo'}) data = 'payload' diff --git a/tests/units/volume.py b/tests/units/volume.py index c06c4c7..feb616a 100755 --- a/tests/units/volume.py +++ b/tests/units/volume.py @@ -243,15 +243,14 @@ class VolumeTest(tests.Test): def blob(self, value): return value - @active_property(prefix='L', localized=True, default='') - def localized_prop(self, value): - return value - self.volume = SingleVolume(tests.tmpdir, [TestDocument]) guid = self.call('POST', document='testdocument', content={'prop': 'value'}) self.assertEqual('value', self.call('GET', document='testdocument', guid=guid, prop='prop')) self.assertRaises(NotFound, self.call, 'GET', document='testdocument', guid=guid, prop='blob') + self.assertEqual( + {'blob': ad.PropertyMeta()}, + self.call('GET', document='testdocument', guid=guid, reply=['blob'])) def test_Command_ReplyForGET(self): |