64 lines
1.7 KiB
Python
Executable file
64 lines
1.7 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
import requests
|
|
import json
|
|
|
|
HOST = "http://localhost:5000"
|
|
|
|
# Get root
|
|
assert 200 == requests.get(HOST + "/").status_code
|
|
|
|
# Get list of athletes as a json object
|
|
get_root = requests.get(HOST + "/athlete").text
|
|
if get_root != "[]\n":
|
|
assert json.loads(get_root)
|
|
|
|
# Post on '/athlete' With no data
|
|
assert 400 == requests.post(HOST + "/athlete").status_code
|
|
|
|
# Post on '/athlete' with uncorrect body
|
|
assert 400 == requests.post(
|
|
HOST + "/athlete", json={"should": "fail"}).status_code
|
|
|
|
|
|
# Post on '/athlete' with correct body
|
|
post_request = requests.post(HOST + "/athlete", json={"name": "test", "surname": "tests",
|
|
"email": "test.test@test.co", "country": "fr", "isDisabled": True})
|
|
assert 200 == post_request.status_code
|
|
id = json.loads(post_request.text)['id']
|
|
|
|
# Get newly created object
|
|
expected_result = f"""{{
|
|
"country": "fr",
|
|
"email": "test.test@test.co",
|
|
"id": {id},
|
|
"isDisabled": true,
|
|
"name": "test",
|
|
"surname": "tests"
|
|
}}
|
|
"""
|
|
assert expected_result == requests.get(HOST + f"/athlete/{id}").text
|
|
|
|
assert 400 == requests.patch(
|
|
HOST + f"/athlete/{id}", json={"should": "fail"}).status_code
|
|
|
|
# Test to patch object
|
|
assert 200 == requests.patch(
|
|
HOST + f"/athlete/{id}", json={"name": "modify"}).status_code
|
|
|
|
expected_result = f"""{{
|
|
"country": "fr",
|
|
"email": "test.test@test.co",
|
|
"id": {id},
|
|
"isDisabled": true,
|
|
"name": "modify",
|
|
"surname": "tests"
|
|
}}
|
|
"""
|
|
assert expected_result == requests.get(HOST + f"/athlete/{id}").text
|
|
|
|
# test delete methode on the newly created athlete
|
|
|
|
assert 200 == requests.delete(HOST + f"/athlete/{id}").status_code
|
|
|
|
# verify that the object don't exist anymore
|
|
assert 404 == requests.get(HOST + f"/athlete/{id}").status_code
|