diff options
author | Aleksey Lim <alsroot@sugarlabs.org> | 2013-09-15 09:34:02 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@sugarlabs.org> | 2013-09-15 09:34:02 (GMT) |
commit | 750bd01dd00af01d3f68df43882a09d837d337a3 (patch) | |
tree | d361cddf386a0a0c58dd4f0bb183e9d4cbe0708d | |
parent | ca90fccc05475bd63d3532bddba4f482b4e00451 (diff) |
Set default property values if it was passed with None
-rw-r--r-- | sugar_network/db/routes.py | 2 | ||||
m--------- | sugar_network/lib/requests | 0 | ||||
-rw-r--r-- | sugar_network/model/context.py | 2 | ||||
-rwxr-xr-x | tests/units/db/routes.py | 13 |
4 files changed, 15 insertions, 2 deletions
diff --git a/sugar_network/db/routes.py b/sugar_network/db/routes.py index 197c215..7a4b582 100644 --- a/sugar_network/db/routes.py +++ b/sugar_network/db/routes.py @@ -201,7 +201,7 @@ class Routes(object): if access == ACL.CREATE: for name, prop in directory.metadata.items(): if not isinstance(prop, BlobProperty) and \ - name not in content and \ + content.get(name) is None and \ (prop.default is not None or prop.on_set is not None): doc[name] = prop.default diff --git a/sugar_network/lib/requests b/sugar_network/lib/requests -Subproject fecf213d44525115a45e21905f775c46a80e390 +Subproject ea6c4665c3ed2c17c276cc2709f8ddb20870530 diff --git a/sugar_network/model/context.py b/sugar_network/model/context.py index a9962a9..053228f 100644 --- a/sugar_network/model/context.py +++ b/sugar_network/model/context.py @@ -29,7 +29,7 @@ class Context(db.Resource): @type.setter def type(self, value): - if 'package' in value and 'common' not in self['layer']: + if value and 'package' in value and 'common' not in self['layer']: self['layer'] = tuple(self['layer']) + ('common',) return value diff --git a/tests/units/db/routes.py b/tests/units/db/routes.py index b1d1afd..b6e0c11 100755 --- a/tests/units/db/routes.py +++ b/tests/units/db/routes.py @@ -1611,6 +1611,19 @@ class RoutesTest(tests.Test): ], self.call('GET', ['document'])['result']) + def test_SetDefaultPropsOnNoneValues(self): + + class Document(db.Resource): + + @db.indexed_property(slot=1, default='default') + def prop(self, value): + return value + + self.volume = db.Volume('db', [Document]) + + guid = self.call('POST', ['document'], content={'prop': None}) + self.assertEqual('default', self.volume['document'].get(guid).meta('prop')['value']) + def call(self, method=None, path=None, accept_language=None, content=None, content_stream=None, cmd=None, content_type=None, host=None, request=None, routes=db.Routes, principal=None, |