-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d19ad05
commit e6e8820
Showing
11 changed files
with
370 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""titiler.stacapi tests.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"type":"Feature","stac_version":"1.0.0","id":"20200307aC0853900w361030","properties":{"event":"Nashville Tornado","datetime":"2020-03-07T00:00:00Z"},"geometry":{"type":"Polygon","coordinates":[[[-85.6501,36.1751],[-85.6501,36.1499],[-85.6249,36.1499],[-85.6249,36.1751],[-85.6501,36.1751]]]},"links":[{"rel":"collection","href":"noaa-emergency-response","type":"application/json"}],"assets":{"cog":{"href":"https://noaa-eri-pds.s3.us-east-1.amazonaws.com/2020_Nashville_Tornado/20200307a_RGB/20200307aC0853900w361030n.tif","type":"image/tiff; application=geotiff; profile=cloud-optimized"}},"bbox":[-85.6501,36.1499,-85.6249,36.1751],"stac_extensions":[],"collection":"noaa-emergency-response"} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"id":"noaa-emergency-response", "title": "NOAA Emergency Response Imagery", "description":"NOAA Emergency Response Imagery hosted on AWS Public Dataset.","stac_version":"1.0.0","license":"public-domain","links":[],"extent":{"spatial":{"bbox":[[-180,-90,180,90]]},"temporal":{"interval":[["2005-01-01T00:00:00Z",null]]}}} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"""test titiler-stacapi mosaic backend.""" | ||
|
||
import json | ||
import os | ||
from unittest.mock import patch | ||
|
||
from geojson_pydantic import Polygon | ||
|
||
from titiler.stacapi.backend import STACAPIBackend | ||
|
||
from .conftest import mock_rasterio_open | ||
|
||
item_json = os.path.join( | ||
os.path.dirname(__file__), "fixtures", "20200307aC0853900w361030.json" | ||
) | ||
|
||
|
||
@patch("rio_tiler.io.rasterio.rasterio") | ||
@patch("titiler.stacapi.backend.STACAPIBackend.get_assets") | ||
def test_stac_backend(get_assets, rio): | ||
"""test STACAPIBackend.""" | ||
rio.open = mock_rasterio_open | ||
|
||
with open(item_json, "r") as f: | ||
get_assets.return_value = [json.loads(f.read())] | ||
|
||
with STACAPIBackend("http://endpoint.stac") as stac: | ||
pass | ||
|
||
with STACAPIBackend("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: | ||
img, assets = stac.tile( | ||
8589, | ||
12849, | ||
15, | ||
search_query={"collections": ["col"], "ids": ["20200307aC0853900w361030"]}, | ||
assets=["cog"], | ||
) | ||
assert assets[0]["id"] == "20200307aC0853900w361030" | ||
assert isinstance(get_assets.call_args.args[0], Polygon) | ||
assert get_assets.call_args.kwargs["search_query"] == { | ||
"collections": ["col"], | ||
"ids": ["20200307aC0853900w361030"], | ||
} | ||
assert img.metadata["timings"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"""Test titiler.stacapi Item endpoints.""" | ||
|
||
import json | ||
import os | ||
from unittest.mock import patch | ||
|
||
from .conftest import mock_rasterio_open | ||
|
||
item_json = os.path.join( | ||
os.path.dirname(__file__), "fixtures", "20200307aC0853900w361030.json" | ||
) | ||
|
||
|
||
@patch("titiler.stacapi.factory.STACAPIBackend.get_assets") | ||
@patch("rio_tiler.io.rasterio.rasterio") | ||
def test_stac_collections(rio, get_assets, app): | ||
"""test STAC items endpoints.""" | ||
rio.open = mock_rasterio_open | ||
|
||
with open(item_json, "r") as f: | ||
get_assets.return_value = [json.loads(f.read())] | ||
|
||
response = app.get( | ||
"/collections/noaa-emergency-response/tiles/WebMercatorQuad/15/8589/12849.png", | ||
params={ | ||
"assets": "cog", | ||
"datetime": "2024-01-01", | ||
}, | ||
) | ||
assert response.status_code == 200 | ||
|
||
response = app.get( | ||
"/collections/noaa-emergency-response/WebMercatorQuad/tilejson.json", | ||
params={ | ||
"assets": "cog", | ||
"minzoom": 12, | ||
"maxzoom": 14, | ||
}, | ||
) | ||
assert response.status_code == 200 | ||
resp = response.json() | ||
assert resp["minzoom"] == 12 | ||
assert resp["maxzoom"] == 14 | ||
assert "?assets=cog" in resp["tiles"][0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
"""Test titiler.stacapi Item endpoints.""" | ||
|
||
import json | ||
import os | ||
from unittest.mock import patch | ||
|
||
import pystac | ||
import pytest | ||
from httpx import HTTPStatusError, RequestError | ||
|
||
from titiler.stacapi.dependencies import get_stac_item | ||
|
||
from .conftest import mock_rasterio_open | ||
|
||
item_json = os.path.join( | ||
os.path.dirname(__file__), "fixtures", "20200307aC0853900w361030.json" | ||
) | ||
|
||
|
||
class MockResponse: | ||
"""Mock HTTX response.""" | ||
|
||
def __init__(self, data): | ||
"""init.""" | ||
self.data = data | ||
|
||
def raise_for_status(self): | ||
"""raise_for_status""" | ||
pass | ||
|
||
@property | ||
def content(self): | ||
"""return content.""" | ||
return self.data | ||
|
||
def json(self): | ||
"""return json.""" | ||
return json.loads(self.data) | ||
|
||
|
||
@patch("titiler.stacapi.dependencies.httpx") | ||
def test_get_stac_item(httpx): | ||
"""test get_stac_item.""" | ||
|
||
with open(item_json, "r") as f: | ||
httpx.get.return_value = MockResponse(f.read()) | ||
httpx.HTTPStatusError = HTTPStatusError | ||
httpx.RequestError = RequestError | ||
|
||
item = get_stac_item( | ||
"http://endpoint.stac", "noaa-emergency-response", "20200307aC0853900w361030" | ||
) | ||
assert isinstance(item, pystac.Item) | ||
assert item.id == "20200307aC0853900w361030" | ||
assert item.collection_id == "noaa-emergency-response" | ||
|
||
|
||
@patch("rio_tiler.io.rasterio.rasterio") | ||
@patch("titiler.stacapi.dependencies.httpx") | ||
def test_stac_items(httpx, rio, app): | ||
"""test STAC items endpoints.""" | ||
rio.open = mock_rasterio_open | ||
|
||
with open(item_json, "r") as f: | ||
httpx.get.return_value = MockResponse(f.read()) | ||
httpx.HTTPStatusError = HTTPStatusError | ||
httpx.RequestError = RequestError | ||
|
||
response = app.get( | ||
"/collections/noaa-emergency-response/items/20200307aC0853900w361030/assets", | ||
) | ||
assert response.status_code == 200 | ||
assert response.json() == ["cog"] | ||
|
||
with pytest.warns(UserWarning): | ||
response = app.get( | ||
"/collections/noaa-emergency-response/items/20200307aC0853900w361030/info", | ||
) | ||
assert response.status_code == 200 | ||
assert response.json()["cog"] | ||
|
||
response = app.get( | ||
"/collections/noaa-emergency-response/items/20200307aC0853900w361030/info", | ||
params={"assets": "cog"}, | ||
) | ||
assert response.status_code == 200 | ||
assert response.json()["cog"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters