Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate content value #371

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion schema/definitions/0.8.0/examples/table_wellpicks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ file:

data: # The data block describes the actual data (e.g. surface). Only present in data objects

content: well_picks # white-listed and standardized
content: wellpicks # white-listed and standardized

name: wellpicks
stratigraphic: false
Expand Down
25 changes: 24 additions & 1 deletion schema/definitions/0.8.0/schema/fmu_results.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,31 @@
"content": {
"type": "string",
"description": "The contents of this data object",
"enum": [
"depth",
"time",
"thickness",
"property",
"seismic",
"fluid_contact",
"field_outline",
"field_region",
"regions",
"pinchout",
"subcrop",
"fault_lines",
"velocity",
"volumes",
"volumetrics",
"inplace_volumes",
"khproduct",
"timeseries",
"wellpicks",
"parameters"
],
"examples": [
"depth"
"depth",
"time"
]
},
"tagname": {
Expand Down
1 change: 1 addition & 0 deletions src/fmu/dataio/_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def __post_init__(self):
"velocity": None,
"volumes": None,
"volumetrics": None, # or?
"inplace_volumes": None, # or?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Included to match the current examples, where this value is used for content.

"khproduct": None,
"timeseries": None,
"wellpicks": None,
Expand Down
31 changes: 31 additions & 0 deletions tests/test_schema/test_schema_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import pytest

from fmu.dataio._definitions import ALLOWED_CONTENTS

perolavsvendsen marked this conversation as resolved.
Show resolved Hide resolved
# pylint: disable=no-member

Expand Down Expand Up @@ -383,3 +384,33 @@ def test_schema_logic_data_spec(schema_080, metadata_examples):

# assert data.spec not required when class === dictionary
jsonschema.validate(instance=example_dict, schema=schema_080)


def test_schema_logic_content_whitelist(schema_080, metadata_examples):
"""Test that validation fails when value of data.content is not in
the whitelist."""

# fetch surface example
example_surface = deepcopy(metadata_examples["surface_depth.yml"])

# assert validation with no changes
jsonschema.validate(instance=example_surface, schema=schema_080)

# shall fail when content is not in whitelist
example_surface["data"]["content"] = "not_valid_content"
with pytest.raises(jsonschema.exceptions.ValidationError):
jsonschema.validate(instance=example_surface, schema=schema_080)


def test_schema_content_synch_with_code(schema_080):
"""Currently, the whitelist for content is maintained both in the schema
and in the code. This test asserts that list used in the code is in synch
with schema. Note! This is one-way, and will not fail if additional
elements are added to the schema only."""

schema_allowed = schema_080["definitions"]["data"]["properties"]["content"]["enum"]
for allowed_content in ALLOWED_CONTENTS:
if allowed_content not in schema_allowed:
raise ValueError(
f"content '{allowed_content}' allowed in code, but not schema."
)
Loading