From 2f6032c0a28d8dbd1d4ea963cdd381493e875dfa Mon Sep 17 00:00:00 2001 From: Aleksey Lim Date: Wed, 03 Oct 2012 18:17:19 +0000 Subject: GET command requests might be without guids --- diff --git a/sugar_network/resources/volume.py b/sugar_network/resources/volume.py index d6867ba..03b1816 100644 --- a/sugar_network/resources/volume.py +++ b/sugar_network/resources/volume.py @@ -214,6 +214,12 @@ class Commands(object): return result def _mixin_blobs(self, request, result): + requested_guid = request.get('guid') + if not requested_guid: + reply = request.get('reply') + if reply and 'guid' not in reply: + return + if node.static_url.value: prefix = node.static_url.value elif hasattr(request, 'environ'): @@ -227,7 +233,7 @@ class Commands(object): document = request['document'] for props in result: - guid = props.get('guid') or request['guid'] + guid = props.get('guid') or requested_guid for name, value in props.items(): if not isinstance(value, ad.PropertyMeta): continue diff --git a/tests/__init__.py b/tests/__init__.py index a638110..c95f45a 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -97,7 +97,7 @@ class Test(unittest.TestCase): Volume.RESOURCES = [ 'sugar_network.resources.user', 'sugar_network.resources.context', - 'sugar_network.resources.report', + 'sugar_network.resources.artifact', 'sugar_network.resources.implementation', ] diff --git a/tests/units/home_mount.py b/tests/units/home_mount.py index 2312154..103fca2 100755 --- a/tests/units/home_mount.py +++ b/tests/units/home_mount.py @@ -10,7 +10,7 @@ from os.path import exists, abspath from __init__ import tests from active_toolkit import sockets, coroutine -from sugar_network.resources.report import Report +from sugar_network.resources.artifact import Artifact from sugar_network import local from sugar_network.local import activities from sugar_network import IPCClient @@ -132,7 +132,7 @@ class HomeMountTest(tests.Test): blob_url = 'http://localhost:%s/context/%s/icon?mountpoint=~' % (local.ipc_port.value, guid) self.assertEqual( [{'guid': guid, 'icon': blob_url}], - client.get(['context'], reply=['icon'])['result']) + client.get(['context'], reply=['guid', 'icon'])['result']) self.assertEqual( {'icon': blob_url}, client.get(['context', guid], reply=['icon'])) @@ -141,23 +141,19 @@ class HomeMountTest(tests.Test): urllib2.urlopen(blob_url).read()) def test_GetAbsentBLOBs(self): - self.start_server([Report]) + self.start_server([Artifact]) client = IPCClient(mountpoint='~') - guid = client.post(['report'], { - 'context': 'context', - 'implementation': 'implementation', - 'description': 'description', - }) + guid = client.post(['artifact'], {}) - self.assertRaises(RuntimeError, client.get, ['report', guid, 'data']) - blob_url = 'http://localhost:%s/report/%s/data?mountpoint=~' % (local.ipc_port.value, guid) + self.assertRaises(RuntimeError, client.get, ['artifact', guid, 'data']) + blob_url = 'http://localhost:%s/artifact/%s/data?mountpoint=~' % (local.ipc_port.value, guid) self.assertEqual( [{'guid': guid, 'data': blob_url}], - client.get(['report'], reply=['data'])['result']) + client.get(['artifact'], reply=['guid', 'data'])['result']) self.assertEqual( {'data': blob_url}, - client.get(['report', guid], reply=['data'])) + client.get(['artifact', guid], reply=['data'])) self.assertRaises(urllib2.HTTPError, urllib2.urlopen, blob_url) def test_Subscription(self): diff --git a/tests/units/node.py b/tests/units/node.py index 9b2b200..9a2689b 100755 --- a/tests/units/node.py +++ b/tests/units/node.py @@ -284,10 +284,7 @@ class NodeTest(tests.Test): 'description': 'description', }) 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', + guid4 = call(cp, method='POST', document='artifact', principal='principal', content={ }) guid5 = call(cp, method='POST', document='context', principal='principal', content={ 'type': 'activity', @@ -307,8 +304,8 @@ class NodeTest(tests.Test): {'guid': guid3, 'icon': 'http://localhost/foo/bar', 'layer': ['public']}, call(cp, method='GET', document='context', guid=guid3, reply=['guid', 'icon', 'layer'])) self.assertEqual( - {'guid': guid4, 'data': 'http://localhost/report/%s/data' % guid4, 'layer': ['public']}, - call(cp, method='GET', document='report', guid=guid4, reply=['guid', 'data', 'layer'])) + {'guid': guid4, 'data': 'http://localhost/artifact/%s/data' % guid4, 'layer': ['public']}, + call(cp, method='GET', document='artifact', guid=guid4, reply=['guid', 'data', 'layer'])) self.assertEqual( sorted([ @@ -320,9 +317,9 @@ class NodeTest(tests.Test): sorted(call(cp, method='GET', document='context', reply=['guid', 'icon', 'layer'])['result'])) self.assertEqual([ - {'guid': guid4, 'data': 'http://localhost/report/%s/data' % guid4, 'layer': ['public']}, + {'guid': guid4, 'data': 'http://localhost/artifact/%s/data' % guid4, 'layer': ['public']}, ], - call(cp, method='GET', document='report', reply=['guid', 'data', 'layer'])['result']) + call(cp, method='GET', document='artifact', reply=['guid', 'data', 'layer'])['result']) node.static_url.value = 'static_url' self.assertEqual( diff --git a/tests/units/node_mount.py b/tests/units/node_mount.py index cac4c71..60635f9 100755 --- a/tests/units/node_mount.py +++ b/tests/units/node_mount.py @@ -20,7 +20,7 @@ from sugar_network.resources.user import User from sugar_network.resources.context import Context from sugar_network import local, sugar from sugar_network.resources.volume import Volume -from sugar_network.resources.report import Report +from sugar_network.resources.artifact import Artifact from sugar_network.local.ipc_client import Router as IPCRouter from sugar_network import IPCClient @@ -42,7 +42,7 @@ class NodeMountTest(tests.Test): self.touch(('mnt/node', 'node')) local.mounts_root.value = tests.tmpdir - volume = Volume('local', [User, Context, Report]) + volume = Volume('local', [User, Context, Artifact]) self.mounts = Mountset(volume) self.server = coroutine.WSGIServer( ('localhost', local.ipc_port.value), IPCRouter(self.mounts)) @@ -314,7 +314,7 @@ class NodeMountTest(tests.Test): blob_url = 'http://localhost:%s/context/%s/icon?mountpoint=%s' % (local.ipc_port.value, guid, tests.tmpdir + '/mnt') self.assertEqual( [{'guid': guid, 'icon': blob_url}], - client.get(['context'], reply=['icon'])['result']) + client.get(['context'], reply=['guid', 'icon'])['result']) self.assertEqual( {'icon': blob_url}, client.get(['context', guid], reply=['icon'])) @@ -327,20 +327,16 @@ class NodeMountTest(tests.Test): mounts[tests.tmpdir + '/mnt'].mounted.wait() client = IPCClient(mountpoint=tests.tmpdir + '/mnt') - guid = client.post(['report'], { - 'context': 'context', - 'implementation': 'implementation', - 'description': 'description', - }) + guid = client.post(['artifact'], {}) - self.assertRaises(RuntimeError, client.get, ['report', guid, 'data']) - blob_url = 'http://localhost:%s/report/%s/data?mountpoint=%s' % (local.ipc_port.value, guid, tests.tmpdir + '/mnt') + self.assertRaises(RuntimeError, client.get, ['artifact', guid, 'data']) + blob_url = 'http://localhost:%s/artifact/%s/data?mountpoint=%s' % (local.ipc_port.value, guid, tests.tmpdir + '/mnt') self.assertEqual( [{'guid': guid, 'data': blob_url}], - client.get(['report'], reply=['data'])['result']) + client.get(['artifact'], reply=['guid', 'data'])['result']) self.assertEqual( {'data': blob_url}, - client.get(['report', guid], reply=['data'])) + client.get(['artifact', guid], reply=['data'])) self.assertRaises(urllib2.HTTPError, urllib2.urlopen, blob_url) def test_get_blob_ExtractImplementations(self): diff --git a/tests/units/remote_mount.py b/tests/units/remote_mount.py index 2544491..3d58a65 100755 --- a/tests/units/remote_mount.py +++ b/tests/units/remote_mount.py @@ -18,7 +18,7 @@ from sugar_network.local.mountset import Mountset from sugar_network.toolkit import sugar, http from sugar_network.resources.user import User from sugar_network.resources.context import Context -from sugar_network.resources.report import Report +from sugar_network.resources.artifact import Artifact from sugar_network.resources.volume import Volume from sugar_network import IPCClient @@ -288,7 +288,7 @@ class RemoteMountTest(tests.Test): url_prefix = 'http://localhost:8800/context/' + guid self.assertEqual( [{'guid': guid, 'icon': url_prefix + '/icon', 'preview': url_prefix + '/preview'}], - remote.get(['context'], reply=['icon', 'preview'])['result']) + remote.get(['context'], reply=['guid', 'icon', 'preview'])['result']) self.assertEqual( {'icon': url_prefix + '/icon', 'preview': url_prefix + '/preview'}, remote.get(['context', guid], reply=['icon', 'preview'])) @@ -297,23 +297,19 @@ class RemoteMountTest(tests.Test): urllib2.urlopen(url_prefix + '/icon').read()) def test_GetAbsentBLOBs(self): - self.start_ipc_and_restful_server([User, Report]) + self.start_ipc_and_restful_server([User, Artifact]) remote = IPCClient(mountpoint='/') - guid = remote.post(['report'], { - 'context': 'context', - 'implementation': 'implementation', - 'description': 'description', - }) + guid = remote.post(['artifact'], {}) - self.assertRaises(RuntimeError, remote.get, ['report', guid, 'data']) - blob_url = 'http://localhost:8800/report/%s/data' % guid + self.assertRaises(RuntimeError, remote.get, ['artifact', guid, 'data']) + blob_url = 'http://localhost:8800/artifact/%s/data' % guid self.assertEqual( [{'guid': guid, 'data': blob_url}], - remote.get(['report'], reply=['data'])['result']) + remote.get(['artifact'], reply=['guid', 'data'])['result']) self.assertEqual( {'data': blob_url}, - remote.get(['report', guid], reply=['data'])) + remote.get(['artifact', guid], reply=['data'])) self.assertRaises(urllib2.HTTPError, urllib2.urlopen, blob_url) -- cgit v0.9.1