-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproduct_test.py
44 lines (31 loc) · 1.21 KB
/
product_test.py
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
from warnings import warn
from fastapi import status
from fastapi.testclient import TestClient
from stapi_fastapi.models.product import Product
from stapi_fastapi_test_backend.backend import TestBackend
from .utils import find_link
from .warnings import StapiSpecWarning
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)
def test_product_response_self_link(
products: list[Product],
stapi_backend: TestBackend,
stapi_client: TestClient,
url_for,
):
stapi_backend._products = products
res = stapi_client.get("/products/mock:standard")
assert res.status_code == status.HTTP_200_OK
assert res.headers["Content-Type"] == "application/json"
data = res.json()
link = find_link(data["links"], "self")
if link is None:
warn(StapiSpecWarning("GET /products Link[rel=self] should exist"))
else:
assert link["type"] == "application/json"
assert link["href"] == url_for("/products/mock:standard")