From 628a2c84510abfbb5eff67d420d32a9e3ec6b1da Mon Sep 17 00:00:00 2001 From: Alex Goodman Date: Thu, 23 Mar 2023 13:51:06 -0400 Subject: [PATCH] fix workspace schema to be correct relative to actual 1.0 datashape (#128) Signed-off-by: Alex Goodman --- .../schema-1.0.0.json | 153 ++---------------- tests/conftest.py | 14 ++ tests/unit/test_workspace.py | 17 ++ 3 files changed, 48 insertions(+), 136 deletions(-) diff --git a/schema/provider-workspace-state/schema-1.0.0.json b/schema/provider-workspace-state/schema-1.0.0.json index 3eb0adcf..ef139bb9 100644 --- a/schema/provider-workspace-state/schema-1.0.0.json +++ b/schema/provider-workspace-state/schema-1.0.0.json @@ -10,154 +10,34 @@ "urls": { "type": "array", "items": [ - { - "type": "string" - }, { "type": "string" } ] }, - "input": { + "store": { + "type": "string" + }, + "timestamp": { + "type": "string" + }, + "listing": { "type": "object", "properties": { - "files": { - "type": "array", - "items": [ - { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "digests": { - "type": "array", - "items": [ - { - "type": "string" - }, - { - "type": "string" - } - ] - }, - "modified": { - "type": "string" - } - }, - "required": [ - "path", - "digests", - "modified" - ] - }, - { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "digests": { - "type": "array", - "items": [ - { - "type": "string" - }, - { - "type": "string" - } - ] - }, - "modified": { - "type": "string" - } - }, - "required": [ - "path", - "digests", - "modified" - ] - } - ] + "digest": { + "type": "string" }, - "timestamp": { + "path": { "type": "string" - } - }, - "required": [ - "files", - "timestamp" - ] - }, - "results": { - "type": "object", - "properties": { - "files": { - "type": "array", - "items": [ - { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "digests": { - "type": "array", - "items": [ - { - "type": "string" - }, - { - "type": "string" - } - ] - }, - "modified": { - "type": "string" - } - }, - "required": [ - "path", - "digests", - "modified" - ] - }, - { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "digests": { - "type": "array", - "items": [ - { - "type": "string" - }, - { - "type": "string" - } - ] - }, - "modified": { - "type": "string" - } - }, - "required": [ - "path", - "digests", - "modified" - ] - } - ] }, - "timestamp": { + "algorithm": { "type": "string" } }, "required": [ - "files", - "timestamp" + "digest", + "path", + "algorithm" ] }, "schema": { @@ -179,8 +59,9 @@ "required": [ "provider", "urls", - "input", - "results", + "store", + "timestamp", + "listing", "schema" ] } diff --git a/tests/conftest.py b/tests/conftest.py index e00aa38f..1bd0761c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,6 +14,10 @@ def __init__(self, root: str, name: str): self.root = root self.name = name + @property + def metadata_path(self): + return self.root / self.name / "metadata.json" + @property def input_dir(self): return self.root / self.name / "input" @@ -48,6 +52,16 @@ def result_schemas_valid(self, require_entries: bool = True) -> bool: return True + def metadata_schema_valid(self) -> bool: + with open(self.metadata_path) as f: + item = json.load(f) + schema_url = item["schema"]["url"] + + schema_dict = load_json_schema(get_schema_repo_path(schema_url)) + jsonschema.validate(instance=item, schema=schema_dict) + + return True + def load_json_schema(path: str) -> dict: with open(path) as f: diff --git a/tests/unit/test_workspace.py b/tests/unit/test_workspace.py index fdbf1a8d..57464ed6 100644 --- a/tests/unit/test_workspace.py +++ b/tests/unit/test_workspace.py @@ -127,3 +127,20 @@ def test_record_state_urls_persisted_across_runs(tmpdir, dummy_file): ) assert current_state == expected_state + + +def test_state_schema(tmpdir, dummy_file, helpers): + name = "dummy" + ws = workspace.Workspace(root=tmpdir, name=name, create=True) + + # create a dummy files + dummy_file(ws.input_path, "dummt-input-1.json") + dummy_file(ws.results_path, "dummy-00000.json") + + urls = ["http://localhost:8000/dummy-input-1.json"] + store = result.StoreStrategy.FLAT_FILE + ws.record_state(urls=urls, store=store.value, timestamp=datetime.datetime(2021, 1, 1)) + + ws_helper = helpers.provider_workspace_helper(name=name, create=False) + + assert ws_helper.metadata_schema_valid()