diff --git a/cads_api_client/processing.py b/cads_api_client/processing.py index e8bf359..5f78130 100644 --- a/cads_api_client/processing.py +++ b/cads_api_client/processing.py @@ -4,7 +4,7 @@ import logging import os import time -import urllib +import urllib.parse from typing import Any, Dict, List, Optional, Type, TypeVar try: @@ -336,14 +336,18 @@ def get_result_size(self) -> Optional[int]: size = asset["file:size"] return int(size) + @property + def location(self) -> str: + result_href = self.get_result_href() + return urllib.parse.urljoin(self.response.url, result_href) + def download( self, target: Optional[str] = None, timeout: int = 60, retry_options: Dict[str, Any] = {}, ) -> str: - result_href = self.get_result_href() - url = urllib.parse.urljoin(self.response.url, result_href) + url = self.location if target is None: parts = urllib.parse.urlparse(url) target = parts.path.strip("/").split("/")[-1] diff --git a/tests/integration_test_50_legacy_api_client.py b/tests/integration_test_50_legacy_api_client.py index 81d4477..e90af1e 100644 --- a/tests/integration_test_50_legacy_api_client.py +++ b/tests/integration_test_50_legacy_api_client.py @@ -1,6 +1,7 @@ import pathlib import pytest +import requests from cads_api_client import legacy_api_client @@ -22,6 +23,9 @@ def test_retrieve(tmp_path: pathlib.Path, api_root_url: str, api_key: str) -> No assert str(target) == actual_target assert target.stat().st_size == 1 + response = requests.head(result.location) + assert response.status_code == 200 + @pytest.mark.parametrize("quiet", [True, False]) def test_quiet(