-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_api.py
85 lines (71 loc) · 2.33 KB
/
test_api.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import requests
import json
from _player_vs_opp_database import _player_vs_opp_database
db = _player_vs_opp_database()
db.load_players("data/players.json")
db.load_teams("data/teams.json")
print ("Testing GET player id...")
try:
if db.get_player_id("Alex Abrines") != 203518:
print ("GET Player ID Failed")
else:
print ("GET Player ID Passed")
except:
print ("GET Player ID Failed")
print ("\nTesting GET team id...")
try:
team_id = db.get_team_id("Boston Celtics")
if team_id != 1610612738:
print ("GET Team ID Failed")
else:
print ("GET Team ID Passed")
except:
print ("GET Team ID Failed")
#### TEST FOR PLAYER GET ####
print ("\nTesting GET Players...")
try:
r = requests.get('http://student04.cse.nd.edu:51033/players/')
resp = json.loads(r.content.decode('utf-8'))
if resp['result'] == 'success' and resp['players']:
print ("GET Players Passed")
else:
print ("GET Players Failed")
except:
print ("GET Players Failed")
#### TESTS FOR TEAMS GET ####
print ("\nTesting GET Teams...")
try:
r = requests.get('http://student04.cse.nd.edu:51033/teams/')
resp = json.loads(r.content.decode('utf-8'))
if resp['result'] == 'success' and resp['teams']:
print ("GET Teams Passed")
else:
print ("GET Teams Failed")
except:
print ("GET Teams Failed")
#### TESTS FOR PVO POST ####
print ("\nTesting POST PlayerVsOpponent...")
try:
pId = db.get_player_id("Kyrie Irving")
tId = db.get_team_id("Cleveland Cavaliers")
data = {"pId":pId, "tId" : tId}
r = requests.post('http://student04.cse.nd.edu:51033/pvo/', data = json.dumps(data))
resp = json.loads(r.content.decode('utf-8'))
if resp['result'] == 'success' and resp['id']:
print ("POST PlayerVsOpponent Passed")
else:
print ("POST PlayerVsOpponent Failed")
except:
print ("POST PlayerVsOpponent Failed")
#### TESTS FOR PVO GET ####
print ("\nTesting GET PlayerVsOpponent...")
try:
r = requests.get('http://student04.cse.nd.edu:51033/pvo/{}{}'.format(pId, tId))
resp = json.loads(r.content.decode('utf-8'))
if resp['result'] == 'success' and resp['data']:
print ("GET PlayerVsOpponent Passed")
else:
print ("GET PlayerVsOpponent Failed")
except Exception as e:
print (str(e))
print ("GET PlayerVsOpponent Failed")