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

Commit 0dcf05b

Browse files
feat: applying new Orders class and test is breaking in the expected, desired way
1 parent 152a227 commit 0dcf05b

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

src/stapi_fastapi/backends/root_backend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from stapi_fastapi.models.order import (
88
Order,
9-
OrderCollection,
9+
Orders,
1010
OrderStatus,
1111
OrderStatusPayload,
1212
)
@@ -15,7 +15,7 @@
1515
class RootBackend[T: OrderStatusPayload, U: OrderStatus](Protocol): # pragma: nocover
1616
async def get_orders(
1717
self, request: Request, next_token: str, limit: int
18-
) -> ResultE[OrderCollection]:
18+
) -> ResultE[Orders]:
1919
"""
2020
Return a list of existing orders.
2121
"""

src/stapi_fastapi/routers/root_router.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ async def get_orders(
164164
) -> OrderCollection:
165165
match await self.backend.get_orders(request, next_token, limit):
166166
case Success(orders):
167-
for order in orders:
167+
for order in orders.collection:
168168
order.links.append(
169169
Link(
170170
href=str(
@@ -176,7 +176,7 @@ async def get_orders(
176176
type=TYPE_JSON,
177177
)
178178
)
179-
return orders
179+
return orders.collection
180180
case Failure(e):
181181
logging.exception("An error occurred while retrieving orders", e)
182182
raise HTTPException(

tests/application.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
OrderCollection,
2222
OrderParameters,
2323
OrderPayload,
24+
Orders,
2425
OrderStatus,
2526
OrderStatusCode,
2627
OrderStatusPayload,
@@ -45,11 +46,18 @@ def __init__(self, orders: InMemoryOrderDB) -> None:
4546

4647
async def get_orders(
4748
self, request: Request, next_token: str, limit: int
48-
) -> ResultE[OrderCollection]:
49+
) -> ResultE[Orders]:
4950
"""
5051
Show all orders.
5152
"""
52-
return Success(OrderCollection(features=list(self._orders_db._orders.values())))
53+
return Success(
54+
Orders(
55+
collection=OrderCollection(
56+
features=list(self._orders_db._orders.values())
57+
),
58+
token="a",
59+
)
60+
)
5361

5462
async def get_order(self, order_id: str, request: Request) -> ResultE[Maybe[Order]]:
5563
"""

tests/test_order.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def test_order_pagination(
198198
product_backend._allowed_payloads = create_order_allowed_payloads
199199

200200
# check empty
201-
res = stapi_client.get("/orders", params={"next_token": "a", "limit": 10})
201+
res = stapi_client.get("/orders", params={"next_token": "a", "limit": 1})
202202
default_orders = {"type": "FeatureCollection", "features": [], "links": []}
203203

204204
assert res.status_code == status.HTTP_200_OK
@@ -221,6 +221,8 @@ def test_order_pagination(
221221

222222
# call all orders
223223
res = stapi_client.get("/orders", params={"next_token": "a", "limit": 1})
224+
checker = res.json()
225+
224226
assert res.status_code == status.HTTP_200_OK
225-
assert res.headers["Content-Type"] == "application/geo+json"
226-
print("hold")
227+
assert len(checker["features"]) == 1
228+
assert checker["links"] != []

0 commit comments

Comments
 (0)