SAE410_TP2/pytest/test_athletes.py
2024-03-27 17:04:51 +01:00

27 lines
1.2 KiB
Python

import requests
import random
import pytest
def pytest_namespace():
return {'current_id': 0}
def test_add_new_athlete():
test_id = str(random.randint(1000,9999))
x = requests.post('http://localhost/athletes', json={"name": "TEST", "surname": test_id, "email": "test@test.org", "country": "Listenbourg", "isDisabled": True})
pytest.current_id = x.json()['id']
assert x.status_code == 200
def test_get_athlete():
assert requests.get("http://localhost/athletes/"+str(pytest.current_id)).status_code == 200
def test_edit_athlete():
assert requests.patch("http://localhost/athletes/"+str(pytest.current_id), json={"name": "HELLO", "isDisabled": False}).status_code == 200
def test_get_modified_athlete():
x = requests.get("http://localhost/athletes/"+str(pytest.current_id))
json = x.json()['data']
assert x.status_code == 200 and json['name'] == "HELLO" and json['isDisabled'] == False
def test_delete_athlete():
assert requests.delete("http://localhost/athletes/"+str(pytest.current_id)).status_code == 200
def test_deleted_athlete():
assert requests.get("http://localhost/athletes/"+str(pytest.current_id)).status_code == 404
def test_add_fake_athlete():
requests.post('http://localhost/athletes', json={"PEBCAK": True}).status_code == 400