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

Commit b690cf1

Browse files
feat: tweaking mock backend to use list index look up and return empty features after token lookup tests: separating empty orders check to separate test
1 parent 5db53c1 commit b690cf1

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

src/stapi_fastapi/routers/root_router.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ async def get_orders(
184184
return collections
185185
case Failure(e):
186186
logging.exception(f"An error occurred while retrieving orders: {e}")
187-
if isinstance(e, IndexError):
187+
if isinstance(e, ValueError):
188188
raise NotFoundException(detail="Error finding pagination token")
189189
else:
190190
raise HTTPException(

tests/application.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,12 @@ async def get_orders(
5555
limit = 100
5656

5757
order_ids = [*self._orders_db._orders.keys()]
58-
if not order_ids and not next: # no data in db
59-
return Success(
60-
(
61-
OrderCollection(
62-
features=list(self._orders_db._orders.values())
63-
),
64-
"",
65-
)
66-
)
6758

6859
if next:
69-
start = [i for i, x in enumerate(order_ids) if x == next][0]
60+
start = order_ids.index(next)
61+
if not order_ids and not next: # no data in db
62+
return Success((OrderCollection(features=[]), ""))
63+
7064
end = start + limit
7165
ids = order_ids[start:end]
7266
feats = [self._orders_db._orders[order_id] for order_id in ids]

tests/test_order.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,19 +194,19 @@ def create_order_payloads() -> list[OrderPayload]:
194194
return payloads
195195

196196

197-
@pytest.fixture
198-
def prepare_order_pagination(
199-
stapi_client: TestClient, create_order_payloads: list[OrderPayload]
200-
) -> None:
201-
product_id = "test-spotlight"
202-
203-
# check empty
197+
def test_empty_order(stapi_client: TestClient):
204198
res = stapi_client.get("/orders")
205199
default_orders = {"type": "FeatureCollection", "features": [], "links": []}
206200
assert res.status_code == status.HTTP_200_OK
207201
assert res.headers["Content-Type"] == "application/geo+json"
208202
assert res.json() == default_orders
209203

204+
205+
@pytest.fixture
206+
def prepare_order_pagination(
207+
stapi_client: TestClient, create_order_payloads: list[OrderPayload]
208+
) -> None:
209+
product_id = "test-spotlight"
210210
# get uuids created to use as pagination tokens
211211
for payload in create_order_payloads:
212212
res = stapi_client.post(

0 commit comments

Comments
 (0)