1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
5 from __future__ import absolute_import
12 from arvados.collection import Collection, CollectionReader
14 import arvados.commands.arv_copy as arv_copy
15 from . import arvados_testutil as tutil
16 from . import run_test_server
18 class ArvCopyVersionTestCase(run_test_server.TestCaseWithServers, tutil.VersionChecker):
22 def run_copy(self, args):
23 sys.argv = ['arv-copy'] + args
24 return arv_copy.main()
26 def test_unsupported_arg(self):
27 with self.assertRaises(SystemExit):
28 self.run_copy(['-x=unknown'])
30 def test_version_argument(self):
31 with tutil.redirected_streams(
32 stdout=tutil.StringIO, stderr=tutil.StringIO) as (out, err):
33 with self.assertRaises(SystemExit):
34 self.run_copy(['--version'])
35 self.assertVersionOutput(out, err)
37 def test_copy_project(self):
39 src_proj = api.groups().create(body={"group": {"name": "arv-copy project", "group_class": "project"}}).execute()["uuid"]
42 with c.open('foo', 'wt') as f:
44 c.save_new("arv-copy foo collection", owner_uuid=src_proj)
46 dest_proj = api.groups().create(body={"group": {"name": "arv-copy dest project", "group_class": "project"}}).execute()["uuid"]
48 tmphome = tempfile.mkdtemp()
49 home_was = os.environ['HOME']
50 os.environ['HOME'] = tmphome
52 cfgdir = os.path.join(tmphome, ".config", "arvados")
54 with open(os.path.join(cfgdir, "zzzzz.conf"), "wt") as f:
55 f.write("ARVADOS_API_HOST=%s\n" % os.environ["ARVADOS_API_HOST"])
56 f.write("ARVADOS_API_TOKEN=%s\n" % os.environ["ARVADOS_API_TOKEN"])
57 f.write("ARVADOS_API_HOST_INSECURE=1\n")
59 contents = api.groups().list(filters=[["owner_uuid", "=", dest_proj]]).execute()
60 assert len(contents["items"]) == 0
63 self.run_copy(["--project-uuid", dest_proj, src_proj])
64 except SystemExit as e:
67 contents = api.groups().list(filters=[["owner_uuid", "=", dest_proj]]).execute()
68 assert len(contents["items"]) == 1
70 assert contents["items"][0]["name"] == "arv-copy project"
71 copied_project = contents["items"][0]["uuid"]
73 contents = api.collections().list(filters=[["owner_uuid", "=", copied_project]]).execute()
74 assert len(contents["items"]) == 1
76 assert contents["items"][0]["uuid"] != c.manifest_locator()
77 assert contents["items"][0]["name"] == "arv-copy foo collection"
78 assert contents["items"][0]["portable_data_hash"] == c.portable_data_hash()
81 os.environ['HOME'] = home_was
82 shutil.rmtree(tmphome)