-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_heroes.py
More file actions
49 lines (32 loc) · 980 Bytes
/
test_heroes.py
File metadata and controls
49 lines (32 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import requests
import json
import time
from requests import Response
BASE_URL = "http://127.0.0.1:8000"
def get_response(url: str) -> Response:
start_time = time.time()
url = BASE_URL + url
print("")
print(f"{url}:")
response = requests.get(url)
print(json.dumps(response.json(), indent=4))
elapsed = time.time() - start_time
print(f"Elapsed: {elapsed:.2f} sec.")
return response
def test_get_heroes():
response = get_response("/heroes/")
assert response.status_code == 200
def test_get_hero(id: int = 1):
response = get_response(f"/hero/{id}")
assert response.status_code == 200
def test_get_teams():
response = get_response("/teams/")
assert response.status_code == 200
def test_get_team(id: int = 1):
response = get_response(f"/team/{id}")
assert response.status_code == 200
if __name__ == "__main__":
test_get_heroes()
test_get_hero(2)
test_get_teams()
test_get_team(2)