17962: Add test that uuid of project is printed on stdout
[arvados.git] / sdk / python / tests / test_sdk.py
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: Apache-2.0
4
5 import mock
6 import os
7 import unittest
8
9 import arvados
10 import arvados.collection
11
12 class TestSDK(unittest.TestCase):
13
14     @mock.patch('arvados.current_task')
15     @mock.patch('arvados.current_job')
16     def test_one_task_per_input_file_normalize(self, mock_job, mock_task):
17         mock_api = mock.MagicMock()
18
19         # This manifest will be reduced from three lines to one when it is
20         # normalized.
21         nonnormalized_manifest = """. 5348b82a029fd9e971a811ce1f71360b+43 0:43:md5sum.txt
22 . 085c37f02916da1cad16f93c54d899b7+41 0:41:md5sum.txt
23 . 8b22da26f9f433dea0a10e5ec66d73ba+43 0:43:md5sum.txt
24 """
25         dummy_hash = 'ffffffffffffffffffffffffffffffff+0'
26
27         mock_job.return_value = {
28             'uuid': 'none',
29             'script_parameters': {
30                 'input': dummy_hash
31             }
32         }
33         mock_task.return_value = {
34             'uuid': 'none',
35             'sequence': 0,
36         }
37         # mock the API client to return a collection with a nonnormalized manifest.
38         mock_api.collections().get().execute.return_value = {
39             'uuid': 'zzzzz-4zz18-mockcollection0',
40             'portable_data_hash': dummy_hash,
41             'manifest_text': nonnormalized_manifest,
42         }
43
44         # Because one_task_per_input_file normalizes this collection,
45         # it should now create only one job task and not three.
46         arvados.job_setup.one_task_per_input_file(and_end_task=False, api_client=mock_api)
47         mock_api.job_tasks().create().execute.assert_called_once_with()