1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
15 from .mock_discovery import get_rootDesc
17 class TestMakeOutput(unittest.TestCase):
19 self.api = mock.MagicMock()
20 self.api._rootDesc = get_rootDesc()
22 @mock.patch("arvados.collection.Collection")
23 @mock.patch("arvados.collection.CollectionReader")
24 def test_make_output_collection(self, reader, col):
25 keep_client = mock.MagicMock()
26 runner = arvados_cwl.ArvCwlRunner(self.api, keep_client=keep_client)
27 runner.project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
29 final = mock.MagicMock()
30 col.return_value = final
31 readermock = mock.MagicMock()
32 reader.return_value = readermock
34 final_uuid = final.manifest_locator()
35 num_retries = runner.num_retries
37 cwlout = StringIO.StringIO()
38 openmock = mock.MagicMock()
39 final.open.return_value = openmock
40 openmock.__enter__.return_value = cwlout
42 _, runner.final_output_collection = runner.make_output_collection("Test output", ["foo"], "tag0,tag1,tag2", {
45 "location": "keep:99999999999999999999999999999991+99/foo.txt",
51 "location": "keep:99999999999999999999999999999992+99/bar.txt",
52 "basename": "baz.txt",
57 final.copy.assert_has_calls([mock.call('bar.txt', 'baz.txt', overwrite=False, source_collection=readermock)])
58 final.copy.assert_has_calls([mock.call('foo.txt', 'foo.txt', overwrite=False, source_collection=readermock)])
59 final.save_new.assert_has_calls([mock.call(ensure_unique_name=True, name='Test output', owner_uuid='zzzzz-j7d0g-zzzzzzzzzzzzzzz', storage_classes=['foo'])])
62 "basename": "baz.txt",
64 "location": "baz.txt",
68 "basename": "foo.txt",
70 "location": "foo.txt",
73 }""", cwlout.getvalue())
75 self.assertIs(final, runner.final_output_collection)
76 self.assertIs(final_uuid, runner.final_output_collection.manifest_locator())
77 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)])
78 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)])
79 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)])