This repository was archived by the owner on Apr 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtest_opportunity.py
More file actions
62 lines (50 loc) · 1.69 KB
/
test_opportunity.py
File metadata and controls
62 lines (50 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import pytest
from fastapi.testclient import TestClient
from stapi_fastapi.models.opportunity import (
OpportunityCollection,
)
from .shared import create_mock_opportunity, pagination_tester
def test_search_opportunities_response(
stapi_client: TestClient, assert_link, opportunity_search
) -> None:
product_id = "test-spotlight"
url = f"/products/{product_id}/opportunities"
response = stapi_client.post(url, json=opportunity_search)
assert response.status_code == 200, f"Failed for product: {product_id}"
body = response.json()
# Validate the opportunity was returned
assert len(body["features"]) == 1
try:
_ = OpportunityCollection(**body)
except Exception as _:
pytest.fail("response is not an opportunity collection")
assert_link(
f"POST {url}",
body,
"create-order",
f"/products/{product_id}/orders",
method="POST",
)
@pytest.mark.parametrize("limit", [0, 1, 2, 4])
def test_search_opportunities_pagination(
limit: int,
stapi_client: TestClient,
opportunity_search,
) -> None:
mock_pagination_opportunities = [create_mock_opportunity() for __ in range(3)]
stapi_client.app_state["_opportunities"] = mock_pagination_opportunities
product_id = "test-spotlight"
expected_returns = []
if limit != 0:
expected_returns = [
x.model_dump(mode="json") for x in mock_pagination_opportunities
]
pagination_tester(
stapi_client=stapi_client,
url=f"/products/{product_id}/opportunities",
method="POST",
limit=limit,
target="features",
expected_returns=expected_returns,
body=opportunity_search,
)