import requests import random import pytest def pytest_namespace(): return {'current_id': 0} def test_add_new_sport(): test_id = str(random.randint(1000,9999)) x = requests.post('http://localhost/sports', json={"name": "TEST", "place": test_id, "category": "Multiplayer"}) pytest.current_id = x.json()['id'] assert x.status_code == 200 def test_get_sport(): print("http://localhost/sports/"+str(pytest.current_id)) assert requests.get("http://localhost/sports/"+str(pytest.current_id)).status_code == 200 def test_edit_sport(): assert requests.patch("http://localhost/sports/"+str(pytest.current_id), json={"category": "Aquatic"}).status_code == 200 def test_get_modified_sport(): x = requests.get("http://localhost/sports/"+str(pytest.current_id)) json = x.json()['data'] assert x.status_code == 200 and json['category'] == "Aquatic" def test_delete_sport(): assert requests.delete("http://localhost/sports/"+str(pytest.current_id)).status_code == 200 def test_deleted_sport(): assert requests.get("http://localhost/sports/"+str(pytest.current_id)).status_code == 404 def test_add_fake_sport(): requests.post('http://localhost/sports', json={"rank": "gold", "sportID": 666, "athleteID": 1}).status_code == 400