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

Commit f1e3086

Browse files
committed
tests: Add a custom marker for supplying mock products
1 parent b775a1e commit f1e3086

File tree

4 files changed

+21
-40
lines changed

4 files changed

+21
-40
lines changed

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ filterwarnings = [
6969
"ignore:The 'app' shortcut is now deprecated.:DeprecationWarning",
7070
"ignore:Pydantic serializer warnings:UserWarning",
7171
]
72+
markers = [
73+
"mock_products",
74+
]
7275

7376
[build-system]
7477
requires = [

tests/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ def base_url() -> Iterator[str]:
4141

4242

4343
@pytest.fixture
44-
def mock_products() -> list[Product]:
44+
def mock_products(request) -> list[Product]:
45+
if request.node.get_closest_marker("mock_products") is not None:
46+
return request.node.get_closest_marker("mock_products").args[0]
4547
return [
4648
product_test_spotlight_sync_opportunity,
4749
product_test_satellite_provider_sync_opportunity,

tests/test_opportunity_async.py

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
OpportunitySearchStatus,
1313
OpportunitySearchStatusCode,
1414
)
15-
from stapi_fastapi.models.product import Product
1615
from stapi_fastapi.models.shared import Link
1716

1817
from .shared import (
@@ -27,10 +26,8 @@
2726
from .test_datetime_interval import rfc3339_strftime
2827

2928

30-
@pytest.mark.parametrize("mock_products", [[product_test_spotlight]])
31-
def test_no_opportunity_search_advertised(
32-
stapi_client: TestClient, mock_products: list[Product]
33-
) -> None:
29+
@pytest.mark.mock_products([product_test_spotlight])
30+
def test_no_opportunity_search_advertised(stapi_client: TestClient) -> None:
3431
product_id = "test-spotlight"
3532

3633
# the `/products/{productId}/opportunities link should not be advertised on the product
@@ -44,10 +41,8 @@ def test_no_opportunity_search_advertised(
4441
assert find_link(root_body["links"], "opportunity-search-records") is None
4542

4643

47-
@pytest.mark.parametrize("mock_products", [[product_test_spotlight_sync_opportunity]])
48-
def test_only_sync_search_advertised(
49-
stapi_client: TestClient, mock_products: list[Product]
50-
) -> None:
44+
@pytest.mark.mock_products([product_test_spotlight_sync_opportunity])
45+
def test_only_sync_search_advertised(stapi_client: TestClient) -> None:
5146
product_id = "test-spotlight"
5247

5348
# the `/products/{productId}/opportunities link should be advertised on the product
@@ -69,9 +64,7 @@ def test_only_sync_search_advertised(
6964
[product_test_spotlight_sync_async_opportunity],
7065
],
7166
)
72-
def test_async_search_advertised(
73-
stapi_client_async_opportunity: TestClient, mock_products: list[Product]
74-
) -> None:
67+
def test_async_search_advertised(stapi_client_async_opportunity: TestClient) -> None:
7568
product_id = "test-spotlight"
7669

7770
# the `/products/{productId}/opportunities link should be advertised on the product
@@ -85,16 +78,10 @@ def test_async_search_advertised(
8578
assert find_link(root_body["links"], "opportunity-search-records")
8679

8780

88-
def test_sync_search_response() -> None:
89-
# handled in test_opportunity.py
90-
pass
91-
92-
93-
@pytest.mark.parametrize("mock_products", [[product_test_spotlight_async_opportunity]])
81+
@pytest.mark.mock_products([product_test_spotlight_async_opportunity])
9482
def test_async_search_response(
9583
stapi_client_async_opportunity: TestClient,
9684
opportunity_search: dict[str, Any],
97-
mock_products: list[Product],
9885
) -> None:
9986
product_id = "test-spotlight"
10087
url = f"/products/{product_id}/opportunities"
@@ -111,13 +98,10 @@ def test_async_search_response(
11198
assert find_link(body["links"], "self")
11299

113100

114-
@pytest.mark.parametrize(
115-
"mock_products", [[product_test_spotlight_sync_async_opportunity]]
116-
)
101+
@pytest.mark.mock_products([product_test_spotlight_async_opportunity])
117102
def test_async_search_is_default(
118103
stapi_client_async_opportunity: TestClient,
119104
opportunity_search: dict[str, Any],
120-
mock_products: list[Product],
121105
) -> None:
122106
product_id = "test-spotlight"
123107
url = f"/products/{product_id}/opportunities"
@@ -132,13 +116,10 @@ def test_async_search_is_default(
132116
pytest.fail("response is not an opportunity search record")
133117

134118

135-
@pytest.mark.parametrize(
136-
"mock_products", [[product_test_spotlight_sync_async_opportunity]]
137-
)
119+
@pytest.mark.mock_products([product_test_spotlight_sync_async_opportunity])
138120
def test_prefer_header(
139121
stapi_client_async_opportunity: TestClient,
140122
opportunity_search: dict[str, Any],
141-
mock_products: list[Product],
142123
) -> None:
143124
product_id = "test-spotlight"
144125
url = f"/products/{product_id}/opportunities"
@@ -170,11 +151,10 @@ def test_prefer_header(
170151
pytest.fail("response is not an opportunity search record")
171152

172153

173-
@pytest.mark.parametrize("mock_products", [[product_test_spotlight_async_opportunity]])
154+
@pytest.mark.mock_products([product_test_spotlight_async_opportunity])
174155
def test_async_search_record_retrieval(
175156
stapi_client_async_opportunity: TestClient,
176157
opportunity_search: dict[str, Any],
177-
mock_products: list[Product],
178158
) -> None:
179159
# post an async search
180160
product_id = "test-spotlight"
@@ -201,11 +181,10 @@ def test_async_search_record_retrieval(
201181
]
202182

203183

204-
@pytest.mark.parametrize("mock_products", [[product_test_spotlight_async_opportunity]])
184+
@pytest.mark.mock_products([product_test_spotlight_async_opportunity])
205185
def test_async_opportunity_search_to_completion(
206186
stapi_client_async_opportunity: TestClient,
207187
opportunity_search: dict[str, Any],
208-
mock_products: list[Product],
209188
url_for: Callable[[str], str],
210189
) -> None:
211190
# Post a request for an async search
@@ -269,7 +248,7 @@ def test_async_opportunity_search_to_completion(
269248
)
270249

271250
# Verify we can retrieve the OpportunityCollection from the
272-
# OpportunitySearchRecord's `opportunities` link, and the retrieved
251+
# OpportunitySearchRecord's `opportunities` link; verify the retrieved
273252
# OpportunityCollection contains an order link and a link pointing back to the
274253
# OpportunitySearchRecord
275254
opportunities_link = next(
@@ -283,11 +262,10 @@ def test_async_opportunity_search_to_completion(
283262
assert any(x for x in retrieved_collection.links if x.rel == "search-record")
284263

285264

286-
@pytest.mark.parametrize("mock_products", [[product_test_spotlight_async_opportunity]])
265+
@pytest.mark.mock_products([product_test_spotlight_async_opportunity])
287266
def test_new_search_location_header_matches_self_link(
288267
stapi_client_async_opportunity: TestClient,
289268
opportunity_search: dict[str, Any],
290-
mock_products: list[Product],
291269
) -> None:
292270
product_id = "test-spotlight"
293271
url = f"/products/{product_id}/opportunities"
@@ -300,7 +278,7 @@ def test_new_search_location_header_matches_self_link(
300278
assert search_response.headers["Location"] == str(link["href"])
301279

302280

303-
@pytest.mark.parametrize("mock_products", [[product_test_spotlight_async_opportunity]])
281+
@pytest.mark.mock_products([product_test_spotlight_async_opportunity])
304282
def test_bad_ids(stapi_client_async_opportunity: TestClient) -> None:
305283
search_record_id = "bad_id"
306284
res = stapi_client_async_opportunity.get(
@@ -319,7 +297,6 @@ def test_bad_ids(stapi_client_async_opportunity: TestClient) -> None:
319297
@pytest.fixture
320298
def setup_search_record_pagination(
321299
stapi_client_async_opportunity: TestClient,
322-
mock_products: list[Product],
323300
) -> list[dict[str, Any]]:
324301
product_id = "test-spotlight"
325302
search_records = []
@@ -357,10 +334,9 @@ def setup_search_record_pagination(
357334

358335

359336
@pytest.mark.parametrize("limit", [0, 1, 2, 4])
360-
@pytest.mark.parametrize("mock_products", [[product_test_spotlight_async_opportunity]])
337+
@pytest.mark.mock_products([product_test_spotlight_async_opportunity])
361338
def test_get_search_records_pagination(
362339
stapi_client_async_opportunity: TestClient,
363-
mock_products: list[Product],
364340
setup_search_record_pagination: list[dict[str, Any]],
365341
limit: int,
366342
) -> None:

tests/test_product.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def test_token_not_found(stapi_client: TestClient) -> None:
124124
assert res.status_code == status.HTTP_404_NOT_FOUND
125125

126126

127-
@pytest.mark.parametrize("mock_products", [[]])
127+
@pytest.mark.mock_products([])
128128
def test_no_products(stapi_client: TestClient):
129129
res = stapi_client.get("/products")
130130
body = res.json()

0 commit comments

Comments
 (0)