Skip to content

Commit

Permalink
Issue #3 fix/update failing unit tests
Browse files Browse the repository at this point in the history
also related to #4
  • Loading branch information
soxofaan committed Dec 11, 2024
1 parent 96cec28 commit 42f5484
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
9 changes: 7 additions & 2 deletions tests/data/ogcapi-records/algorithm01.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@
},
"links": [
{
"rel": "udp",
"rel": "openeo-process",
"type": "application/json",
"title": "UDP One",
"href": "https://esa-apex.test/udp/algorithm01.json"
}
},{
"rel": "service",
"type": "application/json",
"title": "openEO service",
"href": "https://openeo.test/"
}
]
}
42 changes: 32 additions & 10 deletions tests/test_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Algorithm,
GithubAlgorithmRepository,
InvalidMetadataError,
ServiceLink,
UdpLink,
)

Expand Down Expand Up @@ -74,6 +75,9 @@ def test_from_ogc_api_record_minimal(self):
"properties": {
"type": "apex_algorithm",
},
"links": [
{"rel": "service", "href": "https://openeo.test/"},
],
}
algorithm = Algorithm.from_ogc_api_record(data)
assert algorithm.id == "minimal"
Expand Down Expand Up @@ -132,7 +136,13 @@ def test_from_ogc_api_record_basic(self):
"type": "application/json",
"title": "Basic UDP",
"href": "https://esa-apex.test/udp/basic.json",
}
},
{
"rel": "service",
"type": "application/json",
"title": "openEO service",
"href": "https://openeo.test/",
},
],
}
algorithm = Algorithm.from_ogc_api_record(data)
Expand All @@ -143,6 +153,7 @@ def test_from_ogc_api_record_basic(self):
href="https://esa-apex.test/udp/basic.json",
title="Basic UDP",
)
assert algorithm.service_links == [ServiceLink(href="https://openeo.test/", title="openEO service")]

@pytest.mark.parametrize("path_type", [str, Path])
def test_from_ogc_api_record_path(self, path_type):
Expand All @@ -155,6 +166,7 @@ def test_from_ogc_api_record_path(self, path_type):
href="https://esa-apex.test/udp/algorithm01.json",
title="UDP One",
)
assert algorithm.service_links == [ServiceLink(href="https://openeo.test/", title="openEO service")]

def test_from_ogc_api_record_str(self):
dump = (DATA_ROOT / "ogcapi-records/algorithm01.json").read_text()
Expand All @@ -166,6 +178,7 @@ def test_from_ogc_api_record_str(self):
href="https://esa-apex.test/udp/algorithm01.json",
title="UDP One",
)
assert algorithm.service_links == [ServiceLink(href="https://openeo.test/", title="openEO service")]

def test_from_ogc_api_record_url(self, requests_mock):
url = "https://esa-apex.test/algorithms/a1.json"
Expand All @@ -179,32 +192,41 @@ def test_from_ogc_api_record_url(self, requests_mock):
href="https://esa-apex.test/udp/algorithm01.json",
title="UDP One",
)
assert algorithm.service_links == [ServiceLink(href="https://openeo.test/", title="openEO service")]


class TestGithubAlgorithmRepository:
@pytest.fixture
def repo(self) -> GithubAlgorithmRepository:
# TODO: avoid depending on an actual GitHub repository. Mock it instead?
# Or run this as an integration test?
# https://github.com/ESA-APEx/esa-apex-toolbox-python/issues/4
return GithubAlgorithmRepository(
owner="ESA-APEx",
repo="apex_algorithms",
folder="algorithm_catalog",
)

def test_list_algorithms(self, repo):
assert repo.list_algorithms() == [
"worldcereal.json",
]
listing = repo.list_algorithms()
assert listing
assert all(re.fullmatch(r"[a-z0-9_]+\.json", item) for item in listing)

def test_get_algorithm(self, repo):
algorithm = repo.get_algorithm("worldcereal.json")
algorithm = repo.get_algorithm("max_ndvi_composite.json")
assert algorithm == Algorithm(
id="worldcereal_maize",
title="ESA worldcereal global maize detector",
description="A maize detection algorithm.",
id="max_ndvi_composite",
title="Max NDVI Composite based on Sentinel-2 data",
description="A compositing algorithm for Sentinel-2 L2A data, ranking observations by their maximum NDVI.",
udp_link=UdpLink(
href="https://github.com/ESA-APEX/apex_algorithms/blob/main/openeo_udp/worldcereal_inference.json",
title="openEO UDP",
href="https://raw.githubusercontent.com/ESA-APEx/apex_algorithms/main/openeo_udp/examples/max_ndvi_composite/max_ndvi_composite.json",
title="openEO Process Definition",
),
organization="VITO",
service_links=[
ServiceLink(
href="https://openeofed.dataspace.copernicus.eu",
title="CDSE openEO federation",
)
],
)

0 comments on commit 42f5484

Please sign in to comment.