def testLeagueId(self):
        """Test league id parameter"""
        mocker = MockLeague(self)

        # invalid league id
        rv = self.app.post(Routes['vteam'], json={'league_id': INVALID_ID})
        expect = {}
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(expect, loads(rv.data),
                         Routes['vteam'] + " Post: invalid league id")

        # valid league id
        league_id = mocker.get_league()['league_id']
        team = mocker.get_teams()[0]
        team_id = team['team_id']
        rv = self.app.post(Routes['vteam'], json={'league_id': league_id})
        expect = {'games': 1,
                  'hits_allowed': 3,
                  'hits_for': 2,
                  'losses': 1,
                  'name': team['team_name'],
                  'runs_against': 6,
                  'runs_for': 1,
                  'ties': 0,
                  'wins': 0,
                  'espys': 0}
        self.output(loads(rv.data))
        self.output(expect)
        self.assertTrue(len(loads(rv.data).keys()) > 0,
                        Routes['vteam'] + " Post: valid year")
        self.assertEqual(expect,
                         loads(rv.data)[str(team_id)],
                         Routes['vteam'] + " Post: valid year")
Exemplo n.º 2
0
    def testPostLeagueId(self):
        mocker = MockLeague(self)

        # test an invalid league id
        rv = self.app.post(Routes['vplayer'], data={'league_id': INVALID_ID})
        expect = {}
        self.output(expect)
        self.output(loads(rv.data))
        self.assertEqual(expect,
                         loads(rv.data),
                         Routes['vplayer'] + " Post: invalid league id")

        # test an valid league id
        league_id = mocker.get_league()['league_id']
        expect = {'avg': 0.5,
                  'bats': 2,
                  'd': 0,
                  'e': 0,
                  'fc': 0,
                  'fo': 0,
                  'go': 0,
                  'hr': 1,
                  'id': mocker.get_players()[0]['player_id'],
                  'k': 1,
                  'rbi': 2,
                  's': 0,
                  'ss': 0}
        player_check = mocker.get_players()[0]
        rv = self.app.post(Routes['vplayer'], data={"league_id": league_id})
        self.output(loads(rv.data))
        self.assertTrue(len(loads(rv.data).keys()) == 4,
                        Routes['vplayer'] + " Post: valid league id")
        self.assertEqual(loads(rv.data)[player_check['player_name']],
                         expect,
                         Routes['vplayer'] + " Post: valid league id")
    def testEspysParameter(self):
        """Test that the espys are properly being calculated"""
        mocker = MockLeague(self)

        # add an espys to the team
        self.add_espys(mocker.get_teams()[0],
                       mocker.get_sponsor(),
                       points=1)

        # valid league id
        league_id = mocker.get_league()['league_id']
        team = mocker.get_teams()[0]
        team_id = team['team_id']
        rv = self.app.post(Routes['vteam'], json={'league_id': league_id})
        expect = {'games': 1,
                  'hits_allowed': 3,
                  'hits_for': 2,
                  'losses': 1,
                  'name': team['team_name'],
                  'runs_against': 6,
                  'runs_for': 1,
                  'ties': 0,
                  'wins': 0,
                  'espys': 1}
        self.output(loads(rv.data))
        self.output(expect)
        self.assertTrue(len(loads(rv.data).keys()) > 0,
                        Routes['vteam'] + " Post: valid year")
        self.assertEqual(expect,
                         loads(rv.data)[str(team_id)],
                         Routes['vteam'] + " Post: valid year")
