mirror of
https://github.com/Anrab35/SAE410_TP2.git
synced 2024-10-21 21:26:09 +02:00
27 lines
No EOL
1.1 KiB
Python
27 lines
No EOL
1.1 KiB
Python
import requests
|
|
import random
|
|
import pytest
|
|
|
|
|
|
def pytest_namespace():
|
|
return {'current_id': 0}
|
|
|
|
def test_add_new_medal():
|
|
test_id = random.randint(1000,9999)
|
|
x = requests.post('http://localhost/medals', json={"rank": "gold", "sportID": test_id, "athleteID": 1})
|
|
pytest.current_id = x.json()['id']
|
|
assert x.status_code == 200
|
|
def test_get_medal():
|
|
assert requests.get("http://localhost/medals/"+str(pytest.current_id)).status_code == 200
|
|
def test_edit_medal():
|
|
assert requests.patch("http://localhost/medals/"+str(pytest.current_id), json={"athleteID": 88}).status_code == 200
|
|
def test_get_modified_medal():
|
|
x = requests.get("http://localhost/medals/"+str(pytest.current_id))
|
|
json = x.json()['data']
|
|
assert x.status_code == 200 and json['rank'] == "gold" and json['athleteID'] == 88
|
|
def test_delete_medal():
|
|
assert requests.delete("http://localhost/medals/"+str(pytest.current_id)).status_code == 200
|
|
def test_deleted_medal():
|
|
assert requests.get("http://localhost/medals/"+str(pytest.current_id)).status_code == 404
|
|
def test_add_fake_medal():
|
|
requests.post('http://localhost/medals', json={"rank": "Loris"}).status_code == 400 |