From 85dfe8ac23f2816bb10fda02e90169ba74587c6f Mon Sep 17 00:00:00 2001 From: suecharo Date: Thu, 7 May 2020 19:37:47 +0900 Subject: [PATCH] Add Post runs examples --- .gitignore | 1 + .../post_runs_examples/access_remote_files.py | 54 +++++++++++++++++ tests/post_runs_examples/attach_all_files.py | 59 +++++++++++++++++++ .../get_inputs_from_mount.py | 48 +++++++++++++++ .../put_outputs_on_mount.py | 56 ++++++++++++++++++ .../__init__.py | 0 .../test_access_remote_files.py | 0 .../test_attach_all_files.py | 0 .../test_get_inputs_from_mount.py | 0 tests/test_get_run_id.py | 2 +- tests/test_get_run_id_status.py | 2 +- tests/test_get_runs.py | 2 +- tests/test_post_run_id_cancel.py | 2 +- 13 files changed, 222 insertions(+), 4 deletions(-) create mode 100644 tests/post_runs_examples/access_remote_files.py create mode 100644 tests/post_runs_examples/attach_all_files.py create mode 100644 tests/post_runs_examples/get_inputs_from_mount.py create mode 100644 tests/post_runs_examples/put_outputs_on_mount.py rename tests/{post_runs => post_runs_tests}/__init__.py (100%) rename tests/{post_runs => post_runs_tests}/test_access_remote_files.py (100%) rename tests/{post_runs => post_runs_tests}/test_attach_all_files.py (100%) rename tests/{post_runs => post_runs_tests}/test_get_inputs_from_mount.py (100%) diff --git a/.gitignore b/.gitignore index e7ce61c..ef839d4 100644 --- a/.gitignore +++ b/.gitignore @@ -226,3 +226,4 @@ cython_debug/ .gitkeep run/ +tests/resources/outputs/ diff --git a/tests/post_runs_examples/access_remote_files.py b/tests/post_runs_examples/access_remote_files.py new file mode 100644 index 0000000..e3e056b --- /dev/null +++ b/tests/post_runs_examples/access_remote_files.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 +# coding: utf-8 +import json +from pathlib import Path +from typing import BinaryIO, Dict, Tuple + +import requests +from requests import Response + +from genpei.type import RunRequest + +URL: str = "localhost:8080" +SCRIPT_DIR: Path = \ + Path(__file__).parent.resolve() +RES_D: Path = \ + SCRIPT_DIR.parent.joinpath("resources").resolve() + + +def main() -> None: + data: RunRequest = { + "workflow_params": json.dumps({ + "fastq_1": { + "class": "File", + "location": "https://raw.githubusercontent.com/suecharo/" + + "genpei/master/tests/resources/" + + "ERR034597_1.small.fq.gz" + }, + "fastq_2": { + "class": "File", + "location": "https://raw.githubusercontent.com/suecharo/" + + "genpei/master/tests/resources/" + + "ERR034597_2.small.fq.gz" + } + }), + "workflow_type": "CWL", + "workflow_type_version": "v1.0", + "tags": json.dumps({ + "workflow_name": "trimming_and_qc_remote" + }), + "workflow_engine_parameters": json.dumps({}), + "workflow_url": "https://raw.githubusercontent.com/suecharo/" + + "genpei/master/tests/resources/" + + "trimming_and_qc_remote.cwl" + } + files: Dict[str, Tuple[str, BinaryIO]] = {} + response: Response = \ + requests.post(f"http://{URL}/runs", data=data, files=files) + + print(response.status_code) + print(json.dumps(json.loads(response.text), indent=2)) + + +if __name__ == "__main__": + main() diff --git a/tests/post_runs_examples/attach_all_files.py b/tests/post_runs_examples/attach_all_files.py new file mode 100644 index 0000000..7b0ac43 --- /dev/null +++ b/tests/post_runs_examples/attach_all_files.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 +# coding: utf-8 +import json +from pathlib import Path +from typing import BinaryIO, Dict, Tuple + +import requests +from requests import Response + +from genpei.type import RunRequest + +URL: str = "localhost:8080" +SCRIPT_DIR: Path = \ + Path(__file__).parent.resolve() +RES_D: Path = \ + SCRIPT_DIR.parent.joinpath("resources").resolve() + + +def main() -> None: + data: RunRequest = { + "workflow_params": json.dumps({ + "fastq_1": { + "class": "File", + "path": "./ERR034597_1.small.fq.gz" + }, + "fastq_2": { + "class": "File", + "path": "./ERR034597_1.small.fq.gz" + } + }), + "workflow_type": "CWL", + "workflow_type_version": "v1.0", + "tags": json.dumps({ + "workflow_name": "trimming_and_qc_remote" + }), + "workflow_engine_parameters": json.dumps({}), + "workflow_url": "./trimming_and_qc.cwl" + } + files: Dict[str, Tuple[str, BinaryIO]] = { + "fastq_1": ("ERR034597_1.small.fq.gz", + RES_D.joinpath("ERR034597_1.small.fq.gz").open(mode="rb")), + "fastq_2": ("ERR034597_2.small.fq.gz", + RES_D.joinpath("ERR034597_2.small.fq.gz").open(mode="rb")), + "workflow": ("trimming_and_qc.cwl", + RES_D.joinpath("trimming_and_qc.cwl").open(mode="rb")), + "tool_1": ("fastqc.cwl", + RES_D.joinpath("fastqc.cwl").open(mode="rb")), + "tool_2": ("trimmomatic_pe.cwl", + RES_D.joinpath("trimmomatic_pe.cwl").open(mode="rb")) + } + response: Response = \ + requests.post(f"http://{URL}/runs", data=data, files=files) + + print(response.status_code) + print(json.dumps(json.loads(response.text), indent=2)) + + +if __name__ == "__main__": + main() diff --git a/tests/post_runs_examples/get_inputs_from_mount.py b/tests/post_runs_examples/get_inputs_from_mount.py new file mode 100644 index 0000000..2918897 --- /dev/null +++ b/tests/post_runs_examples/get_inputs_from_mount.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 +# coding: utf-8 +import json +from pathlib import Path +from typing import BinaryIO, Dict, Tuple + +import requests +from requests import Response + +from genpei.type import RunRequest + +URL: str = "localhost:8080" +SCRIPT_DIR: Path = \ + Path(__file__).parent.resolve() +RES_D: Path = \ + SCRIPT_DIR.parent.joinpath("resources").resolve() + + +def main() -> None: + data: RunRequest = { + "workflow_params": json.dumps({ + "fastq_1": { + "class": "File", + "location": str(RES_D.joinpath("ERR034597_1.small.fq.gz")) + }, + "fastq_2": { + "class": "File", + "location": str(RES_D.joinpath("ERR034597_2.small.fq.gz")) + } + }), + "workflow_type": "CWL", + "workflow_type_version": "v1.0", + "tags": json.dumps({ + "workflow_name": "trimming_and_qc" + }), + "workflow_engine_parameters": json.dumps({}), + "workflow_url": str(RES_D.joinpath("trimming_and_qc.cwl")) + } + files: Dict[str, Tuple[str, BinaryIO]] = {} + response: Response = requests.post( + f"http://{URL}/runs", data=data, files=files) + + print(response.status_code) + print(json.dumps(json.loads(response.text), indent=2)) + + +if __name__ == "__main__": + main() diff --git a/tests/post_runs_examples/put_outputs_on_mount.py b/tests/post_runs_examples/put_outputs_on_mount.py new file mode 100644 index 0000000..8f5e97a --- /dev/null +++ b/tests/post_runs_examples/put_outputs_on_mount.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +# coding: utf-8 +import json +from pathlib import Path +from typing import BinaryIO, Dict, Tuple + +import requests +from requests import Response + +from genpei.type import RunRequest + +URL: str = "localhost:8080" +SCRIPT_DIR: Path = \ + Path(__file__).parent.resolve() +RES_D: Path = \ + SCRIPT_DIR.parent.joinpath("resources").resolve() + + +def main() -> None: + data: RunRequest = { + "workflow_params": json.dumps({ + "fastq_1": { + "class": "File", + "location": "https://raw.githubusercontent.com/suecharo/" + + "genpei/master/tests/resources/" + + "ERR034597_1.small.fq.gz" + }, + "fastq_2": { + "class": "File", + "location": "https://raw.githubusercontent.com/suecharo/" + + "genpei/master/tests/resources/" + + "ERR034597_2.small.fq.gz" + } + }), + "workflow_type": "CWL", + "workflow_type_version": "v1.0", + "tags": json.dumps({ + "workflow_name": "trimming_and_qc_remote" + }), + "workflow_engine_parameters": json.dumps({ + "--outdir": str(RES_D.joinpath("outputs")) + }), + "workflow_url": "https://raw.githubusercontent.com/suecharo/" + + "genpei/master/tests/resources/" + + "trimming_and_qc_remote.cwl" + } + files: Dict[str, Tuple[str, BinaryIO]] = {} + response: Response = \ + requests.post(f"http://{URL}/runs", data=data, files=files) + + print(response.status_code) + print(json.dumps(json.loads(response.text), indent=2)) + + +if __name__ == "__main__": + main() diff --git a/tests/post_runs/__init__.py b/tests/post_runs_tests/__init__.py similarity index 100% rename from tests/post_runs/__init__.py rename to tests/post_runs_tests/__init__.py diff --git a/tests/post_runs/test_access_remote_files.py b/tests/post_runs_tests/test_access_remote_files.py similarity index 100% rename from tests/post_runs/test_access_remote_files.py rename to tests/post_runs_tests/test_access_remote_files.py diff --git a/tests/post_runs/test_attach_all_files.py b/tests/post_runs_tests/test_attach_all_files.py similarity index 100% rename from tests/post_runs/test_attach_all_files.py rename to tests/post_runs_tests/test_attach_all_files.py diff --git a/tests/post_runs/test_get_inputs_from_mount.py b/tests/post_runs_tests/test_get_inputs_from_mount.py similarity index 100% rename from tests/post_runs/test_get_inputs_from_mount.py rename to tests/post_runs_tests/test_get_inputs_from_mount.py diff --git a/tests/test_get_run_id.py b/tests/test_get_run_id.py index f76ab42..b97ea33 100644 --- a/tests/test_get_run_id.py +++ b/tests/test_get_run_id.py @@ -23,7 +23,7 @@ def test_get_run_id(tmpdir: LocalPath) -> None: app: Flask = create_app(Path(tmpdir)) app.testing = True client: FlaskClient[Response] = app.test_client() - from .post_runs.test_access_remote_files import access_remote_files + from .post_runs_tests.test_access_remote_files import access_remote_files posts_res: Response = access_remote_files(client) posts_res_data: RunId = posts_res.get_json() diff --git a/tests/test_get_run_id_status.py b/tests/test_get_run_id_status.py index 3816841..5664c30 100644 --- a/tests/test_get_run_id_status.py +++ b/tests/test_get_run_id_status.py @@ -23,7 +23,7 @@ def test_get_runs(tmpdir: LocalPath) -> None: app: Flask = create_app(Path(tmpdir)) app.testing = True client: FlaskClient[Response] = app.test_client() - from .post_runs.test_access_remote_files import access_remote_files + from .post_runs_tests.test_access_remote_files import access_remote_files posts_res: Response = access_remote_files(client) posts_res_data: RunId = posts_res.get_json() diff --git a/tests/test_get_runs.py b/tests/test_get_runs.py index fd5ea23..270ef06 100644 --- a/tests/test_get_runs.py +++ b/tests/test_get_runs.py @@ -22,7 +22,7 @@ def test_get_runs(tmpdir: LocalPath) -> None: app: Flask = create_app(Path(tmpdir)) app.testing = True client: FlaskClient[Response] = app.test_client() - from .post_runs.test_access_remote_files import access_remote_files + from .post_runs_tests.test_access_remote_files import access_remote_files posts_res: Response = access_remote_files(client) posts_res_data: RunId = posts_res.get_json() diff --git a/tests/test_post_run_id_cancel.py b/tests/test_post_run_id_cancel.py index 9b9c9bf..c2c607d 100644 --- a/tests/test_post_run_id_cancel.py +++ b/tests/test_post_run_id_cancel.py @@ -23,7 +23,7 @@ def test_post_run_id_cancel(tmpdir: LocalPath) -> None: app: Flask = create_app(Path(tmpdir)) app.testing = True client: FlaskClient[Response] = app.test_client() - from .post_runs.test_access_remote_files import access_remote_files + from .post_runs_tests.test_access_remote_files import access_remote_files posts_res: Response = access_remote_files(client) posts_res_data: RunId = posts_res.get_json()