Skip to content

Commit 6e7f58f

Browse files
committed
Issue #668 support federation extension on list_processes
1 parent 4bfd2a6 commit 6e7f58f

File tree

3 files changed

+61
-11
lines changed

3 files changed

+61
-11
lines changed

openeo/rest/connection.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
from openeo.rest.graph_building import CollectionProperty
6767
from openeo.rest.job import BatchJob, RESTJob
6868
from openeo.rest.mlmodel import MlModel
69-
from openeo.rest.models.general import CollectionListingResponse
69+
from openeo.rest.models.general import CollectionListingResponse, ProcessListingResponse
7070
from openeo.rest.service import Service
7171
from openeo.rest.udp import Parameter, RESTUserDefinedProcess
7272
from openeo.rest.userfile import UserFile
@@ -823,23 +823,22 @@ def collection_metadata(self, name) -> CollectionMetadata:
823823
# TODO: duplication with `Connection.describe_collection`: deprecate one or the other?
824824
return CollectionMetadata(metadata=self.describe_collection(name))
825825

826-
def list_processes(self, namespace: Optional[str] = None) -> List[dict]:
827-
# TODO: Maybe format the result dictionary so that the process_id is the key of the dictionary.
826+
def list_processes(self, namespace: Optional[str] = None) -> ProcessListingResponse:
828827
"""
829828
Loads all available processes of the back end.
830829
831830
:param namespace: The namespace for which to list processes.
832831
833-
:return: processes_dict: Dict All available processes of the back end.
832+
:return: listing of available processes
834833
"""
834+
# TODO: Maybe format the result dictionary so that the process_id is the key of the dictionary.
835835
if namespace is None:
836-
processes = self._capabilities_cache.get(
837-
key=("processes", "backend"),
838-
load=lambda: self.get('/processes', expected_status=200).json()["processes"]
836+
response = self._capabilities_cache.get(
837+
key=("processes", "backend"), load=lambda: self.get("/processes", expected_status=200).json()
839838
)
840839
else:
841-
processes = self.get('/processes/' + namespace, expected_status=200).json()["processes"]
842-
return VisualList("processes", data=processes, parameters={'show-graph': True, 'provide-download': False})
840+
response = self.get("/processes/" + namespace, expected_status=200).json()
841+
return ProcessListingResponse(data=response)
843842

844843
def describe_process(self, id: str, namespace: Optional[str] = None) -> dict:
845844
"""

openeo/rest/models/general.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,44 @@ def _repr_html_(self):
4747

4848
@property
4949
def links(self) -> List[Link]:
50-
"""Get links from collections response."""
50+
"""Get links related to this resource."""
5151
return [Link.from_dict(d) for d in self._data.get("links", [])]
5252

5353
@property
5454
def ext_federation(self) -> FederationExtension:
55-
"""Accessor for federation extension data."""
55+
"""Accessor for federation extension data related to this resource."""
56+
return FederationExtension(self._data)
57+
58+
59+
class ProcessListingResponse(list):
60+
"""
61+
Container for process metadata listing received from a ``GET /processes`` request.
62+
63+
This object mimics a list of process metadata dictionaries,
64+
which was the original return API of :py:meth:`~openeo.rest.connection.Connection.list_processes()`,
65+
but now also includes additional metadata like links and extensions.
66+
67+
:param data: response data from a ``GET /processes`` request
68+
"""
69+
70+
__slots__ = ["_data"]
71+
72+
def __init__(self, data: dict):
73+
self._data = data
74+
# Mimic original list of process metadata dictionaries
75+
super().__init__(data["processes"])
76+
77+
def _repr_html_(self):
78+
return render_component(
79+
component="processes", data=self, parameters={"show-graph": True, "provide-download": False}
80+
)
81+
82+
@property
83+
def links(self) -> List[Link]:
84+
"""Get links related to this resource."""
85+
return [Link.from_dict(d) for d in self._data.get("links", [])]
86+
87+
@property
88+
def ext_federation(self) -> FederationExtension:
89+
"""Accessor for federation extension data related to this resource."""
5690
return FederationExtension(self._data)

tests/rest/test_connection.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3407,6 +3407,23 @@ def test_list_processes_namespace(requests_mock):
34073407
assert m.call_count == 1
34083408

34093409

3410+
def test_list_processes_extra_metadata(requests_mock):
3411+
requests_mock.get(API_URL, json={"api_version": "1.0.0"})
3412+
m = requests_mock.get(
3413+
API_URL + "processes",
3414+
json={
3415+
"processes": [{"id": "add"}, {"id": "mask"}],
3416+
"links": [{"rel": "next", "href": "https://oeo.test/processes?page=2"}],
3417+
"federation:missing": ["oeob"],
3418+
},
3419+
)
3420+
conn = Connection(API_URL)
3421+
processes = conn.list_processes()
3422+
assert processes == [{"id": "add"}, {"id": "mask"}]
3423+
assert processes.links == [Link(rel="next", href="https://oeo.test/processes?page=2", type=None, title=None)]
3424+
assert processes.ext_federation.missing == ["oeob"]
3425+
3426+
34103427
def test_get_job(requests_mock):
34113428
requests_mock.get(API_URL, json={"api_version": "1.0.0"})
34123429
conn = Connection(API_URL)

0 commit comments

Comments
 (0)