Skip to content

Commit 6ebcdc0

Browse files
committed
Lint
1 parent 8df7890 commit 6ebcdc0

File tree

4 files changed

+29
-85
lines changed

4 files changed

+29
-85
lines changed

src/stac_auth_proxy/handlers/reverse_proxy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import logging
55
import time
66
from dataclasses import dataclass
7-
from typing import Annotated, Any, Callable, Optional
7+
from typing import Annotated, Callable, Optional
88

99
import httpx
1010
from cql2 import Expr
@@ -62,6 +62,7 @@ def _get_filter(self, path: str) -> Optional[Callable[..., Expr]]:
6262
for check, builder in endpoint_filters:
6363
if check(path):
6464
return builder
65+
return None
6566

6667
async def proxy_request(self, request: Request, *, stream=False) -> httpx.Response:
6768
"""Proxy a request to the upstream STAC API."""

tests/fixtures/__init__.py

Whitespace-only changes.

tests/fixtures/demo_searches.py

Lines changed: 0 additions & 66 deletions
This file was deleted.

tests/test_filters_jinja2.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55

66
import cql2
77
import pytest
8-
from httpx import Request
98
from fastapi.testclient import TestClient
9+
from httpx import Request
1010
from utils import AppFactory
1111

12-
from fixtures.demo_searches import SEARCHES
13-
1412
app_factory = AppFactory(
1513
oidc_discovery_url="https://example-stac-api.com/.well-known/openid-configuration",
1614
default_public=False,
@@ -198,21 +196,33 @@
198196
"true",
199197
"""{"op": "=", "args": [{"property": "private"}, true]}""",
200198
],
201-
# Not sure what is demonstrated in this...
202-
# [
203-
# """{
204-
# "op": "and",
205-
# "args": [
206-
# { "op": "=", "args": [{ "property": "id" }, "LC08_L1TP_060247_20180905_20180912_01_T1_L1TP" ] },
207-
# { "op": "=", "args": [{ "property": "collection" }, "landsat8_l1tp"] }
208-
# ]
209-
# }"""
210-
# ]
211-
# * 3,
212199
],
213200
)
214201
@pytest.mark.parametrize("is_authenticated", [True, False])
215-
@pytest.mark.parametrize("input_query", SEARCHES)
202+
@pytest.mark.parametrize(
203+
"input_query",
204+
[
205+
# Not using filter
206+
{
207+
"collections": ["example-collection"],
208+
"bbox": [-120.5, 35.7, -120.0, 36.0],
209+
"datetime": "2021-06-01T00:00:00Z/2021-06-30T23:59:59Z",
210+
},
211+
# Using filter
212+
{
213+
"filter-lang": "cql2-json",
214+
"filter": {
215+
"op": "and",
216+
"args": [
217+
{"op": "=", "args": [{"property": "collection"}, "landsat-8-l1"]},
218+
{"op": "<=", "args": [{"property": "eo:cloud_cover"}, 20]},
219+
{"op": "=", "args": [{"property": "platform"}, "landsat-8"]},
220+
],
221+
},
222+
"limit": 5,
223+
},
224+
],
225+
)
216226
def test_search_post(
217227
mock_upstream,
218228
source_api_server,
@@ -223,6 +233,7 @@ def test_search_post(
223233
input_query,
224234
token_builder,
225235
):
236+
"""Test filter is applied to search with full-featured filtering."""
226237
# Setup app
227238
app = app_factory(
228239
upstream_url=source_api_server,
@@ -246,19 +257,17 @@ def test_search_post(
246257
output_query = json.loads(r.read().decode())
247258

248259
# Parse query from upstream
249-
# input_filter_lang = input_query.get("filter-lang")
250260
input_filter = input_query.get("filter")
251261
expected_filter = auth_filter if is_authenticated else anon_filter
252262
expected_filter_exprs = [
253263
cql2.Expr(expr).to_text()
254264
for expr in [input_filter, expected_filter.strip()]
255265
if expr
256266
]
257-
expected_filter_out = cql2.Expr(" AND ".join(expected_filter_exprs)).to_json()
258267

259268
expected_output_query = {
260269
**input_query,
261-
"filter": expected_filter_out,
270+
"filter": cql2.Expr(" AND ".join(expected_filter_exprs)).to_json(),
262271
}
263272

264273
assert (

0 commit comments

Comments
 (0)