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