From e431a3f1853d4c0d3f5e0d85cb3e5923c86c965a Mon Sep 17 00:00:00 2001 From: Rob Emanuele Date: Mon, 1 Nov 2021 20:49:06 -0400 Subject: [PATCH] Test item extra_links with relative href --- stac_fastapi/pgstac/tests/data/test_item.json | 5 ++++ .../pgstac/tests/resources/test_item.py | 26 ++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/stac_fastapi/pgstac/tests/data/test_item.json b/stac_fastapi/pgstac/tests/data/test_item.json index 2b7fdd860..a6e85a00d 100644 --- a/stac_fastapi/pgstac/tests/data/test_item.json +++ b/stac_fastapi/pgstac/tests/data/test_item.json @@ -500,6 +500,11 @@ "href": "http://localhost:8081/", "rel": "root", "type": "application/json" + }, + { + "href": "preview.html", + "rel": "preview", + "type": "application/html" } ] } \ No newline at end of file diff --git a/stac_fastapi/pgstac/tests/resources/test_item.py b/stac_fastapi/pgstac/tests/resources/test_item.py index 5fa747699..d74bb1f04 100644 --- a/stac_fastapi/pgstac/tests/resources/test_item.py +++ b/stac_fastapi/pgstac/tests/resources/test_item.py @@ -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 @@ -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