Skip to content

Commit

Permalink
add open api validation of stac results
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenkilbourn committed Jul 30, 2024
1 parent 8bd7494 commit a181c62
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
19 changes: 14 additions & 5 deletions .github/workflows/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
STAC_HEALTH_ENDPOINT = "http://0.0.0.0:8081/_mgmt/ping"
SEARCH_ROUTE = "search"

RASTER_ENDPOINT = "http://0.0.0.0:8082/mosaic"
RASTER_ENDPOINT = "http://0.0.0.0:8082/searches"
RASTER_HEALTH_ENDPOINT = "http://0.0.0.0:8082/healthz"
TILEMATRIX = {"z": 15, "x": 8589, "y": 12849}

Expand Down Expand Up @@ -239,16 +239,25 @@ def searches():
return SEARCHES


@pytest.fixture
@pytest.fixture(scope="session")
def collection_schema():
"""Retrieve Collection Schema from
Returns:
String: A string representation of the yaml schema
"""
response = httpx.get("https://api.stacspec.org/v1.0.0/collections/openapi.yaml")
# Convert bytes to string
# content = response.content.decode("utf-8")
content = response.text
print("feature content: ", content)
return content


@pytest.fixture(scope="session")
def feature_schema():
"""Retrieve Feature Schema from
Returns:
String: A string representation of the yaml schema
"""
response = httpx.get("https://api.stacspec.org/v1.0.0/ogcapi-features/openapi.yaml")
content = response.text
return content
13 changes: 4 additions & 9 deletions .github/workflows/tests/test_stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def setup(
stac_endpoint,
stac_health_endpoint,
collection_schema,
feature_schema,
):
"""
Set up the test environment with the required fixtures.
Expand All @@ -38,18 +39,10 @@ def setup(
self.stac_endpoint = stac_endpoint
self.stac_health_endpoint = stac_health_endpoint
self.collection_schema = collection_schema

# with httpx.get("https://api.stacspec.org/v1.0.0/ogcapi-features/openapi.yaml") as response:
# # Convert bytes to string
# # content = response.content.decode("utf-8")
# content = response.text
# print("feature content: ", content)
# # Load the yaml
# feature_schema = yaml.safe_load(content)
self.feature_schema = feature_schema

def test_stac_health(self):
"""test stac health endpoint."""

assert httpx.get(self.stac_health_endpoint).status_code == 200

def test_stac_viewer(self):
Expand Down Expand Up @@ -134,6 +127,7 @@ def test_stac_api(self):
)
assert resp.status_code == 200
items = resp.json()["features"]
validate(items[0], yaml.safe_load(self.feature_schema))
assert len(items) == 10

# item
Expand All @@ -143,6 +137,7 @@ def test_stac_api(self):
assert resp.status_code == 200
item = resp.json()
assert item["id"] == self.seeded_id
validate(item, yaml.safe_load(self.feature_schema))

def test_stac_to_raster(self):
"""test link to raster api."""
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"psycopg[binary, pool]",
"fastapi",
"moto",
"openapi-schema-validator",
],
}

Expand Down

0 comments on commit a181c62

Please sign in to comment.