diff --git a/tests/test_app.py b/tests/test_app.py index 4651d37..b9d92d9 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -1,9 +1,11 @@ """test titiler-cmr app.""" import io +from copy import deepcopy from typing import Tuple import pytest +from fastapi.testclient import TestClient from httpx import Response from PIL import Image from rasterio.errors import NotGeoreferencedWarning @@ -187,7 +189,6 @@ def test_xarray_statistics( params=xarray_query_params, json=arctic_geojson, ) - assert response.status_code == 200 assert response.headers["content-type"] == "application/geo+json" resp = response.json() @@ -254,7 +255,7 @@ def test_xarray_part( def test_timeseries_statistics( - app, + app: TestClient, mocker, mock_cmr_get_assets, xarray_query_params, @@ -266,7 +267,7 @@ def test_timeseries_statistics( we need to catch those requests and mock a response since we can't forward them to the test client. """ - arctic_stats = arctic_geojson.copy() + arctic_stats = deepcopy(arctic_geojson) arctic_stats["properties"]["statistics"] = { "sea_ice_fraction": { "min": 0, @@ -292,7 +293,7 @@ async def mock_timestep_request(url: str, **kwargs) -> Response: }, json=arctic_geojson, ) - + print(response.text) assert response.status_code == 200 assert response.headers["content-type"] == "application/geo+json" diff --git a/titiler/cmr/timeseries.py b/titiler/cmr/timeseries.py index 84a4f22..f8f261e 100644 --- a/titiler/cmr/timeseries.py +++ b/titiler/cmr/timeseries.py @@ -7,7 +7,7 @@ from datetime import datetime, timedelta from enum import Enum from types import DynamicClassAttribute -from typing import Annotated, Any, Dict, List, Literal, Optional, Tuple +from typing import Annotated, Any, Dict, List, Literal, Optional, Tuple, Union from urllib.parse import urlencode import earthaccess @@ -17,7 +17,7 @@ from fastapi import Body, Depends, Path, Query, Request, Response from fastapi.exceptions import HTTPException from fastapi.responses import StreamingResponse -from geojson_pydantic import Feature +from geojson_pydantic import Feature, FeatureCollection from PIL import Image from pydantic import BaseModel @@ -26,6 +26,7 @@ from titiler.core.algorithm import algorithms as available_algorithms from titiler.core.dependencies import CoordCRSParams, DefaultDependency, DstCRSParams from titiler.core.factory import FactoryExtension +from titiler.core.models.responses import MultiBaseStatisticsGeoJSON from titiler.core.resources.enums import ImageType from titiler.core.resources.responses import GeoJSONResponse @@ -227,7 +228,7 @@ def timeseries_query( else: raise HTTPException( status_code=400, - detail="you must provide start_datetime, end_datetime, and step", + detail="you must provide at least start_datetime and end_datetime", ) return [ @@ -279,6 +280,7 @@ def register_statistics(self, factory: Endpoints): @factory.router.post( "/timeseries/statistics", + response_model=MultiBaseStatisticsGeoJSON, response_model_exclude_none=True, response_class=GeoJSONResponse, responses={ @@ -292,8 +294,8 @@ def register_statistics(self, factory: Endpoints): async def timeseries_geojson_statistics( request: Request, geojson: Annotated[ - Feature, - Body(description="GeoJSON Feature or FeatureCollection."), + Union[FeatureCollection, Feature], + Body(description="GeoJSON Feature or FeatureCollection.", embed=False), ], query=Depends(timeseries_query), coord_crs=Depends(CoordCRSParams),