From c520f4e679a32b4538de7224c51ae09be1eddf78 Mon Sep 17 00:00:00 2001 From: Stijn Caerts Date: Mon, 18 Mar 2024 17:41:36 +0100 Subject: [PATCH 1/2] URL encode next href (closes #213) --- CHANGELOG.md | 1 + .../core/stac_fastapi/core/models/links.py | 4 +-- stac_fastapi/tests/resources/test_item.py | 27 ++++++++++++++++++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f32cea9..03ce545d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed +- URL encode next href: [#213](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/issues/213) ## [v2.1.0] diff --git a/stac_fastapi/core/stac_fastapi/core/models/links.py b/stac_fastapi/core/stac_fastapi/core/models/links.py index 3941a149..725dc5c0 100644 --- a/stac_fastapi/core/stac_fastapi/core/models/links.py +++ b/stac_fastapi/core/stac_fastapi/core/models/links.py @@ -1,7 +1,7 @@ """link helpers.""" from typing import Any, Dict, List, Optional -from urllib.parse import ParseResult, parse_qs, unquote, urlencode, urljoin, urlparse +from urllib.parse import ParseResult, parse_qs, urlencode, urljoin, urlparse import attr from stac_pydantic.links import Relations @@ -20,7 +20,7 @@ def merge_params(url: str, newparams: Dict) -> str: u = urlparse(url) params = parse_qs(u.query) params.update(newparams) - param_string = unquote(urlencode(params, True)) + param_string = urlencode(params, True) href = ParseResult( scheme=u.scheme, diff --git a/stac_fastapi/tests/resources/test_item.py b/stac_fastapi/tests/resources/test_item.py index 958d0703..20517f42 100644 --- a/stac_fastapi/tests/resources/test_item.py +++ b/stac_fastapi/tests/resources/test_item.py @@ -2,7 +2,7 @@ import os import uuid from copy import deepcopy -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone from random import randint from urllib.parse import parse_qs, urlparse, urlsplit @@ -475,6 +475,31 @@ async def test_item_search_temporal_window_get(app_client, ctx): assert resp_json["features"][0]["id"] == test_item["id"] +@pytest.mark.asyncio +async def test_item_search_temporal_window_timezone_get(app_client, ctx): + """Test GET search with spatio-temporal query ending with Zulu and pagination(core)""" + tzinfo = timezone(timedelta(hours=1)) + test_item = ctx.item + item_date = rfc3339_str_to_datetime(test_item["properties"]["datetime"]) + item_date_before = item_date - timedelta(seconds=1) + item_date_before = item_date_before.replace(tzinfo=tzinfo) + item_date_after = item_date + timedelta(seconds=1) + item_date_after = item_date_after.replace(tzinfo=tzinfo) + + params = { + "collections": test_item["collection"], + "bbox": ",".join([str(coord) for coord in test_item["bbox"]]), + "datetime": f"{datetime_to_str(item_date_before)}/{datetime_to_str(item_date_after)}", + } + resp = await app_client.get("/search", params=params) + resp_json = resp.json() + next_link = next(link for link in resp_json["links"] if link["rel"] == "next")[ + "href" + ] + resp = await app_client.get(next_link) + assert resp.status_code == 200 + + @pytest.mark.asyncio async def test_item_search_post_without_collection(app_client, ctx): """Test POST search without specifying a collection""" From 6fdf201f50f42a61d4e277169281f53063d847f3 Mon Sep 17 00:00:00 2001 From: Stijn Caerts Date: Mon, 18 Mar 2024 19:25:25 +0100 Subject: [PATCH 2/2] reference PR #215 in CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6fa2305..3f5124ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed -- URL encode next href: [#213](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/issues/213) +- URL encode next href: [#215](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/issues/215) - Do not overwrite links in Item and Collection objects before persisting in database [#210](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/issues/210) ## [v2.1.0]