Skip to content

Commit

Permalink
added clarification to adjust_spec function
Browse files Browse the repository at this point in the history
  • Loading branch information
GeraldIr committed Feb 7, 2024
1 parent 8311ba4 commit 11b3726
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions src/openeo_test_suite/lib/compliance_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path
import pathlib
from typing import Union
from typing import Iterator, Union
from openapi_core import Spec
import yaml
import json
Expand Down Expand Up @@ -215,6 +215,13 @@ def check_test_results(e: Exception):
return fail_log


# Server field in the spec has to be adjusted so that validation does not fail on the server url
def adjust_spec(path_to_file: str, endpoint: str, domain: str):
data = adjust_server(path_to_file=path_to_file, endpoint=endpoint)
data = adjust_server_in_well_known(data=data, endpoint=domain)
return Spec.from_dict(data, validator=None)


def adjust_server(path_to_file, endpoint):
with open(path_to_file, "r") as file:
data = yaml.safe_load(file)
Expand All @@ -226,15 +233,8 @@ def adjust_server(path_to_file, endpoint):
return data


def adjust_spec(path_to_file: str, endpoint: str, domain: str):
data = adjust_server(path_to_file=path_to_file, endpoint=endpoint)
data = adjust_server_in_well_known(data=data, endpoint=domain)
return Spec.from_dict(data, validator=None)


def adjust_server_in_well_known(data, endpoint):
data["paths"]["/.well-known/openeo"]["get"]["servers"][0]["url"] = endpoint

return data


Expand All @@ -260,12 +260,6 @@ def unmarshal_commonmark(value):
}


def get_examples_path():
return os.path.join(
os.getcwd(), "src/openeo_test_suite/tests/general/payload_examples"
)


def _guess_root():
project_root = Path(openeo_test_suite.__file__).parents[2]
candidates = [
Expand All @@ -281,12 +275,23 @@ def _guess_root():
)


def get_examples_path():
return (
_guess_root().parents[2]
/ "src"
/ "openeo_test_suite"
/ "tests"
/ "general"
/ "payload_examples"
)


def get_spec_path():
return _guess_root() / "openapi.yaml"


def load_payloads_from_directory(directory_path: str) -> list[dict]:
for filename in pathlib.Path.glob(directory_path, "*.json"):
def load_payloads_from_directory(directory_path: str) -> Iterator[str]:
for filename in pathlib.Path(directory_path).glob("*.json"):
file_path = os.path.join(directory_path, filename)
with open(file_path, "r") as file:
try:
Expand Down

0 comments on commit 11b3726

Please sign in to comment.