From 07a8c973caf8bb5ce9fa2c1c56aa437778dfdbe2 Mon Sep 17 00:00:00 2001 From: Per Olav Svendsen Date: Wed, 27 Sep 2023 11:10:40 +0200 Subject: [PATCH 1/3] schema requires specific data.content values --- .../0.8.0/examples/table_wellpicks.yml | 2 +- .../definitions/0.8.0/schema/fmu_results.json | 25 ++++++++++++++++++- tests/test_schema/test_schema_logic.py | 16 ++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/schema/definitions/0.8.0/examples/table_wellpicks.yml b/schema/definitions/0.8.0/examples/table_wellpicks.yml index 579c10e4b..27660a6f0 100644 --- a/schema/definitions/0.8.0/examples/table_wellpicks.yml +++ b/schema/definitions/0.8.0/examples/table_wellpicks.yml @@ -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 diff --git a/schema/definitions/0.8.0/schema/fmu_results.json b/schema/definitions/0.8.0/schema/fmu_results.json index f38aae621..a509c1179 100644 --- a/schema/definitions/0.8.0/schema/fmu_results.json +++ b/schema/definitions/0.8.0/schema/fmu_results.json @@ -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": { diff --git a/tests/test_schema/test_schema_logic.py b/tests/test_schema/test_schema_logic.py index 7df4e0242..247190edd 100644 --- a/tests/test_schema/test_schema_logic.py +++ b/tests/test_schema/test_schema_logic.py @@ -383,3 +383,19 @@ 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) From a3867bba3257bc2cb23abc40d7620542e3bbeea2 Mon Sep 17 00:00:00 2001 From: Per Olav Svendsen Date: Wed, 27 Sep 2023 11:11:03 +0200 Subject: [PATCH 2/3] add inplace_volumes to allowed contents --- src/fmu/dataio/_definitions.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fmu/dataio/_definitions.py b/src/fmu/dataio/_definitions.py index 1b2e0648f..553180964 100644 --- a/src/fmu/dataio/_definitions.py +++ b/src/fmu/dataio/_definitions.py @@ -61,6 +61,7 @@ def __post_init__(self): "velocity": None, "volumes": None, "volumetrics": None, # or? + "inplace_volumes": None, # or? "khproduct": None, "timeseries": None, "wellpicks": None, From 25e969c6345828304ae86d60fc4d808cd9a0e42f Mon Sep 17 00:00:00 2001 From: Per Olav Svendsen Date: Wed, 27 Sep 2023 11:22:22 +0200 Subject: [PATCH 3/3] test that ALLOWED_CONTENTS is in synch with schema. --- tests/test_schema/test_schema_logic.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/test_schema/test_schema_logic.py b/tests/test_schema/test_schema_logic.py index 247190edd..4958297aa 100644 --- a/tests/test_schema/test_schema_logic.py +++ b/tests/test_schema/test_schema_logic.py @@ -6,6 +6,7 @@ import pytest +from fmu.dataio._definitions import ALLOWED_CONTENTS # pylint: disable=no-member @@ -399,3 +400,17 @@ def test_schema_logic_content_whitelist(schema_080, metadata_examples): 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." + )