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