Skip to content

Commit

Permalink
Implement json handling for result links
Browse files Browse the repository at this point in the history
  • Loading branch information
totycro committed Dec 9, 2024
1 parent d185a61 commit 03e2551
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.6.1
* Fix json output in results

## 1.6.0
* Implement fetching results from external resource

Expand Down
9 changes: 8 additions & 1 deletion pygeoapi_kubernetes_papermill/argo.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,14 @@ def get_job_result(self, job_id) -> tuple[Optional[str], Optional[Any]]:

response = requests.get(resolved_url)
response.raise_for_status()
return response.headers.get("content-type"), response.content

content_type = response.headers.get("content-type")
# in case of json, pygeoapi wants to encode the data itself, so we decode
content = (
response.json() if content_type == "application/json" else response.content
)

return content_type, content

def delete_job(self, job_id) -> bool:
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/test_argo_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def mock_fetch_job_result():
response = requests.Response()
response.status_code = HTTPStatus.OK
response.headers["content-type"] = "application/json"
response._content = b"{'a': 3}"
response._content = b'{"a": 3}'

with mock.patch(
"pygeoapi_kubernetes_papermill.argo.requests.get",
Expand All @@ -157,7 +157,7 @@ def test_result_link_is_resolved(manager: ArgoManager, mock_fetch_job_result):
job_id = "abc-123"
result = manager.get_job_result(job_id)

assert result == ("application/json", b"{'a': 3}")
assert result == ("application/json", {"a": 3})

mock_fetch_job_result.assert_called_with("https://example.com/a/abc-123")

Expand Down

0 comments on commit 03e2551

Please sign in to comment.