Added first tests
This commit is contained in:
parent
e36ac912de
commit
c1bfb7c9bb
2 changed files with 29 additions and 0 deletions
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
29
tests/test_main.py
Normal file
29
tests/test_main.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
from fastapi.testclient import TestClient
|
||||
from pydantic import HttpUrl
|
||||
import validators
|
||||
|
||||
from src.main import app
|
||||
from src.classes import product_classes
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
def default_product_test(product: product_classes.Product):
|
||||
assert type(product.name) == str
|
||||
assert type(product.price) == float
|
||||
assert validators.url(str(product.image_url))
|
||||
|
||||
|
||||
|
||||
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)
|
||||
Loading…
Reference in a new issue