TP_JO2024/medaille/tests/test_postMedaille.py
2024-03-27 15:20:10 +01:00

30 lines
787 B
Python

from models import Medaille
def test_postMedaille(client):
medaille = Medaille(
id=1,
type="Argent",
sport="Escrime",
categorie="Fleuret",
pays="Italie"
)
response = client.post("/", json=medaille.model_dump())
assert response.status_code == 200
medaille.id = response.json["id"]
response = client.get(f"/{medaille.id}")
assert response.json == medaille.model_dump()
def test_postMedaille_erreur(client):
medaille = Medaille(
id=1,
type="NexistePas",
sport="Escrime",
categorie="Fleuret",
pays="Italie"
)
response = client.post("/", json=medaille.model_dump())
assert response.status_code == 400
assert response.json == {'message': 'Données invalides'}