diff options
author | Aleksey Lim <alsroot@sugarlabs.org> | 2012-09-15 03:21:07 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@sugarlabs.org> | 2012-09-15 03:21:07 (GMT) |
commit | 9d6db29ec91652e7a58b86006fba01d67a23eff3 (patch) | |
tree | 89a19f805f91c1141bf180af24e1c7fc424a104d | |
parent | 6b4cb5605a473114adee0990c69366a91f223039 (diff) |
Support composite BLOBs in GET requests
-rw-r--r-- | sugar_network/client/objects.py | 2 | ||||
-rw-r--r-- | sugar_network/node/commands.py | 27 | ||||
-rw-r--r-- | sugar_network/resources/context.py | 21 | ||||
-rwxr-xr-x | tests/units/node.py | 12 |
4 files changed, 40 insertions, 22 deletions
diff --git a/sugar_network/client/objects.py b/sugar_network/client/objects.py index 0f5cbfb..4b64f2f 100644 --- a/sugar_network/client/objects.py +++ b/sugar_network/client/objects.py @@ -125,7 +125,7 @@ class Object(object): blob = Client.call('GET', 'get_blob', mountpoint=self.mountpoint, document=self.document, guid=self._guid, prop=prop) self._blobs[prop] = blob - return blob, type(blob) is dict and 'path' in blob + return blob, isinstance(blob, dict) and 'path' in blob def __getitem__(self, prop): result = self.get(prop) diff --git a/sugar_network/node/commands.py b/sugar_network/node/commands.py index b9c935e..2ac3eb9 100644 --- a/sugar_network/node/commands.py +++ b/sugar_network/node/commands.py @@ -173,19 +173,26 @@ class NodeCommands(ad.VolumeCommands): props['author'] = authors def _mixin_blob(self, document, blobs, props): - directory = self.volume[document] - doc = directory.get(props['guid']) - + doc = self.volume[document].get(props['guid']) for name in blobs: + + def compose_url(value): + if value is None: + value = '/'.join(['', document, props['guid'], name]) + if value.startswith('/'): + value = 'http://%s:%s%s' % \ + (node.host.value, node.port.value, value) + return value + + url = None meta = doc.meta(name) - if meta is not None and 'url' in meta: - url = meta['url'] + if meta is not None: + url = meta.url() + + if type(url) is list: + props[name] = [compose_url(i.get('url')) for i in url] else: - url = '/'.join(['', document, props['guid'], name]) - if url.startswith('/'): - url = 'http://%s:%s%s' % \ - (node.host.value, node.port.value, url) - props[name] = url + props[name] = compose_url(url) class MasterCommands(NodeCommands, SyncCommands): diff --git a/sugar_network/resources/context.py b/sugar_network/resources/context.py index e670d10..85c004b 100644 --- a/sugar_network/resources/context.py +++ b/sugar_network/resources/context.py @@ -62,22 +62,25 @@ class Context(Resource): def icon(self, value): if value is None: if 'package' in self['type']: - return {'url': '/static/images/package.png', - 'path': join(static.PATH, 'images', 'package.png'), - 'mime_type': 'image/png'} + return ad.Meta( + url='/static/images/package.png', + path=join(static.PATH, 'images', 'package.png'), + mime_type='image/png') else: - return {'url': '/static/images/missing.png', - 'path': join(static.PATH, 'images', 'missing.png'), - 'mime_type': 'image/png'} + return ad.Meta( + url='/static/images/missing.png', + path=join(static.PATH, 'images', 'missing.png'), + mime_type='image/png') else: return value @ad.active_property(ad.BlobProperty, mime_type='image/svg+xml') def artifact_icon(self, value): if value is None: - return {'url': '/static/images/missing.svg', - 'path': join(static.PATH, 'images', 'missing.svg'), - 'mime_type': 'image/svg+xml'} + return ad.Meta( + url='/static/images/missing.svg', + path=join(static.PATH, 'images', 'missing.svg'), + mime_type='image/svg+xml') return value @ad.active_property(ad.BlobProperty) diff --git a/tests/units/node.py b/tests/units/node.py index 4d54456..4152ece 100755 --- a/tests/units/node.py +++ b/tests/units/node.py @@ -274,19 +274,26 @@ class NodeTest(tests.Test): 'summary': 'summary', 'description': 'description', }) - volume['context'].set_blob(guid2, 'icon', 'http://foo/bar') + volume['context'].set_blob(guid2, 'icon', url='http://foo/bar') guid3 = call(cp, method='POST', document='context', principal='principal', content={ 'type': 'activity', 'title': 'title3', 'summary': 'summary', 'description': 'description', }) - volume['context'].set_blob(guid3, 'icon', '/foo/bar') + volume['context'].set_blob(guid3, 'icon', url='/foo/bar') guid4 = call(cp, method='POST', document='report', principal='principal', content={ 'context': 'context', 'implementation': 'implementation', 'description': 'description', }) + guid5 = call(cp, method='POST', document='context', principal='principal', content={ + 'type': 'activity', + 'title': 'title5', + 'summary': 'summary', + 'description': 'description', + }) + volume['context'].set_blob(guid5, 'icon', url={'file1': {'order': 1, 'url': '/1'}, 'file2': {'order': 2, 'url': 'http://2'}}) self.assertEqual( {'guid': guid1, 'icon': 'http://localhost:8000/static/images/missing.png'}, @@ -305,6 +312,7 @@ class NodeTest(tests.Test): {'guid': guid1, 'icon': 'http://localhost:8000/static/images/missing.png'}, {'guid': guid2, 'icon': 'http://foo/bar'}, {'guid': guid3, 'icon': 'http://localhost:8000/foo/bar'}, + {'guid': guid5, 'icon': ['http://localhost:8000/1', 'http://2']}, ], call(cp, method='GET', document='context', reply=['guid', 'icon'])['result']) |