Skip to content
This repository was archived by the owner on Apr 2, 2025. It is now read-only.

Commit 152a227

Browse files
feat: adding input parameters to endpoint functions for /orders for pagination tests: creating incomplete test to start testing pagination
1 parent 40a208d commit 152a227

File tree

5 files changed

+71
-4
lines changed

5 files changed

+71
-4
lines changed

src/stapi_fastapi/backends/root_backend.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414

1515
class RootBackend[T: OrderStatusPayload, U: OrderStatus](Protocol): # pragma: nocover
16-
async def get_orders(self, request: Request) -> ResultE[OrderCollection]:
16+
async def get_orders(
17+
self, request: Request, next_token: str, limit: int
18+
) -> ResultE[OrderCollection]:
1719
"""
1820
Return a list of existing orders.
1921
"""

src/stapi_fastapi/models/order.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ def __getitem__(self, index: int) -> Order:
113113
return self.features[index]
114114

115115

116+
class Orders(BaseModel):
117+
collection: OrderCollection
118+
token: str
119+
120+
116121
class OrderPayload(BaseModel, Generic[ORP]):
117122
datetime: DatetimeInterval
118123
geometry: Geometry

src/stapi_fastapi/routers/root_router.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,10 @@ def get_products(self, request: Request) -> ProductsCollection:
159159
],
160160
)
161161

162-
async def get_orders(self, request: Request) -> OrderCollection:
163-
match await self.backend.get_orders(request):
162+
async def get_orders(
163+
self, request: Request, next_token: str, limit: int
164+
) -> OrderCollection:
165+
match await self.backend.get_orders(request, next_token, limit):
164166
case Success(orders):
165167
for order in orders:
166168
order.links.append(

tests/application.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ class MockRootBackend(RootBackend):
4343
def __init__(self, orders: InMemoryOrderDB) -> None:
4444
self._orders_db: InMemoryOrderDB = orders
4545

46-
async def get_orders(self, request: Request) -> ResultE[OrderCollection]:
46+
async def get_orders(
47+
self, request: Request, next_token: str, limit: int
48+
) -> ResultE[OrderCollection]:
4749
"""
4850
Show all orders.
4951
"""

tests/test_order.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,59 @@ def test_order_status_after_update(
168168
assert s["reason_text"] is None
169169
assert s["status_code"] == "received"
170170
assert s["timestamp"]
171+
172+
173+
@pytest.fixture
174+
def create_second_order_allowed_payloads() -> list[OrderPayload]:
175+
return [
176+
OrderPayload(
177+
geometry=Point(
178+
type="Point", coordinates=Position2D(longitude=14.4, latitude=56.5)
179+
),
180+
datetime=(
181+
datetime.fromisoformat("2024-10-09T18:55:33Z"),
182+
datetime.fromisoformat("2024-10-12T18:55:33Z"),
183+
),
184+
filter=None,
185+
order_parameters=MyOrderParameters(s3_path="s3://my-bucket"),
186+
),
187+
]
188+
189+
190+
@pytest.mark.parametrize("product_id", ["test-spotlight"])
191+
def test_order_pagination(
192+
product_id: str,
193+
product_backend: MockProductBackend,
194+
stapi_client: TestClient,
195+
create_order_allowed_payloads: list[OrderPayload],
196+
create_second_order_allowed_payloads: list[OrderPayload],
197+
) -> None:
198+
product_backend._allowed_payloads = create_order_allowed_payloads
199+
200+
# check empty
201+
res = stapi_client.get("/orders", params={"next_token": "a", "limit": 10})
202+
default_orders = {"type": "FeatureCollection", "features": [], "links": []}
203+
204+
assert res.status_code == status.HTTP_200_OK
205+
assert res.headers["Content-Type"] == "application/geo+json"
206+
assert res.json() == default_orders
207+
208+
# add order to product
209+
res = stapi_client.post(
210+
f"products/{product_id}/orders",
211+
json=create_order_allowed_payloads[0].model_dump(),
212+
)
213+
214+
assert res.status_code == status.HTTP_201_CREATED, res.text
215+
assert res.headers["Content-Type"] == "application/geo+json"
216+
217+
res = stapi_client.post(
218+
f"products/{product_id}/orders",
219+
json=create_second_order_allowed_payloads[0].model_dump(),
220+
)
221+
222+
# call all orders
223+
res = stapi_client.get("/orders", params={"next_token": "a", "limit": 1})
224+
assert res.status_code == status.HTTP_200_OK
225+
assert res.headers["Content-Type"] == "application/geo+json"
226+
print("hold")

0 commit comments

Comments
 (0)