Skip to content

Commit e24784e

Browse files
Add test to force a required block whenever there is a property with certain metadata attributes that it is forced to be required
1 parent 512f05a commit e24784e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/test_schemas.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
)
2323
EXPOSURE_TYPE_ELEMENTS = list(asdf.schema.load_schema("asdf://stsci.edu/datamodels/roman/schemas/exposure_type-1.0.0")["enum"])
2424
EXPECTED_COMMON_REFERENCE = {"$ref": "asdf://stsci.edu/datamodels/roman/schemas/reference_files/ref_common-1.0.0"}
25+
METADATA_FORCING_REQUIRED = ["archive_catalog", "sdf"]
2526

2627

2728
@pytest.fixture(scope="session", params=SCHEMA_URIS)
@@ -105,6 +106,10 @@ def callback(node):
105106

106107

107108
def test_required(schema):
109+
"""
110+
Checks that all properties are required if there is a required list.
111+
"""
112+
108113
def callback(node):
109114
if isinstance(node, Mapping) and "required" in node:
110115
assert node.get("type") == "object"
@@ -118,6 +123,22 @@ def callback(node):
118123
asdf.treeutil.walk(schema, callback)
119124

120125

126+
def test_metadata_force_required(schema):
127+
"""
128+
Test that if certain properties have certain metadata entries, that they are in a required list.
129+
"""
130+
131+
def callback(node):
132+
if isinstance(node, Mapping) and "properties" in node:
133+
for prop_name, prop in node["properties"].items():
134+
for metadata in METADATA_FORCING_REQUIRED:
135+
if isinstance(prop, Mapping) and metadata in prop:
136+
assert "required" in node
137+
assert prop_name in node["required"]
138+
139+
asdf.treeutil.walk(schema, callback)
140+
141+
121142
def test_flowstyle(schema, manifest):
122143
is_tag_schema = schema["id"] in {t["schema_uri"] for t in manifest["tags"]}
123144

0 commit comments

Comments
 (0)