3036: Fix arv-put to write name/owner of collections object directly when
authorPeter Amstutz <peter.amstutz@curoverse.com>
Wed, 20 Aug 2014 02:10:10 +0000 (22:10 -0400)
committerPeter Amstutz <peter.amstutz@curoverse.com>
Wed, 20 Aug 2014 02:10:10 +0000 (22:10 -0400)
'name' field is present on the returned object.  Python SDK tests pass.

sdk/python/arvados/commands/put.py
sdk/python/tests/test_arv_put.py

index 335ef174de6dcb860f6d13ee9ec32e330d54cc31..71e31b24184079a00ccfc69ecccdd75b83e97350 100644 (file)
@@ -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(
index 9bc385d2e6645cabaf140a7573c13a7705951090..5c84c48c25111128aa669aba784b9aac8fc01588 100644 (file)
@@ -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__':