Skip to content

Commit

Permalink
Test relative link paths
Browse files Browse the repository at this point in the history
  • Loading branch information
moradology committed Aug 10, 2021
1 parent 1d26a38 commit 2063c09
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
10 changes: 5 additions & 5 deletions stac_fastapi/pgstac/stac_fastapi/pgstac/models/links.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,15 @@ def __post_init__(self):
"""Post init handler."""
self.item_uri = urljoin(
self.base_url,
f"/collections/{self.collection_id}/items/{self.item_id}",
f"collections/{self.collection_id}/items/{self.item_id}",
)

def link_tiles(self) -> Dict:
"""Create tiles link."""
return dict(
href=urljoin(
self.base_url,
f"/titiler/tiles/{{z}}/{{x}}/{{y}}.png?url={self.item_uri}",
f"titiler/tiles/{{z}}/{{x}}/{{y}}.png?url={self.item_uri}",
),
rel=Relations.item.value,
title="tiles",
Expand All @@ -258,7 +258,7 @@ def link_tiles(self) -> Dict:
def link_viewer(self) -> Dict:
"""Create viewer link."""
return dict(
href=urljoin(self.base_url, f"/titiler/viewer?url={self.item_uri}"),
href=urljoin(self.base_url, f"titiler/viewer?url={self.item_uri}"),
rel=Relations.alternate.value,
type=MimeTypes.html.value,
title="viewer",
Expand All @@ -267,7 +267,7 @@ def link_viewer(self) -> Dict:
def link_tilejson(self) -> Dict:
"""Create tilejson link."""
return dict(
href=urljoin(self.base_url, f"/titiler/tilejson.json?url={self.item_uri}"),
href=urljoin(self.base_url, f"titiler/tilejson.json?url={self.item_uri}"),
rel=Relations.alternate.value,
type=MimeTypes.json.value,
title="tilejson",
Expand All @@ -278,7 +278,7 @@ def link_wmts(self) -> Dict:
return dict(
href=urljoin(
self.base_url,
f"/titiler/WMTSCapabilities.xml?url={self.item_uri}",
f"titiler/WMTSCapabilities.xml?url={self.item_uri}",
),
rel=Relations.alternate.value,
type=MimeTypes.xml.value,
Expand Down
23 changes: 23 additions & 0 deletions stac_fastapi/pgstac/tests/resources/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from shapely.geometry import Polygon
from stac_pydantic import Collection, Item
from stac_pydantic.shared import DATETIME_RFC339
from starlette.requests import Request

from stac_fastapi.pgstac.models.links import CollectionLinks


@pytest.mark.asyncio
Expand Down Expand Up @@ -907,3 +910,23 @@ async def test_search_invalid_query_field(app_client):
body = {"query": {"gsd": {"lt": 100}, "invalid-field": {"eq": 50}}}
resp = await app_client.post("/search", json=body)
assert resp.status_code == 400


@pytest.mark.asyncio
async def test_relative_link_construction(load_test_data, altered_root_app_client):

req = Request(
scope={
'type': 'http',
'scheme': 'http',
'method': 'PUT',
'root_path': 'http://test/stac',
'path': '/',
'raw_path': b'/tab/abc',
'query_string': b'',
'headers': {}
}
)
links = CollectionLinks(collection_id="naip", request=req)

assert links.link_items()['href'] == "http://test/stac/collections/naip/items"
1 change: 1 addition & 0 deletions stac_fastapi/sqlalchemy/tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from ..conftest import MockStarletteRequest


STAC_CORE_ROUTES = [
"GET /",
"GET /collections",
Expand Down

0 comments on commit 2063c09

Please sign in to comment.