Flask/tests/test_api.py
Simon Diesenreiter 5efd61d236
Some checks failed
CI / linter (ubuntu-latest, 3.9) (push) Failing after 1m29s
Rename the project from template / rename-project (push) Has been skipped
CI / tests_linux (ubuntu-latest, 3.9) (push) Has been skipped
initial commit
2024-11-10 07:27:36 -08:00

29 lines
955 B
Python

from decimal import Decimal
def test_products_get_all(client, products): # Arrange
"""Test get all products"""
# Act
response = client.get("/api/v1/product/")
# Assert
assert response.status_code == 200
data = response.json["products"]
assert len(data) == 3
for product in products:
assert product.id in [item["id"] for item in data]
assert product.name in [item["name"] for item in data]
assert product.price in [Decimal(item["price"]) for item in data]
def test_products_get_one(client, products): # Arrange
"""Test get one product"""
for product in products:
# Act
response = client.get(f"/api/v1/product/{product.id}")
data = response.json
# Assert
assert response.status_code == 200
assert data["name"] == product.name
assert Decimal(data["price"]) == product.price
assert data["description"] == product.description