Skip to content

Commit

Permalink
update protocol stripping
Browse files Browse the repository at this point in the history
  • Loading branch information
mcucchi9 committed Aug 1, 2024
1 parent fa3d784 commit 73c9c2d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
7 changes: 3 additions & 4 deletions cads_processing_api_service/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,10 @@ def get_job_from_broker_db(
return job


def update_results_href(href: str, data_volume: str | None = None) -> str:
def update_results_href(local_path: str, data_volume: str | None = None) -> str:
if data_volume is None:
data_volume = config.ensure_settings().data_volume
file_path = urllib.parse.urlparse(href).path
file_path = local_path.split("://", 1)[-1]
results_href = urllib.parse.urljoin(data_volume, file_path)
return results_href

Expand Down Expand Up @@ -510,8 +510,7 @@ def get_results_from_job(
raise exceptions.JobResultsExpired(
detail=f"results of job {job_id} expired"
)
if "href" in asset_value:
asset_value["href"] = update_results_href(asset_value["href"])
asset_value["href"] = update_results_href(asset_value["file:local_path"])
results = {"asset": {"value": asset_value}}
elif job_status == "failed":
error_messages = get_job_events(
Expand Down
30 changes: 25 additions & 5 deletions tests/test_30_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,15 @@ def test_get_job_from_broker_db() -> None:


def test_update_results_href() -> None:
href = "http://base_path/results/1234"
data_volume = "http://data_volume/"
updated_href = utils.update_results_href(href, data_volume)

local_path = "protocol://results/1234"
updated_href = utils.update_results_href(local_path, data_volume)
exp_updated_href = "http://data_volume/results/1234"
assert updated_href == exp_updated_href

local_path = "results/1234"
updated_href = utils.update_results_href(local_path, data_volume)
exp_updated_href = "http://data_volume/results/1234"
assert updated_href == exp_updated_href

Expand All @@ -259,12 +265,26 @@ def test_get_results_from_job() -> None:
"status": "successful",
"request_uid": "1234",
"cache_entry": cacholote.database.CacheEntry(
result={"args": [{"key": "value"}]}
result={
"args": [{"key": "value", "file:local_path": "test_local_path"}]
}
),
}
)
results = utils.get_results_from_job(job, session=mock_session)
exp_results = {"asset": {"value": {"key": "value"}}}
with unittest.mock.patch(
"cads_processing_api_service.utils.update_results_href"
) as mock_update_results_href:
mock_update_results_href.return_value = "test_href"
results = utils.get_results_from_job(job, session=mock_session)
exp_results = {
"asset": {
"value": {
"key": "value",
"file:local_path": "test_local_path",
"href": "test_href",
}
}
}
assert results == exp_results

job = cads_broker.SystemRequest(
Expand Down

0 comments on commit 73c9c2d

Please sign in to comment.