Fix typo and modify test
[arvados.git] / sdk / cwl / tests / test_make_output.py
1 import functools
2 import json
3 import logging
4 import mock
5 import os
6 import StringIO
7 import unittest
8
9 import arvados
10 import arvados_cwl
11 from .mock_discovery import get_rootDesc
12
13 class TestMakeOutput(unittest.TestCase):
14     def setUp(self):
15         self.api = mock.MagicMock()
16         self.api._rootDesc = get_rootDesc()
17
18     @mock.patch("arvados.collection.Collection")
19     @mock.patch("arvados.collection.CollectionReader")
20     def test_make_output_collection(self, reader, col):
21         keep_client = mock.MagicMock()
22         runner = arvados_cwl.ArvCwlRunner(self.api, keep_client=keep_client)
23         runner.project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
24
25         final = mock.MagicMock()
26         col.return_value = final
27         readermock = mock.MagicMock()
28         reader.return_value = readermock
29
30         final_uuid = final.manifest_locator()
31
32         cwlout = StringIO.StringIO()
33         openmock = mock.MagicMock()
34         final.open.return_value = openmock
35         openmock.__enter__.return_value = cwlout
36
37         runner.make_output_collection("Test output", "tag0,tag1,tag2", {
38             "foo": {
39                 "class": "File",
40                 "location": "keep:99999999999999999999999999999991+99/foo.txt",
41                 "size": 3,
42                 "basename": "foo.txt"
43             },
44             "bar": {
45                 "class": "File",
46                 "location": "keep:99999999999999999999999999999992+99/bar.txt",
47                 "basename": "baz.txt"
48             }
49         })
50
51         final.copy.assert_has_calls([mock.call('bar.txt', 'baz.txt', overwrite=False, source_collection=readermock)])
52         final.copy.assert_has_calls([mock.call('foo.txt', 'foo.txt', overwrite=False, source_collection=readermock)])
53         final.save_new.assert_has_calls([mock.call(ensure_unique_name=True, name='Test output', owner_uuid='zzzzz-j7d0g-zzzzzzzzzzzzzzz')])
54         self.assertEqual("""{
55     "bar": {
56         "class": "File",
57         "location": "baz.txt"
58     },
59     "foo": {
60         "class": "File",
61         "location": "foo.txt"
62     }
63 }""", cwlout.getvalue())
64
65         self.assertIs(final, runner.final_output_collection)
66         self.assertIs(final_uuid, runner.final_output_collection.manifest_locator())
67         self.api.links().create.assert_has_calls([mock.call(body={"head_uuid": final_uuid, "link_class": "tag", "name": "tag0"}), mock.call().execute()])
68         self.api.links().create.assert_has_calls([mock.call(body={"head_uuid": final_uuid, "link_class": "tag", "name": "tag1"}), mock.call().execute()])
69         self.api.links().create.assert_has_calls([mock.call(body={"head_uuid": final_uuid, "link_class": "tag", "name": "tag2"}), mock.call().execute()])