1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
10 from arvados_cwl.util import *
11 from arvados.errors import ApiError
13 class MockDateTime(datetime.datetime):
16 return datetime.datetime(2018, 1, 1, 0, 0, 0, 0)
18 datetime.datetime = MockDateTime
20 class TestUtil(unittest.TestCase):
21 def test_get_intermediate_collection_info(self):
23 current_container = {"uuid": "zzzzz-8i9sb-zzzzzzzzzzzzzzz"}
24 intermediate_output_ttl = 120
26 info = get_intermediate_collection_info(name, current_container, intermediate_output_ttl)
28 self.assertEqual(info["name"], "Intermediate collection for step one")
29 self.assertEqual(info["trash_at"], datetime.datetime(2018, 1, 1, 0, 2, 0, 0))
30 self.assertEqual(info["properties"], {"type" : "intermediate", "container" : "zzzzz-8i9sb-zzzzzzzzzzzzzzz"})
32 def test_get_current_container_success(self):
33 api = mock.MagicMock()
34 api.containers().current().execute.return_value = {"uuid" : "zzzzz-8i9sb-zzzzzzzzzzzzzzz"}
36 current_container = get_current_container(api)
38 self.assertEqual(current_container, {"uuid" : "zzzzz-8i9sb-zzzzzzzzzzzzzzz"})
40 def test_get_current_container_error(self):
41 api = mock.MagicMock()
42 api.containers().current().execute.side_effect = ApiError(httplib2.Response({"status": 300}), "")
43 logger = mock.MagicMock()
45 self.assertRaises(ApiError, get_current_container(api, num_retries=0, logger=logger))