コード例 #1
0
    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")
コード例 #2
0
    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': mocker.get_players()[0]['player_name']}
        rv = self.app.post(Routes['vplayerteamLookup'], data=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
        player_two = mocker.get_players()[3]
        team_two = mocker.get_teams()[1]
        params = {'player_name': "Test Player"}
        rv = self.app.post(Routes['vplayerteamLookup'], data=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']
        }, {
            'captain': player_two,
            'color': team_two['color'],
            'espys': 0,
            'league_id': league['league_id'],
            'sponsor_id': sponsor['sponsor_id'],
            'team_id': team_two['team_id'],
            'team_name': team_two['team_name'],
            'year': team_two['year']
        }]
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(expect, loads(rv.data), Routes['vplayerteamLookup'])
コード例 #3
0
    def testPost(self):
        """Test adding an invalid player to a team"""
        # mock leagues tests a valid post
        mocker = MockLeague(self)
        player_id = mocker.get_players()[0]['player_id']
        team_id = mocker.get_teams()[0]['team_id']

        # invalid update
        params = {"player_id": player_id}
        rv = self.app.post(Routes['team_roster'] + "/" + str(INVALID_ID),
                           data=params,
                           headers=headers)
        expect = {'details': INVALID_ID, 'message': TeamDoesNotExist.message}
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(loads(rv.data), expect,
                         Routes['team_roster'] + " POST: invalid data")
        self.assertEqual(TeamDoesNotExist.status_code, rv.status_code,
                         Routes['team_roster'] + " PUT: invalid data")

        # invalid player
        params = {"player_id": INVALID_ID}
        rv = self.app.post(Routes['team_roster'] + "/" + str(team_id),
                           data=params,
                           headers=headers)
        expect = {'details': INVALID_ID, 'message': PlayerDoesNotExist.message}
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(loads(rv.data), expect,
                         Routes['team_roster'] + " POST: invalid data")
        self.assertEqual(TeamDoesNotExist.status_code, rv.status_code,
                         Routes['team_roster'] + " PUT: invalid data")
コード例 #4
0
    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")
コード例 #5
0
    def testPostYear(self):
        """Test year parameter"""
        mocker = MockLeague(self)

        # invalid year
        rv = self.app.post(Routes['vteam'], data={'year': INVALID_YEAR})
        expect = {}
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(expect, loads(rv.data),
                         Routes['vteam'] + " Post: invalid year")

        # valid year
        team_id = mocker.get_teams()[0]['team_id']
        rv = self.app.post(Routes['vteam'], data={'year': VALID_YEAR})
        expect = {'games': 1,
                  'hits_allowed': 3,
                  'hits_for': 2,
                  'losses': 1,
                  'name': 'Advanced Test Sponsor Test Team',
                  'runs_against': 6,
                  'runs_for': 1,
                  'ties': 0,
                  'wins': 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")
コード例 #6
0
    def testPostTeamId(self):
        mocker = MockLeague(self)

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

        # test an valid team id
        team_id = mocker.get_teams()[0]['team_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'], json={"team_id": team_id})
        self.output(loads(rv.data))
        self.assertTrue(
            len(loads(rv.data).keys()) == 2,
            Routes['vplayer'] + " Post: valid team id")
        self.assertEqual(
            loads(rv.data)[player_check['player_name']], expect,
            Routes['vplayer'] + " Post: valid team id")
        absent_player_name = mocker.get_players()[2]['player_name']
        player_present = absent_player_name in loads(rv.data).keys()
        self.assertTrue(not player_present,
                        Routes['vplayer'] + " Post: valid team id")
コード例 #7
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")
    def testEmail(self):
        """Tests using a player email 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 emails
        params = {'email': mocker.get_player_email(0)}
        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'])
コード例 #9
0
    def testDelete(self):
        """ Test deleting player from team roster"""
        # add player to team
        mocker = MockLeague(self)
        team_id = mocker.get_teams()[0]['team_id']
        player_id = mocker.get_players()[0]['player_id']
        player_two_id = mocker.get_players()[2]['player_id']

        # invalid combination
        query = "?player_id=" + str(player_two_id)
        url_request = Routes['team_roster'] + "/" + str(team_id) + query
        rv = self.app.delete(url_request, headers=headers)
        expect = {'details': player_two_id, 'message': PlayerNotOnTeam.message}
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(expect, loads(rv.data),
                         Routes['team_roster'] + "DELETE: Invalid combination")
        self.assertEqual(PlayerNotOnTeam.status_code, rv.status_code,
                         Routes['team_roster'] + " PUT: invalid data")

        # team does not exists
        query = "?player_id=" + str(player_id)
        url_request = Routes['team_roster'] + "/" + str(INVALID_ID) + query
        rv = self.app.delete(url_request, headers=headers)
        expect = {'details': INVALID_ID, 'message': TeamDoesNotExist.message}
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(expect, loads(rv.data),
                         Routes['team_roster'] + "DELETE: Invalid player id")
        self.assertEqual(TeamDoesNotExist.status_code, rv.status_code,
                         Routes['team_roster'] + " PUT: invalid player id")

        # player does not exist
        query = "?player_id=" + str(INVALID_ID)
        url_request = Routes['team_roster'] + "/" + str(team_id) + query
        rv = self.app.delete(url_request, headers=headers)
        expect = {'details': INVALID_ID, 'message': PlayerNotOnTeam.message}
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(expect, loads(rv.data),
                         Routes['team_roster'] + "DELETE: Invalid player id")
        self.assertEqual(PlayerNotOnTeam.status_code, rv.status_code,
                         Routes['team_roster'] + " PUT: invalid player id")

        # proper deletion
        query = "?player_id=" + str(player_id)
        url_request = Routes['team_roster'] + "/" + str(team_id) + query
        rv = self.app.delete(url_request, headers=headers)
        expect = None
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(SUCCESSFUL_DELETE_CODE, rv.status_code,
                         Routes['team_roster'] + "DELETE: Invalid combination")
        self.assertEqual(expect, loads(rv.data),
                         Routes['team_roster'] + "DELETE: Invalid combination")

        # make sure player it not on team
        team = Team.query.get(team_id)
        player = Player.query.get(player_id)
        self.assertTrue(player.id not in [p.id for p in team.players],
                        Routes['team_roster'] + " DELETE: player not removed")
        self.assertTrue(player.id != team.player_id,
                        Routes['team_roster'] + " DELETE: player not removed")