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

Commit 5de7bd2

Browse files
authored
Legacy client download (#85)
* implement legacy client download * cleanup
1 parent a522cd6 commit 5de7bd2

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

cads_api_client/legacy_api_client.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import functools
44
import logging
5+
import typing
56
import warnings
67
from types import TracebackType
78
from typing import Any, Callable, TypeVar, cast, overload
@@ -208,8 +209,22 @@ def workflow(self, code, *args, **kwargs): # type: ignore
208209
def status(self, context=None): # type: ignore
209210
self.raise_not_implemented_error()
210211

211-
def download(self, results, targets=None): # type: ignore
212-
self.raise_not_implemented_error()
212+
@typing.no_type_check
213+
def _download(self, results, targets=None):
214+
if isinstance(results, (processing.Results, processing.Remote)):
215+
if targets:
216+
path = targets.pop(0)
217+
else:
218+
path = None
219+
return results.download(path)
220+
221+
if isinstance(results, (list, tuple)):
222+
return [self._download(x, targets) for x in results]
223+
224+
if isinstance(results, dict):
225+
self.raise_not_implemented_error()
226+
227+
return results
213228

214229
def remote(self, url): # type: ignore
215230
self.raise_not_implemented_error()

tests/integration_test_70_legacy_api_client.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,29 @@ def test_legacy_api_client_logging(
214214
client.info("Info message")
215215
client.warning("Warning message")
216216
client.error("Error message")
217-
print(caplog.record_tuples)
218217
assert caplog.record_tuples == [
219218
("cads_api_client.legacy_api_client", 20, "Info message"),
220219
("cads_api_client.legacy_api_client", 30, "Warning message"),
221220
("cads_api_client.legacy_api_client", 40, "Error message"),
222221
]
222+
223+
224+
def test_legacy_api_client_download(
225+
tmp_path: pathlib.Path,
226+
api_root_url: str,
227+
api_anon_key: str,
228+
) -> None:
229+
client = legacy_api_client.LegacyApiClient(
230+
url=api_root_url,
231+
key=api_anon_key,
232+
retry_max=0,
233+
wait_until_complete=False,
234+
)
235+
remote = client.retrieve("test-adaptor-dummy", {"size": 1})
236+
assert isinstance(remote, processing.Remote)
237+
238+
results = (remote, remote.make_results())
239+
target1 = str(tmp_path / "remote.grib")
240+
target2 = str(tmp_path / "results.grib")
241+
assert client.download(results, [target1, target2]) == [target1, target2]
242+
assert os.path.getsize(target1) == os.path.getsize(target2) == 1

0 commit comments

Comments
 (0)