Skip to content

Commit

Permalink
start of openapi validation
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenkilbourn committed Jul 30, 2024
1 parent ffa02fa commit 8bd7494
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Test fixtures and data for STAC and Raster API integration testing.
"""

import httpx
import pytest

SEEDED_COLLECTION = "noaa-emergency-response"
Expand All @@ -14,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/searches"
RASTER_ENDPOINT = "http://0.0.0.0:8082/mosaic"
RASTER_HEALTH_ENDPOINT = "http://0.0.0.0:8082/healthz"
TILEMATRIX = {"z": 15, "x": 8589, "y": 12849}

Expand Down Expand Up @@ -236,3 +237,18 @@ def searches():
dict: An array of searches
"""
return SEARCHES


@pytest.fixture
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
13 changes: 13 additions & 0 deletions .github/workflows/tests/test_stac.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""test veda-backend STAC."""
import httpx
import pytest
import yaml
from openapi_schema_validator import validate


class TestList:
Expand All @@ -22,6 +24,7 @@ def setup(
seeded_id,
stac_endpoint,
stac_health_endpoint,
collection_schema,
):
"""
Set up the test environment with the required fixtures.
Expand All @@ -34,6 +37,15 @@ def setup(
self.seeded_id = seeded_id
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)

def test_stac_health(self):
"""test stac health endpoint."""
Expand Down Expand Up @@ -112,6 +124,7 @@ def test_stac_api(self):
assert resp.status_code == 200
collections = resp.json()["collections"]
assert len(collections) > 0
validate(collections[0], yaml.safe_load(self.collection_schema))
ids = [c["id"] for c in collections]
assert self.seeded_collection in ids

Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ repos:
hooks:
- id: mypy
language_version: python
additional_dependencies: ['types-requests', 'types-cachetools']
additional_dependencies: ['types-requests', 'types-cachetools', 'types-PyYAML']

0 comments on commit 8bd7494

Please sign in to comment.