示例#1
0
def test_withCustomRoute(monkeypatch):
    """Create App."""
    monkeypatch.setenv("GDAL_DISABLE_READDIR_ON_OPEN", "something")

    app = FastAPI()

    env = dict(GDAL_DISABLE_READDIR_ON_OPEN="FALSE")
    with pytest.warns(DeprecationWarning):
        route_class = apiroute_factory(env)
    router = APIRouter(route_class=route_class)

    def f(r):
        return get_gdal_config("GDAL_DISABLE_READDIR_ON_OPEN")

    @router.get("/simple")
    def home():
        """Works and should return FALSE."""
        res = get_gdal_config("GDAL_DISABLE_READDIR_ON_OPEN")
        return {"env": res}

    @router.get("/asimple")
    async def home1():
        """Works and should return FALSE."""
        res = get_gdal_config("GDAL_DISABLE_READDIR_ON_OPEN")
        return {"env": res}

    @router.get("/future")
    def home2():
        """Doesn't work and should return the value from env."""
        with futures.ThreadPoolExecutor() as executor:
            res = list(executor.map(f, range(1)))[0]
        return {"env": res}

    @router.get("/afuture")
    async def home3():
        """Works and should return FALSE."""
        with futures.ThreadPoolExecutor() as executor:
            res = list(executor.map(f, range(1)))[0]
        return {"env": res}

    app.include_router(router)
    client = TestClient(app)

    response = client.get("/simple")
    assert response.json()["env"] == "FALSE"

    response = client.get("/asimple")
    assert response.json()["env"] == "FALSE"

    # confirm the Custom APIRoute class fix
    response = client.get("/future")
    assert response.json()["env"] == "FALSE"

    response = client.get("/afuture")
    assert response.json()["env"] == "FALSE"
示例#2
0
"""NAIP endpoint."""

from titiler.custom.routing import apiroute_factory
from titiler.endpoints.factory import MosaicTilerFactory
from titiler.resources.enums import OptionalHeaders

from ..dependencies import MosaicParams

from fastapi import APIRouter

route_class = apiroute_factory(
    {
        # IMPORTANT NAIP is stored in a REQUESTER-PAYS bucket
        "AWS_DEFAULT_REGION": "us-west-2",
        "AWS_REQUEST_PAYER": "requester",
    }
)

mosaicjson = MosaicTilerFactory(  # type: ignore
    path_dependency=MosaicParams,
    router_prefix="mosaicjson/naip",
    router=APIRouter(route_class=route_class),
    optional_headers=[OptionalHeaders.server_timing, OptionalHeaders.x_assets],
)
示例#3
0
"""Landsat endpoint."""

from rio_tiler_pds.landsat.aws import L8Reader

from titiler.custom.routing import apiroute_factory
from titiler.dependencies import BandsExprParams
from titiler.endpoints.factory import MosaicTilerFactory, MultiBandTilerFactory

from ..dependencies import CustomPathParams, MosaicParams

from fastapi import APIRouter

route_class = apiroute_factory({
    "AWS_NO_SIGN_REQUEST": "YES",
    "GDAL_DISABLE_READDIR_ON_OPEN": "FALSE",
    "CPL_VSIL_CURL_ALLOWED_EXTENSIONS": ".TIF,.ovr",
})

scenes = MultiBandTilerFactory(
    reader=L8Reader,
    path_dependency=CustomPathParams,
    router_prefix="scenes/landsat",
    router=APIRouter(route_class=route_class),
)

mosaicjson = MosaicTilerFactory(
    path_dependency=MosaicParams,
    dataset_reader=L8Reader,
    layer_dependency=BandsExprParams,
    router_prefix="mosaicjson/landsat",
    router=APIRouter(route_class=route_class),
示例#4
0
"""Landsat endpoint."""

from rio_tiler_pds.landsat.aws import LandsatC2Reader

from titiler.custom.routing import apiroute_factory
from titiler.dependencies import BandsExprParams
from titiler.endpoints.factory import MosaicTilerFactory, MultiBandTilerFactory

from ..dependencies import CustomPathParams, MosaicParams

from fastapi import APIRouter

route_class = apiroute_factory({
    # IMPORTANT Landsat collection 2 is stored in a REQUESTER-PAYS bucket
    "AWS_REQUEST_PAYER": "requester",
})

scenes = MultiBandTilerFactory(  # type: ignore
    reader=LandsatC2Reader,
    path_dependency=CustomPathParams,
    router_prefix="scenes/landsat",
    router=APIRouter(route_class=route_class),
)

mosaicjson = MosaicTilerFactory(  # type: ignore
    path_dependency=MosaicParams,
    dataset_reader=LandsatC2Reader,
    layer_dependency=BandsExprParams,
    router_prefix="mosaicjson/landsat",
    router=APIRouter(route_class=route_class),
)
示例#5
0
"""Sentinel endpoint."""

from rio_tiler_pds.sentinel.aws import S2COGReader

from titiler.custom.routing import apiroute_factory
from titiler.dependencies import BandsExprParams
from titiler.endpoints.factory import MosaicTilerFactory, MultiBandTilerFactory

from ..dependencies import CustomPathParams, MosaicParams

from fastapi import APIRouter

route_class = apiroute_factory({"AWS_NO_SIGN_REQUEST": "YES"})

scenes = MultiBandTilerFactory(
    reader=S2COGReader,
    path_dependency=CustomPathParams,
    router_prefix="scenes/sentinel",
    router=APIRouter(route_class=route_class),
)

mosaicjson = MosaicTilerFactory(
    path_dependency=MosaicParams,
    dataset_reader=S2COGReader,
    layer_dependency=BandsExprParams,
    router_prefix="mosaicjson/sentinel",
    router=APIRouter(route_class=route_class),
)