Skip to content
Draft
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 .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
with:
version: "0.9.*"
enable-cache: true
python-version: ${{ matrix.python-version }}
python-version: ${{ env.LATEST_PY_VERSION }}

- name: Install dependencies
run: |
Expand Down
9 changes: 7 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ classifiers = [
dynamic = ["version"]
dependencies = [
"orjson",
"titiler.core>=0.19.0,<0.20",
"titiler.mosaic>=0.19.0,<0.20",
# "titiler.core>=1.0,<1.1",
# "titiler.mosaic>=1.0,<1.1",
"titiler.core @ git+https://github.com/developmentseed/titiler@feature/optional-cogeo-mosaic#egg=titiler.core&subdirectory=src/titiler/core",
"titiler.mosaic @ git+https://github.com/developmentseed/titiler@feature/optional-cogeo-mosaic#egg=titiler.mosaic&subdirectory=src/titiler/mosaic",
"pystac-client",
"pydantic>=2.4,<3.0",
"pydantic-settings~=2.0",
Expand Down Expand Up @@ -69,6 +71,9 @@ only-include = ["titiler"]
[tool.hatch.build.targets.wheel]
only-include = ["titiler"]

[tool.hatch.metadata]
allow-direct-references = true

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
Expand Down
23 changes: 14 additions & 9 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,67 +3,72 @@

def test_landing(app):
"""Test / endpoint."""
name = "TiTiler-STACAPI"

response = app.get("/")
assert response.status_code == 200
assert response.headers["content-type"] == "application/json"
body = response.json()
assert body["title"] == "titiler-stacapi"
assert body["title"] == name
assert body["links"]

response = app.get("/?f=html")
assert response.status_code == 200
assert "text/html" in response.headers["content-type"]
assert "titiler-stacapi" in response.text
assert name in response.text

# Check accept headers
response = app.get("/", headers={"accept": "text/html"})
assert response.status_code == 200
assert "text/html" in response.headers["content-type"]
assert "titiler-stacapi" in response.text
assert name in response.text

# accept quality
response = app.get(
"/", headers={"accept": "application/json;q=0.9, text/html;q=1.0"}
)
assert response.status_code == 200
assert "text/html" in response.headers["content-type"]
assert "titiler-stacapi" in response.text
assert name in response.text

# accept quality but only json is available
response = app.get("/", headers={"accept": "text/csv;q=1.0, application/json"})
assert response.status_code == 200
assert response.headers["content-type"] == "application/json"
body = response.json()
assert body["title"] == "titiler-stacapi"
assert body["title"] == name

# accept quality but only json is available
response = app.get("/", headers={"accept": "text/csv;q=1.0, */*"})
assert response.status_code == 200
assert response.headers["content-type"] == "application/json"
body = response.json()
assert body["title"] == "titiler-stacapi"
assert body["title"] == name

# Invalid accept, return default
response = app.get("/", headers={"accept": "text/htm"})
assert response.status_code == 200
assert response.headers["content-type"] == "application/json"
body = response.json()
assert body["title"] == "titiler-stacapi"
assert body["title"] == name
assert body["links"]

# make sure `?f=` has priority over headers
response = app.get("/?f=json", headers={"accept": "text/html"})
assert response.status_code == 200
assert response.headers["content-type"] == "application/json"
body = response.json()
assert body["title"] == "titiler-stacapi"
assert body["title"] == name


def test_docs(app):
"""Test /api endpoint."""
response = app.get("/api")
assert response.status_code == 200
assert response.headers["content-type"] == "application/json"
assert (
response.headers["content-type"]
== "application/vnd.oai.openapi+json;version=3.0"
)
body = response.json()
assert body["openapi"]

Expand Down
23 changes: 14 additions & 9 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from geojson_pydantic import Polygon

from titiler.stacapi.backend import STACAPIBackend
from titiler.stacapi.dependencies import APIParams, Search

from .conftest import mock_rasterio_open

Expand All @@ -24,27 +25,31 @@ def test_stac_backend(get_assets, rio):
with open(item_json, "r") as f:
get_assets.return_value = [json.loads(f.read())]

with STACAPIBackend("http://endpoint.stac") as stac:
with STACAPIBackend(
input=Search(), api_params=APIParams(url="http://endpoint.stac")
) as stac:
pass

with STACAPIBackend("http://endpoint.stac") as stac:
with STACAPIBackend(
input=Search(), api_params=APIParams(url="http://endpoint.stac")
) as stac:
assets = stac.assets_for_tile(0, 0, 0)
assert len(assets) == 1
assert isinstance(get_assets.call_args.args[0], Polygon)
assert not get_assets.call_args.kwargs

with STACAPIBackend("http://endpoint.stac") as stac:
with STACAPIBackend(
input=Search(collections=["col"], ids=["20200307aC0853900w361030"]),
api_params=APIParams(url="http://endpoint.stac"),
) as stac:
img, assets = stac.tile(
8589,
12849,
15,
search_query={"collections": ["col"], "ids": ["20200307aC0853900w361030"]},
search_options={"limit": 10},
assets=["cog"],
)
assert assets[0]["id"] == "20200307aC0853900w361030"
assert assets[0] == "noaa-emergency-response/20200307aC0853900w361030"
assert isinstance(get_assets.call_args.args[0], Polygon)
assert get_assets.call_args.kwargs["search_query"] == {
"collections": ["col"],
"ids": ["20200307aC0853900w361030"],
}
assert get_assets.call_args.kwargs["limit"] == 10
assert img.metadata["timings"]
103 changes: 0 additions & 103 deletions tests/test_dependencies.py

This file was deleted.

49 changes: 31 additions & 18 deletions tests/test_dependency_params.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""test get_dependency_params."""

from titiler.core.dependencies import RescalingParams
from titiler.stacapi.dependencies import STACQueryParams
from titiler.core.dependencies import RenderingParams
from titiler.stacapi.dependencies import SearchParams, STACAPIExtensionParams
from titiler.stacapi.factory import get_dependency_params


Expand All @@ -20,55 +20,68 @@ def _parse_rescale(rescale):

qs = {"rescale": ["0,1", "2,3"]}
assert get_dependency_params(
dependency=RescalingParams,
dependency=RenderingParams,
query_params={"rescale": _parse_rescale(qs)},
) == [(0.0, 1.0), (2.0, 3.0)]
).rescale == [(0.0, 1.0), (2.0, 3.0)]

qs = {"rescale": [[0, 1], [2, 3]]}
assert get_dependency_params(
dependency=RescalingParams,
dependency=RenderingParams,
query_params={"rescale": _parse_rescale(qs)},
) == [(0.0, 1.0), (2.0, 3.0)]
).rescale == [(0.0, 1.0), (2.0, 3.0)]


def test_get_params_stacquery():
"""test get_dependency_params for STACQueryParams."""

qs = {
"bbox": "1,2,3,4",
"datetime": "2020-01-01/2020-12-31",
"limit": 10,
"max_items": 100,
}
assert get_dependency_params(
dependency=STACQueryParams,
dependency=SearchParams,
query_params=qs,
) == {
"method": "POST",
"ids": None,
"bbox": [1.0, 2.0, 3.0, 4.0],
"datetime": "2020-01-01/2020-12-31",
"filter_expr": None,
"filter_lang": "cql2-text",
}
assert get_dependency_params(
dependency=STACAPIExtensionParams,
query_params=qs,
).as_dict(exclude_none=False) == {
"limit": 10,
"max_items": 100,
"sortby": None,
"filter": None,
}

qs = {
"ids": "a,b,c",
"bbox": "1,2,3,4",
"datetime": "2020-01-01/2020-12-31",
"filter": "property=value",
"limit": 10,
"max_items": 100,
"limit": 100,
"max_items": 1000,
"sortby": "-gsg,yo",
}
assert get_dependency_params(
dependency=STACQueryParams,
dependency=SearchParams,
query_params=qs,
) == {
"method": "GET",
"ids": ["a", "b", "c"],
"bbox": [1.0, 2.0, 3.0, 4.0],
"datetime": "2020-01-01/2020-12-31",
"filter": "property=value",
"limit": 10,
"max_items": 100,
"sortby": None,
"filter_expr": "property=value",
"filter_lang": "cql2-text",
}
assert get_dependency_params(
dependency=STACAPIExtensionParams,
query_params=qs,
).as_dict(exclude_none=False) == {
"limit": 100,
"max_items": 1000,
"sortby": ["-gsg", "yo"],
}
10 changes: 6 additions & 4 deletions tests/test_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pystac

from titiler.core import dependencies
from titiler.stacapi.dependencies import APIParams
from titiler.stacapi.factory import get_dependency_params, get_layer_from_collections

catalog_json = os.path.join(os.path.dirname(__file__), "fixtures", "catalog.json")
Expand All @@ -23,7 +24,8 @@ def test_render(client):
client.open.return_value.get_collections.return_value = collections

collections_render = get_layer_from_collections(
"https://something.stac", None, None
APIParams(url="https://something.stac"),
None,
)
assert len(collections_render) == 4

Expand All @@ -46,8 +48,8 @@ def test_render(client):
"render"
]
assert isinstance(visualr["rescale"][0], str)
rescale = get_dependency_params(
dependency=dependencies.RescalingParams,
rendering = get_dependency_params(
dependency=dependencies.RenderingParams,
query_params=visualr,
)
assert rescale
assert rendering.rescale
Loading