Skip to content

Commit

Permalink
Merge branch 'dts-manifest-schema' into dts-manifest-parse
Browse files Browse the repository at this point in the history
  • Loading branch information
briehl committed Dec 13, 2024
2 parents 33ffb2c + 05b619b commit 84e8b2f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 11 additions & 2 deletions staging_service/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,14 @@ async def authorize_request(request):


def load_and_validate_schema(schema_path: PathPy) -> jsonschema.Draft202012Validator:
"""Loads and validates a JSON schema from a path.
This expects a JSON schema loaded that validates under the 2020-12 draft schema
format: https://json-schema.org/draft/2020-12
This is tested directly as a function in test_app.py, but the whole workflow when
the app server is run is only tested manually.
"""
with open(schema_path) as schema_file:
dts_schema = json.load(schema_file)
try:
Expand Down Expand Up @@ -652,7 +660,6 @@ def inject_config_dependencies(config):
Path._DATA_DIR = DATA_DIR
Path._META_DIR = META_DIR
Path._CONCIERGE_PATH = CONCIERGE_PATH
_DTS_MANIFEST_SCHEMA_PATH = DTS_MANIFEST_SCHEMA_PATH

if Path._DATA_DIR is None:
raise Exception("Please provide DATA_DIR in the config file ")
Expand All @@ -663,11 +670,13 @@ def inject_config_dependencies(config):
if Path._CONCIERGE_PATH is None:
raise Exception("Please provide CONCIERGE_PATH in the config file ")

if _DTS_MANIFEST_SCHEMA_PATH is None:
if DTS_MANIFEST_SCHEMA_PATH is None:
raise Exception("Please provide DTS_MANIFEST_SCHEMA in the config file")

global _DTS_MANIFEST_VALIDATOR
# will raise an Exception if the schema is invalid
# TODO: write automated tests that exercise this code under different config
# conditions and error states.
_DTS_MANIFEST_VALIDATOR = load_and_validate_schema(DTS_MANIFEST_SCHEMA_PATH)

if FILE_EXTENSION_MAPPINGS is None:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,9 @@ def test_load_and_validate_schema_good():


def test_load_and_validate_schema_missing_file():
not_real_file = Path("not_real")
not_real_file = Path(str(uuid.uuid4()))
# double-check that the file doesn't exist and make a new one if so.
# shouldn't ever happen, ideally, but easy to check.
while not_real_file.exists():
not_real_file = Path(str(uuid.uuid4()))
with pytest.raises(FileNotFoundError, match="No such file or directory"):
Expand Down

0 comments on commit 84e8b2f

Please sign in to comment.