Skip to content

Commit e5e7fc2

Browse files
authored
Validate list LENGTH queries with validator (#1637)
* Validate LENGTH queries on lists * Tweak validation of missing version: query versioned info instead * Add optional LENGTH validation carve out for structure features
1 parent 1713044 commit e5e7fc2

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

optimade/validator/config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
),
8080
DataType.INTEGER: inclusive_ops,
8181
DataType.FLOAT: (),
82-
DataType.LIST: ("HAS", "HAS ALL", "HAS ANY"),
82+
DataType.LIST: ("HAS", "HAS ALL", "HAS ANY", "LENGTH"),
8383
}
8484

8585
exclusive_ops = ("!=", "<", ">")
@@ -108,6 +108,9 @@
108108
if op != "="
109109
],
110110
},
111+
"structure_features": {
112+
SupportLevel.OPTIONAL: "LENGTH",
113+
},
111114
}
112115

113116

optimade/validator/validator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,8 @@ def _format_test_value(test_value: Any, prop_type: DataType, operator: str) -> s
682682
else:
683683
_vals = [f"{val}" for val in _vals]
684684
_test_value = ",".join(_vals)
685+
elif operator == "LENGTH":
686+
_test_value = f"{len(test_value)}"
685687
else:
686688
if isinstance(test_value[0], str):
687689
_test_value = f'"{test_value[0]}"'
@@ -1238,7 +1240,7 @@ def _test_bad_version_returns_553(self) -> None:
12381240
expected_status_code = [404, 400]
12391241

12401242
self._get_endpoint(
1241-
"v123123", expected_status_code=expected_status_code, optional=True
1243+
"v123123/info", expected_status_code=expected_status_code, optional=True
12421244
)
12431245

12441246
@test_case

0 commit comments

Comments
 (0)