Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

full support for legacy download #88

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion cads_api_client/legacy_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,24 @@ def _download(self, results, targets=None):
return [self._download(x, targets) for x in results]

if isinstance(results, dict):
self.raise_not_implemented_error()
if "location" in results and "contentLength" in results:
reply = dict(
location=results["location"],
content_length=results["contentLength"],
content_type=results.get("contentType"),
)

if targets:
path = targets.pop(0)
else:
path = None

return cdsapi.api.Result(self, reply).download(path)

r = {}
for v in results.values():
r[v] = self._download(v, targets)
return r

return results

Expand Down
15 changes: 11 additions & 4 deletions tests/integration_test_70_legacy_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,19 +226,26 @@ def test_legacy_api_client_download(
client = LegacyApiClient(
url=api_root_url,
key=api_anon_key,
retry_max=0,
retry_max=1,
wait_until_complete=False,
)
remote = client.retrieve("test-adaptor-dummy", {"size": 1})
assert isinstance(remote, processing.Remote)
target = client.download(remote)
assert os.path.getsize(target) == 1

results = (remote, remote.make_results())
results = remote.make_results()
results_dict = {
"location": results.location,
"contentLength": results.content_length,
}
results_tuple = (remote, remote.make_results(), results_dict)
target1 = "remote.grib"
target2 = "results.grib"
assert client.download(results, [target1, target2]) == [target1, target2]
assert os.path.getsize(target1) == os.path.getsize(target2) == 1
target3 = "dict.grib"
targets = [target1, target2, target3]
assert client.download(results_tuple, targets) == [target1, target2, target3]
assert all(os.path.getsize(target) == 1 for target in targets)


def test_legacy_api_client_status(legacy_client: LegacyApiClient) -> None:
Expand Down