45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
from fastapi import HTTPException
|
|
|
|
from app.api.v1 import layers
|
|
|
|
|
|
def test_layer_guard_requires_bbox():
|
|
try:
|
|
layers._parse_layer_bbox("")
|
|
except HTTPException as exc:
|
|
assert exc.status_code == 400
|
|
else:
|
|
raise AssertionError("Expected missing bbox to fail")
|
|
|
|
|
|
def test_layer_guard_filters_bbox_and_clamps_low_zoom_limit():
|
|
geojson = {
|
|
"type": "FeatureCollection",
|
|
"features": [
|
|
{
|
|
"type": "Feature",
|
|
"geometry": {"type": "Point", "coordinates": [121.0, 31.0]},
|
|
"properties": {"id": "inside"},
|
|
},
|
|
{
|
|
"type": "Feature",
|
|
"geometry": {"type": "Point", "coordinates": [10.0, 10.0]},
|
|
"properties": {"id": "outside"},
|
|
},
|
|
],
|
|
}
|
|
|
|
result = layers._guard_geojson_layer(
|
|
geojson,
|
|
bbox=(120.0, 30.0, 122.0, 32.0),
|
|
zoom=2,
|
|
limit=6000,
|
|
)
|
|
|
|
assert result["returned_count"] == 1
|
|
assert result["visible_count"] == 1
|
|
assert result["features"][0]["properties"]["id"] == "inside"
|
|
assert result["diagnostics"]["limit"] == layers.LOW_ZOOM_FEATURE_LIMIT
|
|
assert result["diagnostics"]["limit_clamped"] is True
|
|
assert result["diagnostics"]["degraded"] is True
|