From 4b1846b20aba4c6442cdbdbe6fc3d70b4b4fce8e Mon Sep 17 00:00:00 2001 From: Julia Signell Date: Wed, 17 Apr 2024 05:45:05 -0400 Subject: [PATCH] Sins acknowledged --- stat_fastapi/api.py | 2 +- stat_fastapi/models/opportunity.py | 7 +++++-- stat_fastapi_test_backend/backend.py | 5 +---- stat_fastapi_tle_backend/backend.py | 2 +- tests/order_test.py | 3 +-- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/stat_fastapi/api.py b/stat_fastapi/api.py index 5ce0a4d..1dcfc04 100644 --- a/stat_fastapi/api.py +++ b/stat_fastapi/api.py @@ -9,7 +9,7 @@ OpportunityCollection, OpportunitySearch, ) -from stat_fastapi.models.order import Order +from stat_fastapi.models.order import Order from stat_fastapi.models.product import Product, ProductsCollection from stat_fastapi.models.root import RootResponse from stat_fastapi.models.shared import HTTPException as HTTPExceptionModel diff --git a/stat_fastapi/models/opportunity.py b/stat_fastapi/models/opportunity.py index fd278de..25e44d8 100644 --- a/stat_fastapi/models/opportunity.py +++ b/stat_fastapi/models/opportunity.py @@ -1,24 +1,27 @@ -from typing import Any, Literal, Mapping +from typing import Literal from geojson_pydantic import Feature, FeatureCollection from geojson_pydantic.geometries import Geometry - from pydantic import BaseModel from stat_fastapi.models.constraints import Constraints from stat_fastapi.types.datetime_interval import DatetimeInterval + # Copied and modified from stack_pydantic.item.ItemProperties class OpportunityProperties(BaseModel): datetime: DatetimeInterval product_id: str constraints: Constraints + class OpportunitySearch(OpportunityProperties): geometry: Geometry + class Opportunity(Feature[Geometry, OpportunityProperties]): type: Literal["Feature"] = "Feature" + class OpportunityCollection(FeatureCollection[Opportunity]): type: Literal["FeatureCollection"] = "FeatureCollection" diff --git a/stat_fastapi_test_backend/backend.py b/stat_fastapi_test_backend/backend.py index 99d2d8b..b9407e3 100644 --- a/stat_fastapi_test_backend/backend.py +++ b/stat_fastapi_test_backend/backend.py @@ -36,10 +36,7 @@ def product(self, product_id: str, request: Request) -> Product | None: async def search_opportunities( self, search: OpportunitySearch, request: Request ) -> list[Opportunity]: - return [ - o.model_copy(update=search.model_dump()) - for o in self._opportunities - ] + return [o.model_copy(update=search.model_dump()) for o in self._opportunities] async def create_order(self, payload: OpportunitySearch, request: Request) -> Order: """ diff --git a/stat_fastapi_tle_backend/backend.py b/stat_fastapi_tle_backend/backend.py index e992dda..5d5d6bb 100644 --- a/stat_fastapi_tle_backend/backend.py +++ b/stat_fastapi_tle_backend/backend.py @@ -5,12 +5,12 @@ from stat_fastapi.models.opportunity import Opportunity, OpportunitySearch from stat_fastapi.models.order import Order from stat_fastapi.models.product import Product, Provider, ProviderRole - from stat_fastapi_tle_backend.models import ValidatedOpportunitySearch from stat_fastapi_tle_backend.repository import Repository from stat_fastapi_tle_backend.satellite import EarthObservationSatelliteModel from stat_fastapi_tle_backend.settings import Settings + class OffNadirRange(BaseModel): minimum: float = Field(ge=0.0, le=45) maximum: float = Field(ge=0.0, le=45) diff --git a/tests/order_test.py b/tests/order_test.py index 29a3c39..921a4d3 100644 --- a/tests/order_test.py +++ b/tests/order_test.py @@ -62,6 +62,5 @@ def test_get_order_properties(get_order_response: Response, allowed_payloads): } assert ( - order["properties"]["datetime"] - == allowed_payloads[0].model_dump()["datetime"] + order["properties"]["datetime"] == allowed_payloads[0].model_dump()["datetime"] )