1+ from datetime import datetime , timezone
12from uuid import uuid4
23
34from fastapi import FastAPI , Request
45
56from stapi_fastapi .backends .product_backend import ProductBackend
67from stapi_fastapi .backends .root_backend import RootBackend
7- from stapi_fastapi .exceptions import ConstraintsException , NotFoundException
8+ from stapi_fastapi .exceptions import NotFoundException
89from stapi_fastapi .models .conformance import CORE
910from stapi_fastapi .models .opportunity import (
1011 Opportunity ,
11- OpportunityPropertiesBase ,
12+ OpportunityProperties ,
1213 OpportunityRequest ,
1314)
14- from stapi_fastapi .models .order import Order , OrderCollection
15- from stapi_fastapi .models .product import (
15+ from stapi_fastapi .models .order import (
16+ Order ,
17+ OrderCollection ,
1618 OrderParameters ,
19+ OrderRequest ,
20+ OrderStatus ,
21+ OrderStatusCode ,
22+ )
23+ from stapi_fastapi .models .product import (
1724 Product ,
1825 Provider ,
1926 ProviderRole ,
2027)
28+ from stapi_fastapi .routers .product_router import ProductRouter
2129from stapi_fastapi .routers .root_router import RootRouter
2230
2331
@@ -48,43 +56,57 @@ async def get_order(self, order_id: str, request: Request) -> Order:
4856class MockProductBackend (ProductBackend ):
4957 def __init__ (self , orders : MockOrderDB ) -> None :
5058 self ._opportunities : list [Opportunity ] = []
51- self ._allowed_payloads : list [OpportunityRequest ] = []
59+ self ._allowed_payloads : list [OrderRequest ] = []
5260 self ._orders : MockOrderDB = orders
5361
5462 async def search_opportunities (
55- self , product : Product , search : OpportunityRequest , request : Request
63+ self ,
64+ product_router : ProductRouter ,
65+ search : OpportunityRequest ,
66+ request : Request ,
5667 ) -> list [Opportunity ]:
5768 return [o .model_copy (update = search .model_dump ()) for o in self ._opportunities ]
5869
5970 async def create_order (
60- self , product : Product , payload : OpportunityRequest , request : Request
71+ self , product_router : ProductRouter , payload : OrderRequest , request : Request
6172 ) -> Order :
6273 """
6374 Create a new order.
6475 """
65- allowed : bool = any (allowed == payload for allowed in self ._allowed_payloads )
66- if allowed :
67- order = Order (
68- id = str (uuid4 ()),
69- geometry = payload .geometry ,
70- properties = {
71- "filter" : payload .filter ,
76+ order = Order (
77+ id = str (uuid4 ()),
78+ geometry = payload .geometry ,
79+ properties = {
80+ "product_id" : product_router .product .id ,
81+ "created" : datetime .now (timezone .utc ),
82+ "status" : OrderStatus (
83+ timestamp = datetime .now (timezone .utc ),
84+ status_code = OrderStatusCode .accepted ,
85+ ),
86+ "search_parameters" : {
87+ "geometry" : payload .geometry ,
7288 "datetime" : payload .datetime ,
73- "product_id" : product .id ,
89+ "filter" : payload .filter ,
90+ },
91+ "order_parameters" : payload .order_parameters .model_dump (),
92+ "opportunity_properties" : {
93+ "datetime" : "2024-01-29T12:00:00Z/2024-01-30T12:00:00Z" ,
94+ "off_nadir" : 10 ,
7495 },
75- links = [],
76- )
77- self ._orders [order .id ] = order
78- return order
79- raise ConstraintsException ("not allowed" )
96+ },
97+ links = [],
98+ )
99+
100+ self ._orders [order .id ] = order
101+ return order
80102
81103
82- class TestSpotlightProperties ( OpportunityPropertiesBase ):
104+ class MyOpportunityProperties ( OpportunityProperties ):
83105 off_nadir : int
84106
85107
86- class TestSpotlightOrderParameters (OrderParameters ):
87- delivery_mechanism : str | None = None
108+ class MyOrderParameters (OrderParameters ):
109+ s3_path : str | None = None
88110
89111
90112order_db = MockOrderDB ()
@@ -106,8 +128,8 @@ class TestSpotlightOrderParameters(OrderParameters):
106128 keywords = ["test" , "satellite" ],
107129 providers = [provider ],
108130 links = [],
109- constraints = TestSpotlightProperties ,
110- order_parameters = TestSpotlightOrderParameters ,
131+ constraints = MyOpportunityProperties ,
132+ order_parameters = MyOrderParameters ,
111133 backend = product_backend ,
112134)
113135
0 commit comments