Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fmigneault committed Jul 8, 2022
1 parent d6b742f commit e78d7af
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 10 deletions.
10 changes: 7 additions & 3 deletions tests/functional/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,14 @@ def test_undeploy(self):

def test_describe(self):
result = mocked_sub_requests(self.app, self.client.describe, self.test_process["Echo"])
assert self.test_payload["Echo"]["version"] == "1.0", "Original version submitted should be partial."
assert self.test_payload["Echo"]["processDescription"]["process"]["version"] == "1.0", (
"Original version submitted should be partial."
)

assert result.success
# see deployment file for details that are expected here
assert result.body["id"] == self.test_process["Echo"]
assert result.body["version"] == "1.0.0", "Resulting version missing MAJOR.MINOR.PATCH parts should be padded."
assert result.body["version"] == "1.0"
assert result.body["keywords"] == ["test", "application"] # app is added by Weaver since not CWL Workflow
assert "message" in result.body["inputs"]
assert result.body["inputs"]["message"]["title"] == "message"
Expand All @@ -263,7 +265,9 @@ def test_describe(self):
assert result.body["outputs"]["output"]["description"] == "Output file with echo message."
assert result.body["outputs"]["output"]["formats"] == [{"default": True, "mediaType": ContentType.TEXT_PLAIN}]
assert "undefined" not in result.message, "CLI should not have confused process description as response detail."
assert "description" not in result.body, "CLI should not have overridden the process description field."
assert result.body["description"] == (
"Dummy process that simply echo's back the input message for testing purposes."
), "CLI should not have overridden the process description field."

def run_execute_inputs_schema_variant(self, inputs_param, process="Echo",
preload=False, location=False, expect_success=True, mock_exec=True):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_opensearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ def _get_mocked(req):
stack.enter_context(mock.patch("weaver.wps_restapi.processes.processes.get_db", side_effect=MockDB))
stack.enter_context(mock.patch("weaver.wps_restapi.processes.utils.get_db", side_effect=MockDB))
stack.enter_context(mock.patch("weaver.wps_restapi.processes.utils.get_settings", side_effect=_get_mocked))
stack.enter_context(mock.patch("weaver.database.get_settings", side_effect=_get_mocked))
stack.enter_context(mock.patch("weaver.database.mongodb.get_settings", side_effect=_get_mocked))
stack.enter_context(mock.patch("weaver.datatype.get_settings", side_effect=_get_mocked))
stack.enter_context(mock.patch("weaver.processes.utils.get_db", side_effect=MockDB))
stack.enter_context(mock.patch("weaver.processes.utils.get_settings", side_effect=_get_mocked))
Expand Down
2 changes: 1 addition & 1 deletion tests/wps_restapi/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ def test_jobs_list_schema_not_required_fields(self):
"""
uri = sd.openapi_json_service.path
resp = self.app.get(uri, headers=self.json_headers)
schema_prefix = sd.GetJobsQueries.__name__
schema_prefix = sd.GetProcessJobsQuery.__name__
assert not resp.json["parameters"][f"{schema_prefix}.page"]["required"]
assert not resp.json["parameters"][f"{schema_prefix}.limit"]["required"]

Expand Down
2 changes: 1 addition & 1 deletion tests/wps_restapi/test_processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,7 @@ def test_replace_process_valid(self):
"version": "4.3.2", # explicitly provided to avoid auto-bump to '3.0.0'
# use OAS representation in this case to validate it is still valid using update request
"inputs": {"number": {"schema": {"type": "integer", "minimum": 1, "maximum": 3}}},
"visible": Visibility.PUBLIC, # ensure we can retrieve the description later
"visibility": Visibility.PUBLIC, # ensure we can retrieve the description later
},
"executionUnit": [{"unit": cwl_v3}],
}
Expand Down
2 changes: 1 addition & 1 deletion weaver/datatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -1824,7 +1824,7 @@ def latest(self):
Checks if this :term:`Process` corresponds to the latest revision.
"""
# if ID loaded from DB contains a version, it is not the latest by design
return ":" not in self.id
return self.split_version(self.id)[-1] is None

@property
def name(self):
Expand Down
16 changes: 13 additions & 3 deletions weaver/processes/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@
# FIXME:
# https://github.com/crim-ca/weaver/issues/215
# define common Exception classes that won't require this type of conversion
def get_process(process_id=None, request=None, settings=None):
# type: (Optional[str], Optional[PyramidRequest], Optional[SettingsType]) -> Process
def get_process(process_id=None, request=None, settings=None, revision=True):
# type: (Optional[str], Optional[PyramidRequest], Optional[SettingsType], bool) -> Process
"""
Obtain the specified process and validate information, returning appropriate HTTP error if invalid.
Expand All @@ -115,11 +115,21 @@ def get_process(process_id=None, request=None, settings=None):
Different parameter combinations are intended to be used as needed or more appropriate, such that redundant
operations can be reduced where some objects are already fetched from previous operations.
:param process_id: Explicit :term:`Process` identifier to employ for lookup.
:param request: When no explicit ID specified, try to find information from the request.
:param settings:
Application settings for database connection. Can be guessed from local thread or request object if not given.
:param revision:
When parsing the :term:`Process` ID (either explicit or from request), indicate if any tagged revision
specifier should be used or dropped.
"""
store = get_db(settings or request).get_store(StoreProcesses)
try:
if process_id is None and request is not None:
process_id = resolve_process_tag(request)
if not revision:
process_id = Process.split_version(process_id)[0]
process = store.fetch_by_id(process_id, visibility=Visibility.PUBLIC)
return process
except (InvalidIdentifierValue, MissingIdentifierValue, colander.Invalid) as exc:
Expand Down Expand Up @@ -504,7 +514,7 @@ def _update_deploy_process_version(process, process_overwrite, update_level, con
"cause": {"mutable": False}
})

if not process.name == process_overwrite.name:
if process.name != process_overwrite.name:
raise HTTPBadRequest(json={
"type": "InvalidParameterValue",
"title": "Invalid process identifier.",
Expand Down
2 changes: 1 addition & 1 deletion weaver/wps_restapi/processes/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def put_local_process(request):
Updates the new process MAJOR semantic version from the previous one if not specified explicitly.
For MINOR or PATCH changes to metadata of the process definition, consider using the PATCH request.
"""
process = get_process(request=request)
process = get_process(request=request, revision=False) # ignore tagged version since must always be latest
return deploy_process_from_payload(request.text, request, overwrite=process)


Expand Down

0 comments on commit e78d7af

Please sign in to comment.