Skip to content

Commit a432be8

Browse files
thodson-usgsclaude
andcommitted
Harden POST-route test to assert CQL2 envelope shape
Replace `assert req.body is not None` (which passes for empty bytes, malformed JSON, or any truthy value) with structural checks on the parsed CQL2 body: top-level AND, the single IN predicate, the value list in order. Also asserts the Content-Type header. Future regressions in `_cql2_param` or routing fail loudly with a clear message instead of slipping through. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 999eebe commit a432be8

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

tests/waterdata_test.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime
2+
import json
23
import sys
34
from unittest import mock
45

@@ -131,7 +132,18 @@ def test_construct_api_requests_monitoring_locations_post():
131132
hydrologic_unit_code=["010802050102", "010802050103"],
132133
)
133134
assert req.method == "POST"
134-
assert req.body is not None
135+
assert req.headers["Content-Type"] == "application/query-cql-json"
136+
137+
body = json.loads(req.body)
138+
# Top-level shape: AND over a list of per-param predicates.
139+
assert body["op"] == "and"
140+
assert isinstance(body["args"], list) and len(body["args"]) == 1
141+
142+
# The single predicate is an IN over hydrologic_unit_code with both values.
143+
predicate = body["args"][0]
144+
assert predicate["op"] == "in"
145+
assert predicate["args"][0] == {"property": "hydrologic_unit_code"}
146+
assert predicate["args"][1] == ["010802050102", "010802050103"]
135147

136148

137149
def test_construct_api_requests_single_value_stays_get():

0 commit comments

Comments
 (0)