-
Notifications
You must be signed in to change notification settings - Fork 91
/
test_scoreboard.py
94 lines (81 loc) · 4.49 KB
/
test_scoreboard.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
86
87
88
89
90
91
92
93
94
import requests_mock
import unittest
import json
from espnff.league import (League)
from espnff.exception import (PrivateLeagueException,
InvalidLeagueException,
UnknownLeagueException, )
class ScoreboardTestCase(unittest.TestCase):
'''Test Scoreboard funtion'''
def setUp(self):
self.data = json.loads(open('tests/test_league.json').read())
self.scoreboard_data = json.loads(open('tests/test_scoreboard.json').read())
self.scoreboard_expected = ["Matchup(Team(Team 2), Team(Team 7))", "Matchup(Team(Team 1), Team(Team 11))",
"Matchup(Team(Team 6), Team(Team 9))", "Matchup(Team(Team 12), Team(Team 4))",
"Matchup(Team(Team 10), Team(Team 3))", "Matchup(Team(Team 8), Team(Team 5))"]
@requests_mock.Mocker()
def test_public_scoreboard(self, m):
'''Is the status code 200 when calling a public league?'''
m.get('http://games.espn.com/ffl/api/v2/leagueSettings?leagueId=1234&seasonId=2016',
status_code=200, json=self.data)
m.get('http://games.espn.com/ffl/api/v2/scoreboard?leagueId=1234&seasonId=2016',
status_code=200, json=self.scoreboard_data)
league = League(1234, 2016)
league.scoreboard()
self.assertEqual(league.status, 200)
@requests_mock.Mocker()
def test_private_scoreboard(self, m):
'''Does the correct exception raise when the status code is 401?'''
scoreboard_error = {"error": [{"message": "No permission to view this league", "code": "functional"}]}
m.get('http://games.espn.com/ffl/api/v2/leagueSettings?leagueId=1234&seasonId=2016',
status_code=200, json=self.data)
m.get('http://games.espn.com/ffl/api/v2/scoreboard?leagueId=1234&seasonId=2016',
status_code=401, json=scoreboard_error)
with self.assertRaises(PrivateLeagueException):
league = League(1234, 2016)
league.scoreboard()
@requests_mock.Mocker()
def test_invalid_scoreboard(self, m):
'''Does the correct exception raise when the status code is 404?'''
scoreboard_error = {"error": [{"message": "Unable to retrieve league (2016:1234)", "code": "functional"}]}
m.get('http://games.espn.com/ffl/api/v2/leagueSettings?leagueId=1234&seasonId=2016',
status_code=200, json=self.data)
m.get('http://games.espn.com/ffl/api/v2/scoreboard?leagueId=1234&seasonId=2016',
status_code=404, json=scoreboard_error)
with self.assertRaises(InvalidLeagueException):
league = League(1234, 2016)
league.scoreboard()
@requests_mock.Mocker()
def test_unknown_scoreboard(self, m):
'''Does the correct exception raise when the status code is 500?'''
scoreboard_error = {"error": [{"message": "java.lang.NullPointerException", "code": "functional"}]}
m.get('http://games.espn.com/ffl/api/v2/leagueSettings?leagueId=1234&seasonId=2016',
status_code=200, json=self.data)
m.get('http://games.espn.com/ffl/api/v2/scoreboard?leagueId=1234&seasonId=2016',
status_code=500, json=scoreboard_error)
with self.assertRaises(UnknownLeagueException):
league = League(1234, 2016)
league.scoreboard()
@requests_mock.Mocker()
def test_scoreboard_week(self, m):
'''Does the correct url generate from params when a week is entered?'''
m.get('http://games.espn.com/ffl/api/v2/leagueSettings?leagueId=1234&seasonId=2016',
status_code=200, json=self.data)
m.get('http://games.espn.com/ffl/api/v2/scoreboard?leagueId=1234&seasonId=2016&matchupPeriodId=12',
status_code=200, json=self.scoreboard_data)
league = League(1234, 2016)
league.scoreboard(week=12)
self.assertEqual(league.status, 200)
@requests_mock.Mocker()
def test_scoreboard(self, m):
'''Does the correct output return?'''
m.get('http://games.espn.com/ffl/api/v2/leagueSettings?leagueId=1234&seasonId=2016',
status_code=200, json=self.data)
m.get('http://games.espn.com/ffl/api/v2/scoreboard?leagueId=1234&seasonId=2016',
status_code=200, json=self.scoreboard_data)
league = League(1234, 2016)
scoreboard = league.scoreboard()
scoreboard = [str(x) for x in scoreboard]
self.assertEqual(scoreboard, self.scoreboard_expected)
if __name__ == '__main__':
unittest.main()