38 lines
989 B
Python
38 lines
989 B
Python
from fastapi.testclient import TestClient
|
|
from pydantic import HttpUrl
|
|
import validators
|
|
|
|
from src.main import app
|
|
from src.classes import product_classes
|
|
from shop_validators import image_validator
|
|
|
|
client = TestClient(app)
|
|
|
|
def default_product_test(product: product_classes.Product):
|
|
assert type(product.name) == str
|
|
assert type(product.price) == float
|
|
assert type(product.image_filename) == str
|
|
|
|
|
|
|
|
def test_read_main():
|
|
response = client.get("/")
|
|
assert response.status_code == 200
|
|
assert response.json() == {"Hello": "World"}
|
|
|
|
|
|
def test_retrieve_products():
|
|
response = client.get("/products")
|
|
assert response.status_code == 200
|
|
|
|
returned_product = product_classes.Product(**response.json()[0])
|
|
|
|
default_product_test(returned_product)
|
|
|
|
def test_retrieve_icon():
|
|
response = client.get("/icons/cart")
|
|
assert response.status_code == 200
|
|
|
|
returned_icon = response.text
|
|
|
|
assert image_validator.is_valid_svg(file_content=returned_icon)
|