Skip to content

Commit b3209df

Browse files
committed
WIP
1 parent 6b5efa3 commit b3209df

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

clients/python/src/osparc/_api_solvers_api.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,41 @@ def __init__(self, api_client: ApiClient):
3232
else None
3333
)
3434

35+
def iter_solvers(self, **kwargs) -> PaginationGenerator:
36+
"""Iterates over latest version of all solvers"""
37+
38+
def _pagination_method():
39+
return super(SolversApi, self).get_solvers_page(
40+
limit=_DEFAULT_PAGINATION_LIMIT,
41+
offset=_DEFAULT_PAGINATION_OFFSET,
42+
**kwargs,
43+
)
44+
45+
return PaginationGenerator(
46+
first_page_callback=_pagination_method,
47+
api_client=self.api_client,
48+
base_url=self.api_client.configuration.host,
49+
auth=self._auth,
50+
)
51+
52+
def iter_solver_releases(self, solver_key: str, **kwargs) -> PaginationGenerator:
53+
"""Iterates over all released versions of a given solver"""
54+
55+
def _pagination_method():
56+
return super(SolversApi, self).get_solver_releases_page(
57+
solver_key=solver_key,
58+
limit=_DEFAULT_PAGINATION_LIMIT,
59+
offset=_DEFAULT_PAGINATION_OFFSET,
60+
**kwargs,
61+
)
62+
63+
return PaginationGenerator(
64+
first_page_callback=_pagination_method,
65+
api_client=self.api_client,
66+
base_url=self.api_client.configuration.host,
67+
auth=self._auth,
68+
)
69+
3570
def list_solver_ports(
3671
self, solver_key: str, version: str, **kwargs
3772
) -> List[SolverPort]:
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# pylint: disable=redefined-outer-name
2+
# pylint: disable=unused-argument
3+
# pylint: disable=unused-variable
4+
# pylint: disable=too-many-arguments
5+
6+
7+
from pathlib import Path
8+
from typing import List
9+
10+
import osparc
11+
import pytest
12+
from osparc import (
13+
CreditsApi,
14+
FilesApi,
15+
JobInputs,
16+
JobOutputs,
17+
JobStatus,
18+
Solver,
19+
SolversApi,
20+
UsersApi,
21+
WalletsApi,
22+
)
23+
24+
25+
@pytest.fixture
26+
def users_api(api_client: osparc.ApiClient) -> UsersApi:
27+
return UsersApi(api_client)
28+
29+
30+
@pytest.fixture
31+
def wallets_api(api_client: osparc.ApiClient) -> WalletsApi:
32+
return WalletsApi(api_client)
33+
34+
35+
@pytest.fixture
36+
def credits_api(api_client: osparc.ApiClient) -> CreditsApi:
37+
return CreditsApi(api_client)
38+
39+
40+
@pytest.fixture
41+
def files_api(api_client: osparc.ApiClient) -> FilesApi:
42+
return FilesApi(api_client)
43+
44+
45+
@pytest.fixture
46+
def solvers_api(api_client: osparc.ApiClient) -> SolversApi:
47+
return SolversApi(api_client)
48+
49+
50+
def test_initialize_solvers(solvers_api: SolversApi):
51+
# TODO: search a solver and give me all its releases!
52+
53+
# -> "/{solver_key:path}/releases:search?title='{title}'? or add filter? in list?
54+
55+
include = {"Sim4Life Python Runner 8.0"} # titles!?
56+
# Why not key and we can add a search by release?
57+
result = []
58+
59+
# TODO: expose iter_solvers
60+
for solver in solvers_api.iter_solvers():
61+
if solver.title in include:
62+
temp_solver = solvers_api.get_solver_release(
63+
solver_key=solver.id, version=solver.version
64+
)
65+
result[solver.title] = temp_solver
66+
67+
assert result
68+
69+
70+
def test_upload(files_api: FilesApi, tmp_path: Path):
71+
p = (tmp_path / "foo.txt").write_text("hi")
72+
files_api.upload_file(file=p)
73+
74+
75+
# def test_create_run(solvers_api: SolversApi):
76+
77+
# solvers_api.create_job(
78+
# self.solvers_in_use[SolverTitle.S4LPYRUN.value].version,
79+
# JobInputs(payloads),
80+
# )

0 commit comments

Comments
 (0)