From: Peter Amstutz Date: Wed, 20 Aug 2014 02:10:10 +0000 (-0400) Subject: 3036: Fix arv-put to write name/owner of collections object directly when X-Git-Tag: 1.1.0~2275^2~18 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/d08c3a56c462a0277aba6f67e0551214f1510102?hp=57d7ce9de300d1340ed12d61248e7cea6bd1be15 3036: Fix arv-put to write name/owner of collections object directly when 'name' field is present on the returned object. Python SDK tests pass. --- diff --git a/sdk/python/arvados/commands/put.py b/sdk/python/arvados/commands/put.py index 335ef174de..71e31b2418 100644 --- a/sdk/python/arvados/commands/put.py +++ b/sdk/python/arvados/commands/put.py @@ -455,7 +455,12 @@ def main(arguments=None, stdout=sys.stdout, stderr=sys.stderr): output = collection['uuid'] if project_link is not None: try: - create_project_link(output, project_link) + if 'name' in collection: + arvados.api().collections().update(uuid=output, + body={"owner_uuid": project_link["tail_uuid"], + "name": project_link["name"]}).execute() + else: + create_project_link(output, project_link) except apiclient.errors.Error as error: print >>stderr, ( "arv-put: Error adding Collection to project: {}.".format( diff --git a/sdk/python/tests/test_arv_put.py b/sdk/python/tests/test_arv_put.py index 9bc385d2e6..5c84c48c25 100644 --- a/sdk/python/tests/test_arv_put.py +++ b/sdk/python/tests/test_arv_put.py @@ -551,9 +551,8 @@ class ArvPutIntegrationTest(unittest.TestCase): p = subprocess.Popen([sys.executable, arv_put.__file__, datadir], stdout=subprocess.PIPE, env=self.ENVIRON) (arvout, arverr) = p.communicate() - self.assertEqual(p.returncode, 0) self.assertEqual(arverr, None) - self.assertEqual(arvout.strip(), manifest_uuid) + self.assertEqual(p.returncode, 0) # The manifest text stored in the API server under the same # manifest UUID must use signed locators. @@ -565,21 +564,20 @@ class ArvPutIntegrationTest(unittest.TestCase): os.remove(os.path.join(datadir, "foo")) os.rmdir(datadir) - def run_and_find_link(self, text, extra_args=[]): + def run_and_find_collection(self, text, extra_args=[]): self.authorize_with('active') pipe = subprocess.Popen( [sys.executable, arv_put.__file__] + extra_args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=self.ENVIRON) stdout, stderr = pipe.communicate(text) - link_list = arvados.api('v1', cache=False).links().list( - filters=[['head_uuid', '=', stdout.strip()], - ['link_class', '=', 'name']]).execute().get('items', []) - self.assertEqual(1, len(link_list)) - return link_list[0] + collection_list = arvados.api('v1', cache=False).collections().list( + filters=[['uuid', '=', stdout.strip()]]).execute().get('items', []) + self.assertEqual(1, len(collection_list)) + return collection_list[0] def test_put_collection_with_unnamed_project_link(self): - link = self.run_and_find_link("Test unnamed collection", + link = self.run_and_find_collection("Test unnamed collection", ['--project-uuid', self.PROJECT_UUID]) username = pwd.getpwuid(os.getuid()).pw_name self.assertRegexpMatches( @@ -588,19 +586,18 @@ class ArvPutIntegrationTest(unittest.TestCase): def test_put_collection_with_name_and_no_project(self): link_name = 'Test Collection Link in home project' - link = self.run_and_find_link("Test named collection in home project", + collection = self.run_and_find_collection("Test named collection in home project", ['--name', link_name]) - self.assertEqual(link_name, link['name']) + self.assertEqual(link_name, collection['name']) my_user_uuid = self.current_user()['uuid'] - self.assertEqual(my_user_uuid, link['tail_uuid']) - self.assertEqual(my_user_uuid, link['owner_uuid']) + self.assertEqual(my_user_uuid, collection['owner_uuid']) def test_put_collection_with_named_project_link(self): link_name = 'Test auto Collection Link' - link = self.run_and_find_link("Test named collection", + collection = self.run_and_find_collection("Test named collection", ['--name', link_name, '--project-uuid', self.PROJECT_UUID]) - self.assertEqual(link_name, link['name']) + self.assertEqual(link_name, collection['name']) if __name__ == '__main__':