Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL encode next href #215

Merged
merged 3 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed

- 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]

### Added
Expand Down
4 changes: 2 additions & 2 deletions stac_fastapi/core/stac_fastapi/core/models/links.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down
27 changes: 26 additions & 1 deletion stac_fastapi/tests/resources/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"""
Expand Down