diff --git a/cads_processing_api_service/utils.py b/cads_processing_api_service/utils.py index c4a0f3c..d5cd092 100644 --- a/cads_processing_api_service/utils.py +++ b/cads_processing_api_service/utils.py @@ -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 @@ -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( diff --git a/tests/test_30_utils.py b/tests/test_30_utils.py index e3cbbcb..b3f3075 100644 --- a/tests/test_30_utils.py +++ b/tests/test_30_utils.py @@ -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 @@ -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(