Skip to content

Commit

Permalink
Merge pull request #215 from StijnCaerts/#213-urlencode-next-href
Browse files Browse the repository at this point in the history
URL encode next href
  • Loading branch information
jamesfisher-geo authored Mar 18, 2024
2 parents 1f2700d + 6fdf201 commit d768319
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
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

0 comments on commit d768319

Please sign in to comment.