Exemplo n.º 4
0
    def testPostGameId(self):
        """Test game id parameter"""
        # test an invalid league id
        mocker = MockLeague(self)
        rv = self.app.post(Routes['vgame'], data={"game_id": INVALID_ID})
        expect = []
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(expect, loads(rv.data),
                         Routes['vgame'] + " Post: invalid game id")

        # test a valid league id
        data = {"game_id": mocker.get_games()[0]['game_id']}
        rv = self.app.post(Routes['vgame'], data=data)
        games_data = loads(rv.data)
        game_data = games_data[0]
        expect = 1
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(expect, len(games_data))
        self.assertEqual(6, game_data['away_score'])
        self.assertEqual(4, len(game_data['away_bats']))
        self.assertEqual(1, game_data['home_score'])
        self.assertEqual(4, len(game_data['home_bats']))
        self.assertLeagueModelEqual(mocker.get_league(), game_data['league'])
    def testPlayerName(self):
        """Tests using a player name as a parameter"""
        mocker = MockLeague(self)
        league = mocker.get_league()
        team = mocker.get_teams()[0]
        player = mocker.get_players()[0]
        sponsor = mocker.get_sponsor()

        # test a test player names
        params = {'player_name': player['player_name']}
        rv = self.app.post(Routes['vplayerteamLookup'], json=params)
        expect = [{
            'captain': player,
            'color': team['color'],
            'espys': 0,
            'league_id': league['league_id'],
            'sponsor_id': sponsor['sponsor_id'],
            'team_id': team['team_id'],
            'team_name': team['team_name'],
            'year': team['year']
        }]
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(expect, loads(rv.data), Routes['vplayerteamLookup'])

        # test a test player names
        params = {'player_name': "Not a player"}
        rv = self.app.post(Routes['vplayerteamLookup'], json=params)
        expect = []
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(expect, loads(rv.data), Routes['vplayerteamLookup'])
 def testGetLeagueExists(self):
     """Test a get request for a league that exists"""
     mocker = MockLeague(self)
     league = mocker.get_league()
     league_id = league['league_id']
     result = self.app.get(f"{MAIN_ROUTE}/{VALID_YEAR}/{league_id}")
     expect = [mocker.get_division()]
     self.output(loads(result.data))
     self.output(expect)
     self.assertEqual(expect, loads(result.data),
                      f"{MAIN_ROUTE}: GET league that exists but no games")
 def testGetLeagueDoesExistsNoGames(self):
     """Test a get request for a league that exist but invalid year"""
     mocker = MockLeague(self)
     league = mocker.get_league()
     league_id = league['league_id']
     result = self.app.get(f"{MAIN_ROUTE}/{INVALID_YEAR}/{league_id}")
     expect = []
     self.output(loads(result.data))
     self.output(expect)
     self.assertEqual(expect, loads(result.data),
                      f"{MAIN_ROUTE}: GET league that exists but no games")
Exemplo n.º 8
0
    def testPostLeagueId(self):
        """Test league id parameter"""
        # test an invalid league id
        mocker = MockLeague(self)
        rv = self.app.post(Routes['vgame'], data={"league_id": INVALID_ID})
        expect = []
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(expect, loads(rv.data),
                         Routes['vgame'] + " Post: invalid league id")

        # test a valid league id
        data = {"league_id": mocker.get_league()['league_id']}
        rv = self.app.post(Routes['vgame'], data=data)
        expect = 3
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(expect, len(loads(rv.data)),
                         Routes['vgame'] + " Post: valid league id")
Exemplo n.º 9
0
    def testGet(self):
        # empty get
        rv = self.app.get(Routes['team_roster'] + "/" + str(INVALID_ID))
        expect = {'details': INVALID_ID, 'message': TeamDoesNotExist.message}
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(expect, loads(rv.data),
                         Routes['team_roster'] + " GET: team DNE")
        self.assertEqual(TeamDoesNotExist.status_code, rv.status_code,
                         Routes['team_roster'] + " GET: team DNE")

        # add some teams
        mocker = MockLeague(self)
        team = mocker.get_teams()[0]
        team_id = team['team_id']
        captain = mocker.get_players()[0]
        player = mocker.get_players()[1]
        league = mocker.get_league()

        # get one team
        rv = self.app.get(Routes['team_roster'] + "/" + str(team_id))
        expect = {
            'captain': captain,
            'color': team['color'],
            'espys': 0,
            'league_id': league['league_id'],
            'players': [captain, player],
            'sponsor_id': team['sponsor_id'],
            'team_id': team['team_id'],
            'team_name': team['team_name'],
            'year': date.today().year
        }
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(expect, loads(rv.data),
                         Routes['team_roster'] + " GET: on non-empty set")