1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
15 import arvados_cwl.executor
16 from .mock_discovery import get_rootDesc
18 class TestMakeOutput(unittest.TestCase):
20 self.api = mock.MagicMock()
21 self.api._rootDesc = get_rootDesc()
23 @mock.patch("arvados.collection.Collection")
24 @mock.patch("arvados.collection.CollectionReader")
25 def test_make_output_collection(self, reader, col):
26 keep_client = mock.MagicMock()
27 runner = arvados_cwl.executor.ArvCwlExecutor(self.api, keep_client=keep_client)
28 runner.project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
30 final = mock.MagicMock()
31 col.return_value = final
32 readermock = mock.MagicMock()
33 reader.return_value = readermock
35 final_uuid = final.manifest_locator()
36 num_retries = runner.num_retries
38 cwlout = StringIO.StringIO()
39 openmock = mock.MagicMock()
40 final.open.return_value = openmock
41 openmock.__enter__.return_value = cwlout
43 _, runner.final_output_collection = runner.make_output_collection("Test output", ["foo"], "tag0,tag1,tag2", {
46 "location": "keep:99999999999999999999999999999991+99/foo.txt",
52 "location": "keep:99999999999999999999999999999992+99/bar.txt",
53 "basename": "baz.txt",
58 final.copy.assert_has_calls([mock.call('bar.txt', 'baz.txt', overwrite=False, source_collection=readermock)])
59 final.copy.assert_has_calls([mock.call('foo.txt', 'foo.txt', overwrite=False, source_collection=readermock)])
60 final.save_new.assert_has_calls([mock.call(ensure_unique_name=True, name='Test output', owner_uuid='zzzzz-j7d0g-zzzzzzzzzzzzzzz', storage_classes=['foo'])])
63 "basename": "baz.txt",
65 "location": "baz.txt",
69 "basename": "foo.txt",
71 "location": "foo.txt",
74 }""", cwlout.getvalue())
76 self.assertIs(final, runner.final_output_collection)
77 self.assertIs(final_uuid, runner.final_output_collection.manifest_locator())
78 self.api.links().create.assert_has_calls([mock.call(body={"head_uuid": final_uuid, "link_class": "tag", "name": "tag0"}), mock.call().execute(num_retries=num_retries)])
79 self.api.links().create.assert_has_calls([mock.call(body={"head_uuid": final_uuid, "link_class": "tag", "name": "tag1"}), mock.call().execute(num_retries=num_retries)])
80 self.api.links().create.assert_has_calls([mock.call(body={"head_uuid": final_uuid, "link_class": "tag", "name": "tag2"}), mock.call().execute(num_retries=num_retries)])