7 import arvados.collection
10 class TestSubmit(unittest.TestCase):
11 @mock.patch("arvados.commands.keepdocker.list_images_in_arv")
12 @mock.patch("arvados.collection.KeepClient")
13 @mock.patch("arvados.events.subscribe")
14 def test_submit(self, events, keep, keepdocker):
15 api = mock.MagicMock()
16 def putstub(p, **kwargs):
17 return "%s+%i" % (hashlib.md5(p).hexdigest(), len(p))
18 keep().put.side_effect = putstub
19 keepdocker.return_value = True
20 user_uuid = "zzzzz-tpzed-zzzzzzzzzzzzzzz"
21 api.users().current().execute.return_value = {"uuid": user_uuid}
22 api.collections().list().execute.return_value = {"items": []}
23 api.collections().create().execute.side_effect = ({"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzz1",
24 "portable_data_hash": "99999999999999999999999999999991+99"},
25 {"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzz2",
26 "portable_data_hash": "99999999999999999999999999999992+99"})
27 api.jobs().create().execute.return_value = {"uuid": "zzzzz-8i9sb-zzzzzzzzzzzzzzz", "state": "Queued"}
29 arvados_cwl.main(["--debug", "--submit", "--no-wait", "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
30 sys.stdout, sys.stderr, api_client=api)
32 api.collections().create.assert_has_calls([
34 mock.call(body={'manifest_text': './tool 84ec4df683711de31b782505389a8843+429 0:16:blub.txt 16:413:submit_tool.cwl\n./wf 81d977a245a41b8e79859fbe00623fd0+344 0:344:submit_wf.cwl\n',
35 'owner_uuid': 'zzzzz-tpzed-zzzzzzzzzzzzzzz',
36 'name': 'submit_wf.cwl'
37 }, ensure_unique_name=True),
38 mock.call().execute(),
39 mock.call(body={'manifest_text': '. 979af1245a12a1fed634d4222473bfdc+16 0:16:blorp.txt\n',
40 'owner_uuid': 'zzzzz-tpzed-zzzzzzzzzzzzzzz',
42 }, ensure_unique_name=True),
43 mock.call().execute()])
45 api.jobs().create.assert_called_with(
47 'owner_uuid': user_uuid,
48 'runtime_constraints': {
49 'docker_image': 'arvados/jobs'
51 'script_parameters': {
53 'path': '99999999999999999999999999999992+99/blorp.txt',
56 'cwl:tool': '99999999999999999999999999999991+99/wf/submit_wf.cwl'
58 'repository': 'arvados',
59 'script_version': 'master',
60 'script': 'cwl-runner'
64 @mock.patch("arvados.commands.keepdocker.list_images_in_arv")
65 @mock.patch("arvados.collection.KeepClient")
66 @mock.patch("arvados.events.subscribe")
67 def test_submit_with_project_uuid(self, events, keep, keepdocker):
68 api = mock.MagicMock()
69 def putstub(p, **kwargs):
70 return "%s+%i" % (hashlib.md5(p).hexdigest(), len(p))
71 keep().put.side_effect = putstub
72 keepdocker.return_value = True
73 api.users().current().execute.return_value = {"uuid": "zzzzz-tpzed-zzzzzzzzzzzzzzz"}
74 api.collections().list().execute.return_value = {"items": []}
75 api.collections().create().execute.side_effect = ({"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzz1",
76 "portable_data_hash": "99999999999999999999999999999991+99"},
77 {"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzz2",
78 "portable_data_hash": "99999999999999999999999999999992+99"})
79 api.jobs().create().execute.return_value = {"uuid": "zzzzz-8i9sb-zzzzzzzzzzzzzzz", "state": "Queued"}
80 project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
82 arvados_cwl.main(["--debug", "--submit", "--project-uuid", project_uuid,
83 "--no-wait", "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
84 sys.stdout, sys.stderr, api_client=api)
86 api.jobs().create.assert_called_with(
88 'owner_uuid': project_uuid,
89 'runtime_constraints': {
90 'docker_image': 'arvados/jobs'
92 'script_parameters': {
94 'path': '99999999999999999999999999999992+99/blorp.txt',
97 'cwl:tool': '99999999999999999999999999999991+99/wf/submit_wf.cwl'
99 'repository': 'arvados',
100 'script_version': 'master',
101 'script': 'cwl-runner'