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

Commit

Permalink
full support for download
Browse files Browse the repository at this point in the history
  • Loading branch information
malmans2 committed Sep 25, 2024
1 parent bb42c45 commit 91e93d0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
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
16 changes: 12 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,27 @@ 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)
os.path.getsize(target1) == os.path.getsize(target2) == 1


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

0 comments on commit 91e93d0

Please sign in to comment.