Skip to content

Commit

Permalink
autoformatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Lichtman committed Aug 29, 2024
1 parent c090186 commit 1cab1ee
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
8 changes: 4 additions & 4 deletions pctiler/pctiler/endpoints/pg_mosaic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from titiler.core.factory import img_endpoint_params
from titiler.core.resources.enums import ImageType
from titiler.pgstac.dependencies import SearchIdParams, TmsTileParams
from titiler.pgstac.factory import MosaicTilerFactory
from titiler.pgstac.extensions import searchInfoExtension
from titiler.pgstac.factory import MosaicTilerFactory

from pccommon.config import get_collection_config
from pccommon.config.collections import MosaicInfo
Expand All @@ -23,7 +23,6 @@

@dataclass
class AssetsBidxExprParams(dependencies.AssetsBidxExprParams):

collection: str = Query(None, description="STAC Collection ID")


Expand All @@ -46,10 +45,11 @@ def __init__(self, request: Request):
colormap_dependency=PCColorMapParams,
layer_dependency=AssetsBidxExprParams,
reader_dependency=ReaderParams,
router_prefix=get_settings().mosaic_endpoint_prefix + "/{search_id}", # reverts /searches back to /mosaic
router_prefix=get_settings().mosaic_endpoint_prefix
+ "/{search_id}", # reverts /searches back to /mosaic
backend_dependency=BackendParams,
add_statistics=False,
extensions=[searchInfoExtension()]
extensions=[searchInfoExtension()],
)


Expand Down
46 changes: 29 additions & 17 deletions pctiler/tests/endpoints/test_pg_mosaic.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ async def test_register_search_with_geom(client: AsyncClient) -> None:
"filter-lang": "cql2-json",
"filter": {
"op": "and",
"args": [{"op": "=", "args": [{"property": "collection"}, "naip"]},
{"op": "s_intersects", "args": [{"property": "geometry"}, geom]}],
"args": [
{"op": "=", "args": [{"property": "collection"}, "naip"]},
{"op": "s_intersects", "args": [{"property": "geometry"}, geom]},
],
},
}
response = await client.post("/mosaic/register", json=cql)
assert response.status_code == 200
assert response.json()["searchid"] == '2607eab51afd5d626da8d50d9df3bbf0'
assert response.json()["searchid"] == "2607eab51afd5d626da8d50d9df3bbf0"


@pytest.mark.asyncio
Expand All @@ -60,17 +62,22 @@ async def test_mosaic_info(client: AsyncClient) -> None:

@pytest.mark.asyncio
async def test_register(client: AsyncClient, register_search: REGISTER_TYPE) -> None:

expected_content_hash, register_resp = register_search

# Test that `searchid` which has been removed in titiler remains in pctiler,
# and that the search hash remains consistent
assert register_resp["searchid"] == expected_content_hash
# Test that the links have had the {tileMatrixSetId} template string removed
assert len(register_resp["links"]) == 3
assert register_resp["links"][0]["href"].endswith(f"/mosaic/{expected_content_hash}/info") # gets added by searchInfoExtension
assert register_resp["links"][1]["href"].endswith(f"/mosaic/{expected_content_hash}/tilejson.json")
assert register_resp["links"][2]["href"].endswith(f"/mosaic/{expected_content_hash}/WMTSCapabilities.xml")
assert register_resp["links"][0]["href"].endswith(
f"/mosaic/{expected_content_hash}/info"
) # gets added by searchInfoExtension
assert register_resp["links"][1]["href"].endswith(
f"/mosaic/{expected_content_hash}/tilejson.json"
)
assert register_resp["links"][2]["href"].endswith(
f"/mosaic/{expected_content_hash}/WMTSCapabilities.xml"
)


@pytest.mark.asyncio
Expand Down Expand Up @@ -122,36 +129,41 @@ async def test_mosaic_tile_routes(
assert response.status_code == 200


async def test_info_path_with_searchid(client: AsyncClient, register_search: REGISTER_TYPE) -> None:
async def test_info_path_with_searchid(
client: AsyncClient, register_search: REGISTER_TYPE
) -> None:
# route source code is here https://github.com/developmentseed/titiler/blob/main/src/titiler/mosaic/titiler/mosaic/factory.py#L157
# the searchId functionality is added by titiler-pgstac
route = "mosaic/{searchId}/info"
expected_content_hash, _ = register_search
formatted_route = route.format(searchId=expected_content_hash)
url = (f"/{formatted_route}?asset_bidx=image%7C1%2C2%2C3&assets=image&collection=naip")
url = (
f"/{formatted_route}?asset_bidx=image%7C1%2C2%2C3&assets=image&collection=naip"
)
response = await client.get(url)
assert response.status_code == 200


async def test_info_path_with_bad_searchid(client: AsyncClient) -> None:
route = "mosaic/{searchId}/info"
expected_content_hash = "9b989f86a149628eabfde894fb965982" # does not match the one we registered in the fixture
expected_content_hash = "9b989f86a149628eabfde894fb965982" # does not match the one we registered in the fixture
formatted_route = route.format(searchId=expected_content_hash)
url = (f"/{formatted_route}?asset_bidx=image%7C1%2C2%2C3&assets=image&collection=naip")
url = (
f"/{formatted_route}?asset_bidx=image%7C1%2C2%2C3&assets=image&collection=naip"
)
response = await client.get(url)
assert response.status_code == 404


async def test_bad_searchid(client: AsyncClient) -> None:
route = "mosaic/tiles/{searchId}/{z}/{x}/{y}"
expected_content_hash = "9b989f86a149628eabfde894fb965982" # does not match the one we registered in the fixture
expected_content_hash = "9b989f86a149628eabfde894fb965982" # does not match the one we registered in the fixture
formatted_route = route.format(
searchId=expected_content_hash,
z=16,
x=17218,
y=26838
searchId=expected_content_hash, z=16, x=17218, y=26838
)
url = (
f"/{formatted_route}?asset_bidx=image%7C1%2C2%2C3&assets=image&collection=naip"
)
url = (f"/{formatted_route}?asset_bidx=image%7C1%2C2%2C3&assets=image&collection=naip")
response = await client.get(url)
assert response.status_code == 404

Expand Down

0 comments on commit 1cab1ee

Please sign in to comment.