9308: Set task.keepTmpOutput: true when outputDirType is keep_output_dir.
[arvados.git] / sdk / cwl / tests / test_submit.py
index 21be5c71b9f904668c4813f57958edca4216e134..eb7199295144368d30da1122e435209e2c6323fa 100644 (file)
@@ -9,6 +9,7 @@ import hashlib
 import mock
 import sys
 import unittest
+import json
 
 from .matcher import JsonDiffMatcher
 
@@ -84,9 +85,23 @@ def stubs(func):
             'script_parameters': {
                 'x': {
                     'basename': 'blorp.txt',
-                    'location': '99999999999999999999999999999994+99/blorp.txt',
+                    'location': 'keep:99999999999999999999999999999994+99/blorp.txt',
                     'class': 'File'
                 },
+                'y': {
+                    'basename': '99999999999999999999999999999998+99',
+                    'location': 'keep:99999999999999999999999999999998+99',
+                    'class': 'Directory'
+                },
+                'z': {
+                    'basename': 'anonymous',
+                    "listing": [{
+                        "basename": "renamed.txt",
+                        "class": "File",
+                        "location": "keep:99999999999999999999999999999998+99/file1.txt"
+                    }],
+                    'class': 'Directory'
+                },
                 'cwl:tool':
                 '99999999999999999999999999999991+99/wf/submit_wf.cwl'
             },
@@ -111,7 +126,7 @@ def stubs(func):
                     'kind': 'file'
                 },
                 '/var/lib/cwl/job/cwl.input.json': {
-                    'portable_data_hash': '765fda0d9897729ff467a4609879c00a+60/cwl.input.json',
+                    'portable_data_hash': 'd20d7cddd1984f105dd3702c7f125afb+60/cwl.input.json',
                     'kind': 'collection'
                 }
             },
@@ -128,6 +143,12 @@ def stubs(func):
                 'ram': 268435456
             }
         }
+
+        stubs.expect_workflow_uuid = "zzzzz-7fd4e-zzzzzzzzzzzzzzz"
+        stubs.api.workflows().create().execute.return_value = {
+            "uuid": stubs.expect_workflow_uuid,
+        }
+
         return func(self, stubs, *args, **kwargs)
     return wrapped
 
@@ -148,7 +169,7 @@ class TestSubmit(unittest.TestCase):
                 'manifest_text':
                 './tool d51232d96b6116d964a69bfb7e0c73bf+450 '
                 '0:16:blub.txt 16:434:submit_tool.cwl\n./wf '
-                '4d31c5fefd087faf67ca8db0111af36c+353 0:353:submit_wf.cwl\n',
+                'cc2ffb940e60adf1b2b282c67587e43d+413 0:413:submit_wf.cwl\n',
                 'owner_uuid': 'zzzzz-tpzed-zzzzzzzzzzzzzzz',
                 'name': 'submit_wf.cwl',
             }, ensure_unique_name=True),
@@ -156,8 +177,8 @@ class TestSubmit(unittest.TestCase):
             mock.call(body={'manifest_text': '. d41d8cd98f00b204e9800998ecf8427e+0 '
                             '0:0:blub.txt 0:0:submit_tool.cwl\n',
                             'owner_uuid': 'zzzzz-tpzed-zzzzzzzzzzzzzzz',
-                            'name': 'New collection',
                             'replication_desired': None,
+                            'name': 'New collection'
             }, ensure_unique_name=True),
             mock.call().execute(num_retries=4),
             mock.call(body={
@@ -208,7 +229,7 @@ class TestSubmit(unittest.TestCase):
                 'manifest_text':
                 './tool d51232d96b6116d964a69bfb7e0c73bf+450 '
                 '0:16:blub.txt 16:434:submit_tool.cwl\n./wf '
-                '4d31c5fefd087faf67ca8db0111af36c+353 0:353:submit_wf.cwl\n',
+                'cc2ffb940e60adf1b2b282c67587e43d+413 0:413:submit_wf.cwl\n',
                 'owner_uuid': 'zzzzz-tpzed-zzzzzzzzzzzzzzz',
                 'name': 'submit_wf.cwl',
             }, ensure_unique_name=True),
@@ -244,7 +265,7 @@ class TestCreateTemplate(unittest.TestCase):
         capture_stdout = cStringIO.StringIO()
 
         exited = arvados_cwl.main(
-            ["--create-template", "--no-wait", "--debug",
+            ["--create-template", "--debug",
              "--project-uuid", project_uuid,
              "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
             capture_stdout, sys.stderr, api_client=stubs.api)
@@ -260,6 +281,17 @@ class TestCreateTemplate(unittest.TestCase):
             'type': 'File',
             'value': '99999999999999999999999999999994+99/blorp.txt',
         }
+        expect_component['script_parameters']['y'] = {
+            'dataclass': 'Collection',
+            'required': True,
+            'type': 'Directory',
+            'value': '99999999999999999999999999999998+99',
+        }
+        expect_component['script_parameters']['z'] = {
+            'dataclass': 'Collection',
+            'required': True,
+            'type': 'Directory',
+        }
         expect_template = {
             "components": {
                 "submit_wf.cwl": expect_component,
@@ -274,6 +306,41 @@ class TestCreateTemplate(unittest.TestCase):
                          stubs.expect_pipeline_template_uuid + '\n')
 
 
+class TestCreateWorkflow(unittest.TestCase):
+    @stubs
+    def test_create(self, stubs):
+        project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
+
+        capture_stdout = cStringIO.StringIO()
+
+        exited = arvados_cwl.main(
+            ["--create-workflow", "--debug",
+             "--project-uuid", project_uuid,
+             "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
+            capture_stdout, sys.stderr, api_client=stubs.api)
+        self.assertEqual(exited, 0)
+
+        stubs.api.pipeline_templates().create.refute_called()
+        stubs.api.container_requests().create.refute_called()
+
+        with open("tests/wf/expect_packed.cwl") as f:
+            expect_workflow = f.read()
+
+        body = {
+            "workflow": {
+                "owner_uuid": project_uuid,
+                "name": "submit_wf.cwl",
+                "description": "",
+                "definition": expect_workflow
+                }
+        }
+        stubs.api.workflows().create.assert_called_with(
+            body=JsonDiffMatcher(body))
+
+        self.assertEqual(capture_stdout.getvalue(),
+                         stubs.expect_workflow_uuid + '\n')
+
+
 class TestTemplateInputs(unittest.TestCase):
     expect_template = {
         "components": {