1212from stapi_fastapi .types .datetime_interval import DatetimeInterval
1313
1414from collections .abc import Iterator
15- from fastapi import FastAPI
1615from fastapi .testclient import TestClient
17- from pydantic import BaseModel
1816from stapi_fastapi .products_router import ProductRouter
17+ from stapi_fastapi .main_router import MainRouter
1918
2019from .backend import TestBackend
2120
21+ # Define concrete classes for Products to mock
22+ class UmbraSpotlight (Product ):
23+ def search_opportunities (self , search , request ):
24+ return []
25+ def create_order (self , search , request ):
26+ return []
2227
23- @pytest .fixture (scope = "session" )
24- def base_url () -> Iterator [str ]:
25- yield "http://stapiserver"
26-
27-
28- @pytest .fixture
29- def stapi_backend () -> Iterator [TestBackend ]:
30- yield TestBackend ()
28+ class UmbraSpotlightProperties (OpportunityProperties ):
29+ datetime : DatetimeInterval
3130
3231@pytest .fixture
3332def mock_product_umbra_spotlight (mock_provider_umbra : Provider ) -> Product :
3433 """Fixture for a mock Umbra Spotlight product."""
34+ now = datetime .now (timezone .utc ) # Use timezone-aware datetime
35+ start = now
36+ end = start + timedelta (days = 5 )
37+ datetime_interval = f"{ start .isoformat ()} /{ end .isoformat ()} "
3538
36- return Product (
37- id = str ( uuid4 ()) ,
39+ return UmbraSpotlight (
40+ id = "umbra-spotlight" ,
3841 title = "Umbra Spotlight Product" ,
3942 description = "Test product for umbra spotlight" ,
4043 license = "CC-BY-4.0" ,
@@ -44,16 +47,27 @@ def mock_product_umbra_spotlight(mock_provider_umbra: Provider) -> Product:
4447 Link (href = "http://example.com" , rel = "self" ),
4548 Link (href = "http://example.com/catalog" , rel = "parent" ),
4649 ],
47- parameters = UmbraSpotlightProperties
50+ parameters = UmbraSpotlightProperties (
51+ datetime = datetime_interval ,
52+ off_nadir = 20 ,
53+ )
4854 )
4955
56+ @pytest .fixture (scope = "session" )
57+ def base_url () -> Iterator [str ]:
58+ yield "http://stapiserver"
59+
60+
61+ @pytest .fixture
62+ def stapi_backend () -> Iterator [TestBackend ]:
63+ yield TestBackend ()
64+
5065@pytest .fixture
51- def stapi_client (stapi_backend , base_url : str ) -> Iterator [TestClient ]:
52- app = FastAPI ( )
66+ def stapi_client (stapi_backend , mock_product_umbra_spotlight , base_url : str ) -> Iterator [TestClient ]:
67+ app = MainRouter ( stapi_backend )
5368
54- app .include_router (
55- ProductRouter (mock_product_umbra_spotlight ),
56- prefix = "" ,
69+ app .add_product_router (
70+ ProductRouter (mock_product_umbra_spotlight )
5771 )
5872
5973 yield TestClient (app , base_url = f"{ base_url } " )
@@ -71,12 +85,14 @@ def url_for(value: str) -> str:
7185
7286
7387@pytest .fixture
74- def products () -> Iterator [list [Product ]]:
75- class Parameters (BaseModel ):
76- pass
88+ def products (mock_product_umbra_spotlight ) -> Iterator [list [Product ]]:
89+ now = datetime .now (timezone .utc ) # Use timezone-aware datetime
90+ start = now
91+ end = start + timedelta (days = 5 )
92+ datetime_interval = f"{ start .isoformat ()} /{ end .isoformat ()} "
7793
7894 yield [
79- Product (
95+ UmbraSpotlight (
8096 id = "mock:standard" ,
8197 description = "Mock backend's standard product" ,
8298 license = "CC0-1.0" ,
@@ -92,7 +108,10 @@ class Parameters(BaseModel):
92108 url = "http://acme.example.com" ,
93109 )
94110 ],
95- parameters = Parameters ,
111+ parameters = UmbraSpotlightProperties (
112+ datetime = datetime_interval ,
113+ off_nadir = 20 ,
114+ ),
96115 links = [],
97116 )
98117 ]
@@ -127,7 +146,6 @@ def allowed_payloads(products: list[Product]) -> Iterator[list[OpportunityReques
127146
128147YieldFixture = Generator [T , None , None ]
129148
130-
131149def pytest_addoption (parser : Parser ):
132150 parser .addoption (
133151 "--stapi-backend" ,
@@ -162,15 +180,6 @@ def mock_provider_umbra() -> Provider:
162180 url = "https://umbra-provider.example.com" # Must be a valid URL
163181 )
164182
165- # Define a mock OpportunityProperties class for Umbra
166- class UmbraSpotlightProperties (OpportunityProperties ):
167- datetime : DatetimeInterval
168-
169- @pytest .fixture
170- def mock_products (mock_product_umbra_spotlight : Product ) -> List [Product ]:
171- """Fixture to return a list of mock products."""
172- return [mock_product_umbra_spotlight ]
173-
174183@pytest .fixture
175184def mock_umbra_spotlight_opportunities () -> List [Opportunity ]:
176185 """Fixture to create mock data for Opportunities for `umbra-spotlight-1`."""
@@ -190,4 +199,4 @@ def mock_umbra_spotlight_opportunities() -> List[Opportunity]:
190199 off_nadir = 20 ,
191200 ),
192201 ),
193- ]
202+ ]
0 commit comments