Skip to content

Commit

Permalink
add test cases for new CLI execute options -oC/-oP
Browse files Browse the repository at this point in the history
  • Loading branch information
fmigneault committed Oct 4, 2023
1 parent 3cb5412 commit c716fc8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
25 changes: 16 additions & 9 deletions tests/functional/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import pytest
from owslib.ows import DEFAULT_OWS_NAMESPACE
from owslib.wps import WPSException
from parameterized import parameterized
from pyramid.httpexceptions import HTTPForbidden, HTTPOk, HTTPUnauthorized
from webtest import TestApp as WebTestApp

Expand Down Expand Up @@ -1559,7 +1560,14 @@ def test_execute_result_by_reference(self):
data = file.read()
assert msg in data # technically, output is log of echoed input message, so not exactly equal

def test_execute_output_context(self):
@parameterized.expand(
[
(["-oP"], "public"),
(["-oC", "data"], "data"),
(["-oC", "test/nested"], "test/nested"),
]
)
def test_execute_output_context(self, cli_options, expect_output_context):
proc = self.test_process["Echo"]
with contextlib.ExitStack() as stack_exec:
for mock_exec_proc in mocked_execute_celery():
Expand All @@ -1576,13 +1584,14 @@ def test_execute_output_context(self):
"-M",
"-T", 10,
"-W", 1,
"-oP", # request public WPS output context
"-F", OutputFormat.YAML,
*cli_options,
],
trim=False,
entrypoint=weaver_cli,
only_local=True,
)
assert any(f"\"status\": \"{Status.SUCCEEDED}\"" in line for line in lines)
assert any(f"status: {Status.SUCCEEDED}" in line for line in lines)
job_id = None
for line in lines:
if line.startswith("jobID: "):
Expand All @@ -1605,19 +1614,17 @@ def test_execute_output_context(self):
only_local=True,
)
sep = lines.index("---")
headers = lines[:sep]
content = lines[sep + 1:]
assert content
link = None
for header in headers:
if "Link:" in header:
link = header.split(":", 1)[-1].strip()
for line in content:
if "href:" in line:
link = line.split(":", 1)[-1].strip()
break
assert link
link = link.split(";")[0].strip("<>")
wps_url = get_wps_output_url(self.settings)
wps_path = link.split(wps_url)[-1]
assert wps_path == f"/public/{job_id}/output/output.txt"
assert wps_path == f"/{expect_output_context}/{job_id}/output/stdout.log"

def test_execute_help_details(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion weaver/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2531,7 +2531,7 @@ def make_parser():
)
op_execute_output_context = op_execute.add_mutually_exclusive_group()
op_execute_output_context.add_argument(
"-oP", "--output-public", dest="output_context", const="public",
"-oP", "--output-public", dest="output_context", const="public", action="store_const",
help=(
"Set header 'X-WPS-Output-Context: public' to indicate preference of job output context to be "
"located under the public WPS output location of the server. The server is not mandated to fulfill this "
Expand Down

0 comments on commit c716fc8

Please sign in to comment.