kenken999's picture
teste
b1ce64c
raw
history blame
1.1 kB
from fastapi.testclient import TestClient
from main import app
client = TestClient(app)
def test_create_user():
response = client.post("/users/", json={"username": "john", "email": "john@example.com"})
assert response.status_code == 200
assert response.json() == {"message": "User created successfully"}
def test_read_users():
response = client.get("/users/")
assert response.status_code == 200
assert len(response.json()) > 0
def test_read_user():
response = client.get("/users/1")
assert response.status_code == 200
assert response.json()["id"] == 1
def test_create_product():
response = client.post("/products/", json={"name": "Product 1", "price": 10.99})
assert response.status_code == 200
assert response.json() == {"message": "Product created successfully"}
def test_read_products():
response = client.get("/products/")
assert response.status_code == 200
assert len(response.json()) > 0
def test_read_product():
response = client.get("/products/1")
assert response.status_code == 200
assert response.json()["id"] == 1