Skip to content

Commit

Permalink
more tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
hrodmn committed Oct 28, 2024
1 parent 7864b42 commit 694cb45
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
9 changes: 5 additions & 4 deletions tests/test_app.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -254,7 +255,7 @@ def test_xarray_part(


def test_timeseries_statistics(
app,
app: TestClient,
mocker,
mock_cmr_get_assets,
xarray_query_params,
Expand All @@ -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,
Expand All @@ -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"

Expand Down
12 changes: 7 additions & 5 deletions titiler/cmr/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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 [
Expand Down Expand Up @@ -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={
Expand All @@ -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),
Expand Down

0 comments on commit 694cb45

Please sign in to comment.