Skip to content

Commit

Permalink
fix workspace schema to be correct relative to actual 1.0 datashape (#…
Browse files Browse the repository at this point in the history
…128)

Signed-off-by: Alex Goodman <[email protected]>
  • Loading branch information
wagoodman authored Mar 23, 2023
1 parent 3a30ea1 commit 628a2c8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 136 deletions.
153 changes: 17 additions & 136 deletions schema/provider-workspace-state/schema-1.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -179,8 +59,9 @@
"required": [
"provider",
"urls",
"input",
"results",
"store",
"timestamp",
"listing",
"schema"
]
}
14 changes: 14 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/test_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 628a2c8

Please sign in to comment.