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_product.py
More file actions
136 lines (112 loc) · 4.29 KB
/
test_product.py
File metadata and controls
136 lines (112 loc) · 4.29 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import pytest
from fastapi import status
from fastapi.testclient import TestClient
from stapi_fastapi.models.product import Product
from .shared import pagination_tester
def test_products_response(stapi_client: TestClient):
res = stapi_client.get("/products")
assert res.status_code == status.HTTP_200_OK
assert res.headers["Content-Type"] == "application/json"
data = res.json()
assert data["type"] == "ProductCollection"
assert isinstance(data["products"], list)
@pytest.mark.parametrize("product_id", ["test-spotlight"])
def test_product_response_self_link(
product_id: str,
stapi_client: TestClient,
assert_link,
):
res = stapi_client.get(f"/products/{product_id}")
assert res.status_code == status.HTTP_200_OK
assert res.headers["Content-Type"] == "application/json"
body = res.json()
url = "GET /products"
assert_link(url, body, "self", f"/products/{product_id}")
assert_link(url, body, "constraints", f"/products/{product_id}/constraints")
assert_link(
url, body, "order-parameters", f"/products/{product_id}/order-parameters"
)
assert_link(url, body, "opportunities", f"/products/{product_id}/opportunities")
assert_link(
url, body, "create-order", f"/products/{product_id}/orders", method="POST"
)
@pytest.mark.parametrize("product_id", ["test-spotlight"])
def test_product_constraints_response(
product_id: str,
stapi_client: TestClient,
):
res = stapi_client.get(f"/products/{product_id}/constraints")
assert res.status_code == status.HTTP_200_OK
assert res.headers["Content-Type"] == "application/json"
json_schema = res.json()
assert "properties" in json_schema
assert "off_nadir" in json_schema["properties"]
@pytest.mark.parametrize("product_id", ["test-spotlight"])
def test_product_order_parameters_response(
product_id: str,
stapi_client: TestClient,
):
res = stapi_client.get(f"/products/{product_id}/order-parameters")
assert res.status_code == status.HTTP_200_OK
assert res.headers["Content-Type"] == "application/json"
json_schema = res.json()
assert "properties" in json_schema
assert "s3_path" in json_schema["properties"]
@pytest.mark.parametrize("limit", [0, 1, 2, 4])
def test_get_products_pagination(
limit: int,
stapi_client: TestClient,
mock_products: list[Product],
):
expected_returns = []
if limit != 0:
for product in mock_products:
prod = product.model_dump(mode="json", by_alias=True)
product_id = prod["id"]
prod["links"] = [
{
"href": f"http://stapiserver/products/{product_id}",
"rel": "self",
"type": "application/json",
},
{
"href": f"http://stapiserver/products/{product_id}/constraints",
"rel": "constraints",
"type": "application/json",
},
{
"href": f"http://stapiserver/products/{product_id}/order-parameters",
"rel": "order-parameters",
"type": "application/json",
},
{
"href": f"http://stapiserver/products/{product_id}/orders",
"rel": "create-order",
"type": "application/json",
"method": "POST",
},
{
"href": f"http://stapiserver/products/{product_id}/opportunities",
"rel": "opportunities",
"type": "application/json",
},
]
expected_returns.append(prod)
pagination_tester(
stapi_client=stapi_client,
url="/products",
method="GET",
limit=limit,
target="products",
expected_returns=expected_returns,
)
def test_token_not_found(stapi_client: TestClient) -> None:
res = stapi_client.get("/products", params={"next": "a_token"})
assert res.status_code == status.HTTP_404_NOT_FOUND
@pytest.mark.mock_products([])
def test_no_products(stapi_client: TestClient):
res = stapi_client.get("/products")
body = res.json()
print("hold")
assert res.status_code == status.HTTP_200_OK
assert len(body["products"]) == 0