Skip to content

Commit

Permalink
Test item extra_links with relative href
Browse files Browse the repository at this point in the history
  • Loading branch information
lossyrob committed Nov 2, 2021
1 parent 4c37355 commit e431a3f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions stac_fastapi/pgstac/tests/data/test_item.json
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,11 @@
"href": "http://localhost:8081/",
"rel": "root",
"type": "application/json"
},
{
"href": "preview.html",
"rel": "preview",
"type": "application/html"
}
]
}
26 changes: 25 additions & 1 deletion stac_fastapi/pgstac/tests/resources/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import uuid
from datetime import datetime, timedelta
from typing import Callable
from urllib.parse import parse_qs, urlparse
from urllib.parse import parse_qs, urljoin, urlparse

import pystac
import pytest
from httpx import AsyncClient
from shapely.geometry import Polygon
from stac_pydantic import Collection, Item
from stac_pydantic.shared import DATETIME_RFC339
Expand Down Expand Up @@ -1005,3 +1006,26 @@ async def test_search_bbox_errors(app_client):
params = {"bbox": "100.0,0.0,0.0,105.0"}
resp = await app_client.get("/search", params=params)
assert resp.status_code == 400


@pytest.mark.asyncio
async def test_preserves_extra_link(
app_client: AsyncClient, load_test_data, load_test_collection
):
coll = load_test_collection
test_item = load_test_data("test_item.json")
expected_href = urljoin(str(app_client.base_url), "preview.html")

resp = await app_client.post(f"/collections/{coll['id']}/items", json=test_item)
assert resp.status_code == 200

response_item = await app_client.get(
f"/collections/{coll['id']}/items/{test_item['id']}",
params={"limit": 1},
)
assert response_item.status_code == 200
item = response_item.json()

extra_link = [link for link in item["links"] if link["rel"] == "preview"]
assert extra_link
assert extra_link[0]["href"] == expected_href

0 comments on commit e431a3f

Please sign in to comment.