コード例 #1
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")
コード例 #2
0
 def add_espys(self,
               team,
               sponsor,
               description=None,
               points=0.0,
               receipt=None,
               time=None,
               date=None):
     """Returns a espy json object that was created with a post request."""
     params = {
         "team_id": team["team_id"],
         "sponsor_id": sponsor["sponsor_id"],
         "description": description,
         "points": points,
         "receipt": receipt,
         "date": date,
         "time": time
     }
     rv = self.app.post(Routes['espy'], data=params, headers=headers)
     self.assertEqual(SUCCESSFUL_POST_CODE, rv.status_code,
                      "Unable to add espy object")
     self.assertTrue(loads(rv.data) > 0, "Unable to add espy object")
     espy = Espys.query.get(loads(rv.data))
     self.espys_to_delete.append(espy.id)
     return espy.json()
    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'])
コード例 #4
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")
コード例 #5
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")
コード例 #6
0
ファイル: testKikApi.py プロジェクト: Vermss/mlsb-platform
    def testMain(self):
        # add some background
        day = datetime.date.today() + datetime.timedelta(days=1)
        game = addGame(self, day=day.strftime("%Y-%m-%d"), time="22:40")
        team_model = Team.query.get(game['home_team_id'])
        team = team_model.json()
        player = self.add_player("Test Kik Bot Captain", "*****@*****.**",
                                 "m")
        self.add_player_to_team(team, player, captain=True)
        route = Routes['kikupcominggames']

        # non-subscribed player
        data = {'name': 'DoesNotExist'}
        expect = {
            'details': 'DoesNotExist',
            'message': PlayerDoesNotExist.message
        }
        rv = self.app.post(route, data=data, headers=KIK_HEADER)
        self.output(loads(rv.data))
        self.output(expect)
        m = route + " POST: Player DNE for upcoming games"
        self.assertEqual(rv.status_code, PlayerDoesNotExist.status_code, m)
        self.assertEqual(expect, loads(rv.data), m)

        # subscribed player upcoming games
        data = {'name': player['player_name']}
        rv = self.app.post(route, data=data, headers=KIK_HEADER)
        self.output(loads(rv.data))
        self.output(expect)
        m = route + " POST: Subscribed player for upcoming games"
        self.assertEqual(rv.status_code, SUCCESSFUL_GET_CODE, m)
        self.assertTrue(len(loads(rv.data)) > 0, m)
        self.assertEqual(game['game_id'], loads(rv.data)[0]['game_id'], m)
コード例 #7
0
 def add_game(self,
              date,
              time,
              home_team,
              away_team,
              league,
              division,
              status="",
              field=""):
     """Returns a game json object that was created with a post request."""
     params = {"home_team_id": int(home_team["team_id"]),
               "away_team_id": int(away_team["team_id"]),
               "date": date,
               "time": time,
               "league_id": int(league['league_id']),
               "division_id": int(division['division_id']),
               "status": status
               }
     rv = self.app.post(Routes['game'], json=params, headers=headers)
     self.assertEqual(SUCCESSFUL_POST_CODE,
                      rv.status_code,
                      "Unable to add game object")
     self.assertTrue(loads(rv.data) > 0, "Unable to add game object")
     game = Game.query.get(loads(rv.data))
     self.games_to_delete.append(game.id)
     return game.json()
コード例 #8
0
    def testMain(self):

        # add some background
        game = addGame(self)
        team_model = Team.query.get(game['home_team_id'])
        team = team_model.json()
        player = self.add_player("Test Bot Captain", "*****@*****.**", "m")
        self.add_player_to_team(team, player, captain=True)
        route = Routes['botcaptaingames']

        # valid request
        data = {'player_id': player['player_id'],
                'team': team['team_id']}
        rv = self.app.post(route, json=data, headers=headers)
        self.output(loads(rv.data))
        self.output(game)
        error = Routes['botcaptaingames'] + " POST: Valid Captain's games"
        self.assertTrue(len(loads(rv.data)) > 0, error)
        self.assertEqual(rv.status_code, SUCCESSFUL_GET_CODE, error)
        self.assertGameModelEqual(game, loads(rv.data)[0], error)

        # submit score
        self.submit_a_score(player, game, 1, hr=[player['player_id']])

        # second valid request
        data = {'player_id': player['player_id'],
                'team': team['team_id']}
        expect = []
        rv = self.app.post(route, json=data, headers=headers)
        self.output(loads(rv.data))
        self.output(expect)
        error = Routes['botcaptaingames'] + " POST: Invalid Captain's games"
        self.assertEqual(rv.status_code, SUCCESSFUL_GET_CODE, error)
        self.assertEqual(expect, loads(rv.data), error)
コード例 #9
0
    def testGameDelete(self):

        # delete invalid game id
        rv = self.app.delete(Routes['game'] + "/" + str(INVALID_ID),
                             headers=headers)
        expect = {'details': INVALID_ID, 'message': GameDoesNotExist.message}
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(loads(rv.data), expect,
                         Routes['game'] + " DELETE: on invalid game id")
        self.assertEqual(rv.status_code, GameDoesNotExist.status_code,
                         Routes['game'] + " DELETE: on invalid game id")

        # add a game
        game = addGame(self)

        # delete valid game id
        rv = self.app.delete(Routes['game'] + "/" + str(game['game_id']),
                             headers=headers)
        expect = None
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(loads(rv.data), expect,
                         Routes['game'] + " DELETE: on valid game id")
        self.assertEqual(rv.status_code, 200,
                         Routes['game'] + " DELETE: on valid game id")
コード例 #10
0
    def deleteValidTest(self,
                        route,
                        expected_status_code_after_deletion,
                        assert_function,
                        object_id,
                        expected_object,
                        expected_message,
                        error_message=""):
        """Used to test a delete request for a valid resource."""
        # check object exists
        self.getTest(route + "/" + str(object_id),
                     SUCCESSFUL_GET_CODE,
                     assert_function,
                     expected_object,
                     error_message=error_message)

        # delete object
        rv = self.app.delete(route + "/" + str(object_id), headers=headers)
        expect = None
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(loads(rv.data), expect, error_message)
        self.assertEqual(rv.status_code, SUCCESSFUL_DELETE_CODE, error_message)

        # check object was deleted
        self.getTest(route + "/" + str(object_id),
                     expected_status_code_after_deletion,
                     self.assertEqual,
                     {"details": object_id, "message": expected_message},
                     error_message=error_message)
コード例 #11
0
ファイル: test.py プロジェクト: fras2560/mlsb-platform
 def testGet(self):
     #empty get
     rv = self.app.get(Routes['team_roster'] + "/1")
     expect = {'details': 1, '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")
     self.addPlayersToTeam()
     # get one team
     rv = self.app.get(Routes['team_roster'] + "/1")
     expect =  {   'captain': {
                'gender': 'm',
                'player_id': 1,
                'player_name': 'Dallas Fraser'},
                 'color': 'Green',
                 'espys': 0,
                 'league_id': None,
                 'players': [   {   
                                    'gender': 'm',
                                    'player_id': 1,
                                    'player_name': 'Dallas Fraser'}],
                 'sponsor_id': 1,
                 'team_id': 1,
                 'team_name': 'Domus Green',
                 'year': 2016}
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(expect, loads(rv.data), Routes['team_roster'] +
                      " GET: on non-empty set")
コード例 #12
0
ファイル: test.py プロジェクト: fras2560/mlsb-platform
 def testPost(self):
     self.addFun()
     params = {'year': 2012}
     rv = self.app.post(Routes['vfun'], data=params)
     expect = [{'count': 377, 'year': 2012}]
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(expect, loads(rv.data), Routes['vfun'] +
                      " View: on 2012 year")
     params = {}
     rv = self.app.post(Routes['vfun'], data=params)
     expect = [  
                 {'count': 89, 'year': 2002},
                 {'count': 100, 'year': 2003},
                 {'count': 177, 'year': 2004},
                 {'count': 186, 'year': 2005},
                 {'count': 176, 'year': 2006},
                 {'count': 254, 'year': 2007},
                 {'count': 290, 'year': 2008},
                 {'count': 342, 'year': 2009},
                 {'count': 304, 'year': 2010},
                 {'count': 377, 'year': 2011},
                 {'count': 377, 'year': 2012},
                 {'count': 461, 'year': 2013},
                 {'count': 349, 'year': 2014},
                 {'count': 501, 'year': 2015}]
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(expect, loads(rv.data), Routes['vfun'] +
                      " View: on 2012 year")
コード例 #13
0
ファイル: test.py プロジェクト: fras2560/mlsb-platform
 def testPost(self):
     self.addPlayersToTeam()
     params = {'player_name': "Dallas Fraser"}
     rv = self.app.post(Routes['vplayerteamLookup'], data=params)
     expect = [   {   'captain': {   'gender': 'm',
                    'player_id': 1,
                    'player_name': 'Dallas Fraser'},
                     'color': 'Green',
                     'espys': 0,
                     'league_id': None,
                     'sponsor_id': 1,
                     'team_id': 1,
                     'team_name': 'Domus Green',
                     'year': 2016}]
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(expect, loads(rv.data), Routes['vplayerteamLookup'] +
                      " View: on Dallas Fraser")
     params = {"player_name": "NotFuckingReal"}
     rv = self.app.post(Routes['vfun'], data=params)
     expect = []
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(expect, loads(rv.data), Routes['vplayerteamLookup'] +
                      " View: on no one")
コード例 #14
0
    def testPostPlayerId(self):
        """Test player id parameter"""
        mocker = MockLeague(self)

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

        # test an valid player id
        player_id = mocker.get_players()[0]['player_id']
        rv = self.app.post(Routes['vplayer'], data={"player_id": player_id})
        expect = {'Test Player 1': {'avg': 0.5,
                                    'bats': 2,
                                    'd': 0,
                                    'e': 0,
                                    'fc': 0,
                                    'fo': 0,
                                    'go': 0,
                                    'hr': 1,
                                    'id': player_id,
                                    'k': 1,
                                    'rbi': 2,
                                    's': 0,
                                    'ss': 0}}
        self.output(expect)
        self.output(loads(rv.data))
        self.assertEqual(expect,
                         loads(rv.data),
                         Routes['vplayer'] + " Post: valid player id")
コード例 #15
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")
コード例 #16
0
ファイル: testKikApi.py プロジェクト: Vermss/mlsb-platform
    def testMain(self):
        # add some background
        league = self.add_league("Test Kik Bot League")
        sponsor = self.add_sponsor("Test Kik Bot Sponsor")
        team = self.add_team("Black", sponsor, league, VALID_YEAR)
        player = self.add_player("TestKikCaptain", "*****@*****.**", "m")
        self.add_player_to_team(team, player, captain=True)
        kik = "testKikCaptain"
        player = self.add_kik_to_player(player, kik)
        route = Routes['kikunsubscribe']

        # player does not exist
        data = {'kik': "DoesNotExist", "team": team['team_id']}
        expect = {
            'details': 'Player is not subscribed',
            'message': 'Player is not subscribed'
        }
        rv = self.app.post(route, data=data, headers=KIK_HEADER)
        self.output(loads(rv.data))
        self.output(expect)
        m = route + " POST: team does not exist"
        self.assertEqual(rv.status_code, PlayerNotSubscribed.status_code, m)
        self.assertEqual(expect, loads(rv.data), m)

        # unsubscribe
        data = {'kik': kik, "team": team['team_id']}
        expect = True
        rv = self.app.post(route, data=data, headers=KIK_HEADER)
        self.output(loads(rv.data))
        self.output(expect)
        message = route + " POST: team does not exist"
        self.assertEqual(rv.status_code, SUCCESSFUL_GET_CODE, message)
        self.assertEqual(expect, loads(rv.data), message)
コード例 #17
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")
コード例 #18
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'])
コード例 #19
0
 def testNonEmptyYear(self):
     """Test a non-empty year"""
     MockLeague(self)
     params = {'stat': "k", 'year': VALID_YEAR}
     rv = self.app.post(Routes['vleagueleaders'], json=params)
     self.output(loads(rv.data))
     self.assertTrue(len(loads(rv.data)) > 0, Routes['vleagueleaders'] +
                     " View: hr stat was empty")
コード例 #20
0
 def testNonEmptyStat(self):
     """Test a stat that is not empty"""
     MockLeague(self)
     params = {'stat': "hr"}
     rv = self.app.post(Routes['vleagueleaders'], json=params)
     self.output(loads(rv.data))
     self.assertTrue(len(loads(rv.data)) > 0, Routes['vleagueleaders'] +
                     " View: hr stat was empty for all years")
 def testEmptyYear(self):
     """Test schedule view for empty league"""
     rv = self.app.get(Routes['vschedule'] + "/2012" + "/1")
     expect = []
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(expect, loads(rv.data)['items'],
                      Routes['vschedule'] + "View: on 2012 year")
コード例 #22
0
ファイル: test.py プロジェクト: fras2560/mlsb-platform
    def testMain(self):
        self.mockScoreSubmission()
        # invalid captian request
        data = {"kik": "frase2560", "team": 1}
        expect = {"details": None, "message": NotTeamCaptain.message}
        rv = self.app.post(Routes["kikcaptaingames"], data=data, headers=kik)
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(
            rv.status_code, NotTeamCaptain.status_code, Routes["kikcaptaingames"] + " POST: Invalid Captain's games"
        )
        self.assertEqual(expect, loads(rv.data), Routes["kikcaptain"] + " Post: Invalid Captain's games")

        # subscribe the captain to a team
        data = {"kik": "frase2560", "captain": "Dallas Fraser", "team": 1}
        expect = 1
        rv = self.app.post(Routes["kikcaptain"], data=data, headers=kik)
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(rv.status_code, 200, Routes["kikcaptain"] + " POST: Authenticate Captain")
        self.assertEqual(expect, loads(rv.data), Routes["kikcaptain"] + " Post: Authenticate Captain")
        # valid request
        data = {"kik": "frase2560", "team": 1}
        expect = [
            {
                "away_team": "Chainsaw Black",
                "away_team_id": 2,
                "date": "2014-08-23",
                "field": "",
                "game_id": 1,
                "home_team": "Domus Green",
                "home_team_id": 1,
                "league_id": 1,
                "status": "",
                "time": "11:37",
            }
        ]
        rv = self.app.post(Routes["kikcaptaingames"], data=data, headers=kik)
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(rv.status_code, 200, Routes["kikcaptaingames"] + " POST: Valid Captain's games")
        self.assertEqual(expect, loads(rv.data), Routes["kikcaptain"] + " Post: Invalid Captain's games")
        # submit score
        data = {"kik": "frase2560", "game_id": 1, "score": 5, "hr": [1, 2], "ss": []}
        expect = True
        rv = self.app.post(Routes["kiksubmitscore"], data=data, headers=kik)
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(rv.status_code, 200, Routes["kiksubmitscore"] + " POST: valid request")
        self.assertEqual(expect, loads(rv.data), Routes["kiksubmitscore"] + " POST: valid request")
        # second valid request
        data = {"kik": "frase2560", "team": 1}
        expect = []
        rv = self.app.post(Routes["kikcaptaingames"], data=data, headers=kik)
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(rv.status_code, 200, Routes["kikcaptaingames"] + " POST: Invalid Captain's games")
        self.assertEqual(expect, loads(rv.data), Routes["kikcaptain"] + " Post: Invalid Captain's games")
コード例 #23
0
 def add_league(self, league_name):
     """Returns league json object that was created with a post request."""
     params = {"league_name": league_name}
     rv = self.app.post(Routes['league'], data=params, headers=headers)
     self.assertEqual(SUCCESSFUL_POST_CODE, rv.status_code,
                      "Unable to add league object")
     self.assertTrue(loads(rv.data) > 0, "Unable to add league object")
     league = League.query.get(loads(rv.data))
     self.leagues_to_delete.append(league.id)
     return league.json()
 def testGetLeagueDoesNotExists(self):
     """Test a get request for a league that does not exist"""
     rv = self.app.get(f"{MAIN_ROUTE}/{VALID_YEAR}/{INVALID_ID}")
     expect = {'details': INVALID_ID, 'message': LeagueDoesNotExist.message}
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(loads(rv.data), expect,
                      f"{MAIN_ROUTE}: GET league that Dne")
     self.assertEqual(LeagueDoesNotExist.status_code, rv.status_code,
                      f"{MAIN_ROUTE}: GET league that Dne")
コード例 #25
0
 def testEmptyYear(self):
     """Test an empty year"""
     MockLeague(self)
     params = {'stat': "hr", 'year': INVALID_YEAR}
     rv = self.app.post(Routes['vleagueleaders'], json=params)
     expect = []
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(expect, loads(rv.data), Routes['vleagueleaders'] +
                      " View: empty stat on not-recording year")
コード例 #26
0
 def add_fun(self, count, year=date.today().year):
     """Returns a fun json object that was created with a post request."""
     params = {"year": year, "count": count}
     rv = self.app.post(Routes['fun'], data=params, headers=headers)
     self.assertEqual(SUCCESSFUL_POST_CODE, rv.status_code,
                      "Unable to add fun object")
     self.assertTrue(loads(rv.data) > 0, "Unable to add fun object")
     fun = Fun.query.filter(Fun.year == loads(rv.data)).first()
     self.fun_to_delete.append(fun.id)
     return fun.json()
 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")
コード例 #28
0
 def add_division(self, division_name):
     """Returns" division json object the result of a post request"""
     params = {"division_name": division_name}
     rv = self.app.post(Routes['division'], json=params, headers=headers)
     self.assertEqual(SUCCESSFUL_POST_CODE,
                      rv.status_code,
                      "Unable to add divsion object")
     self.assertTrue(loads(rv.data) > 0, "Unable to add division object")
     division = Division.query.get(loads(rv.data))
     self.divisions_to_delete.append(division.id)
     return division.json()
 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")
コード例 #30
0
 def getTest(self,
             route,
             expected_status_code,
             assert_function,
             expected_object,
             error_message=""):
     """Used to test a get request."""
     rv = self.app.get(route, headers=headers)
     self.output(loads(rv.data))
     self.output(expected_object)
     assert_function(expected_object, loads(rv.data), error_message)
     self.assertEqual(expected_status_code, rv.status_code, error_message)
コード例 #31
0
 def deleteInvalidTest(self,
                       route,
                       expected_status_code,
                       expected_message,
                       error_message=""):
     """Used to test a delete request for an invalid resource."""
     rv = self.app.delete(route + "/" + str(INVALID_ID), headers=headers)
     expect = {'details': INVALID_ID, 'message': expected_message}
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(loads(rv.data), expect, error_message)
     self.assertEqual(rv.status_code, expected_status_code, error_message)
コード例 #32
0
 def postInvalidTest(self,
                     route,
                     params,
                     expected_status_code,
                     assert_function,
                     expect,
                     error_message=""):
     """Used to test an invalid post test."""
     rv = self.app.post(route, json=params, headers=headers)
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(expected_status_code, rv.status_code, error_message)
     assert_function(expect, loads(rv.data), error_message)
 def testMockLeague(self):
     """Test schedule view for mocked league"""
     league_id = MockLeague(self).league['league_id']
     year = datetime.datetime.now().year
     url = Routes['vschedule'] + "/" + str(year) + "/" + str(league_id)
     rv = self.app.get(url)
     game = {'away_team': 'Advanced Test Sponsor Test Team 2',
             'home_team': 'Advanced Test Sponsor Test Team',
             'score': '1-6'}
     expect = ["1-6", "0-0", ""]
     self.output(loads(rv.data))
     self.output(expect)
     for index, game in enumerate(loads(rv.data)['items']):
         self.assertEqual(expect[index], game['score'])
コード例 #34
0
ファイル: test.py プロジェクト: fras2560/mlsb-platform
 def testPostNoParameters(self):
     rv = self.app.post(Routes['vteam'])
     expect = {}
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(expect, loads(rv.data),
              Routes['vteam'] + " Post: View of Team")
     self.addSeason()
     rv = self.app.post(Routes['vteam'])
     expect = {   '1': {   'games': 3,
                          'hits_allowed': 3,
                          'hits_for': 3,
                          'losses': 1,
                          'name': 'Domus Green',
                          'runs_against': 4,
                          'runs_for': 4,
                          'ties': 1,
                          'wins': 1},
                 '2': {   'games': 3,
                          'hits_allowed': 3,
                          'hits_for': 3,
                          'losses': 1,
                          'name': 'Sentry Sky Blue',
                          'runs_against': 4,
                          'runs_for': 4,
                          'ties': 1,
                          'wins': 1},
                 '3': {   'games': 3,
                          'hits_allowed': 3,
                          'hits_for': 3,
                          'losses': 1,
                          'name': 'Nightschool Navy',
                          'runs_against': 4,
                          'runs_for': 4,
                          'ties': 1,
                          'wins': 1},
                 '4': {   'games': 3,
                          'hits_allowed': 3,
                          'hits_for': 3,
                          'losses': 1,
                          'name': 'Brick Blue',
                          'runs_against': 4,
                          'runs_for': 4,
                          'ties': 1,
                          'wins': 1}}
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(expect, loads(rv.data),
              Routes['vteam'] + " Post: View of Team")
コード例 #35
0
def submit_score(user):
    """Submits a score and wipes the data

    Parameters:
        user: the dictionary object
    Returns:
        user: the update user
    """
    submission = user['game']
    submission['player_id'] = user['pid']
    r = requests.post(BASEURL + "api/bot/submit_score",
                      params=submission,
                      headers=HEADERS)
    print(r.text, r.status_code)
    if (r.status_code == 401):
        raise NotCaptainException("Says you are not the captain, ask admin")
    elif (r.status_code != 200):
        d = loads(r.text)
        if d['status_code'] == 401 or d['status_code'] == 404:
            m = "Says you are not a captain, check admin"
            raise NotCaptainException(m)
        else:
            raise PlatformException(PLATFORMMESSAGE)
    # remove the data since not relevant
    user['game'] = {}
    return user
コード例 #36
0
ファイル: test.py プロジェクト: fras2560/mlsb-platform
 def testPost(self):
     # no date
     rv = self.app.post(Routes['vplayer'])
     expect = {}
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(expect, loads(rv.data),
                      Routes['vplayer'] + " Post: View of Player")
     self.addBats()
     # no parameters
     rv = self.app.post(Routes['vplayer'])
     expect = {   'Dallas Fraser': {   'avg': 1.0,
                                      'bats': 1,
                                      'd': 0,
                                      'e': 0,
                                      'fc': 0,
                                      'fo': 0,
                                      'go': 0,
                                      'hr': 0,
                                      'id': 1,
                                      'k': 0,
                                      'rbi': 1,
                                      's': 1,
                                      'ss': 0},
                 'My Dream Girl': {   'avg': 0.0,
                                      'bats': 1,
                                      'd': 0,
                                      'e': 0,
                                      'fc': 0,
                                      'fo': 0,
                                      'go': 0,
                                      'hr': 0,
                                      'id': 2,
                                      'k': 1,
                                      'rbi': 1,
                                      's': 0,
                                      'ss': 0}}
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(expect, loads(rv.data),
                      Routes['vplayer'] + " Post: View of Player")
コード例 #37
0
ファイル: test.py プロジェクト: fras2560/mlsb-platform
    def testMain(self):
        self.addPlayersToTeam()
        # valid request
        data = {"kik": "frase2560", "name": "Dallas Fraser", "team": 1}
        expect = True
        rv = self.app.post(Routes["kiksubscribe"], data=data, headers=kik)
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(rv.status_code, 200, Routes["kiksubscribe"] + " POST: valid request")
        self.assertEqual(expect, loads(rv.data), Routes["kiksubscribe"] + " Post: subscribe")
        # player does not exist
        data = {"kik": "DoesNotExist", "team": 1}
        expect = {"details": "Player is not subscribed", "message": "Player is not subscribed"}

        rv = self.app.post(Routes["kikunsubscribe"], data=data, headers=kik)
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(
            rv.status_code, PlayerNotSubscribed.status_code, Routes["kikunsubscribe"] + " POST: team does not exist"
        )
        self.assertEqual(expect, loads(rv.data), Routes["kikunsubscribe"] + " Post: team does not exist")
        # unsubscribe
        data = {"kik": "frase2560", "team": 1}
        expect = True
        rv = self.app.post(Routes["kikunsubscribe"], data=data, headers=kik)
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(rv.status_code, 200, Routes["kikunsubscribe"] + " POST: team does not exist")
        self.assertEqual(expect, loads(rv.data), Routes["kikunsubscribe"] + " Post: team does not exist")
コード例 #38
0
ファイル: test.py プロジェクト: fras2560/mlsb-platform
 def testDelete(self):
     #add player to team
     self.addPlayersToTeam()
     # missing data
     rv = self.app.delete(Routes['team_roster'] + "/2")
     message = 'Missing required parameter in the JSON body or the post body or the query string'
     expect = {   'message': {   'player_id': message}}
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(expect, loads(rv.data), Routes['team_roster'] +
                      " DELETE: Missing header")
     self.assertEqual(400, rv.status_code, 
                      Routes['team_roster'] + " PUT: invalid data")
     # invalid combination
     query = "?player_id=2"
     rv = self.app.delete(Routes['team_roster'] + "/1" + query)
     expect = {'details': 2, '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")
     # proper deletion
     query = "?player_id=1"
     rv = self.app.delete(Routes['team_roster'] + "/1" + query)
     expect = None
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(expect, loads(rv.data), Routes['team_roster'] +
                      " DELETE: Invalid combination")
コード例 #39
0
ファイル: test.py プロジェクト: fras2560/mlsb-platform
 def testPost(self):
     #invalid update
     params = {"player_id": 1}
     rv = self.app.post(Routes['team_roster'] + "/1", data=params)
     expect = {'details': 1, '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")
     # add player to team
     self.addTeams()
     params = {"player_id": 1}
     rv = self.app.post(Routes['team_roster'] + "/1", data=params)
     expect = None
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(loads(rv.data), expect,
                      Routes['team_roster'] + " POST: proper data")
     self.assertEqual(201, rv.status_code, 
                      Routes['team_roster'] + " PUT: invalid data")
     # add a captain
     params = {"player_id": 2, "captain": 1}
     rv = self.app.post(Routes['team_roster'] + "/1", data=params)
     expect = None
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(loads(rv.data), expect,
                      Routes['team_roster'] + " POST: proper data")
     self.assertEqual(201, rv.status_code, 
                      Routes['team_roster'] + " PUT: invalid data")
コード例 #40
0
ファイル: test.py プロジェクト: fras2560/mlsb-platform
 def testMain(self):
     self.addPlayers()
     # players email
     expect = [   {  
                         'gender': 'm',
                         'player_id': 1,
                         'player_name': 'Dallas Fraser'}]
     rv = self.app.post(Routes['vplayerLookup'], data={'email': '*****@*****.**'})
     self.output(loads(rv.data), )
     self.output(expect)
     self.assertEqual(expect, loads(rv.data),
              Routes['vteam'] + " Post: View of Team")
     # players name
     expect = [   {  'gender': 'm',
                     'player_id': 1,
                     'player_name': 'Dallas Fraser'}]
     rv = self.app.post(Routes['vplayerLookup'], data={'player_name': 'Dallas'})
     self.output(loads(rv.data), )
     self.output(expect)
     self.assertEqual(expect, loads(rv.data),
              Routes['vteam'] + " Post: View of Team")
     # not a player
     expect = []
     rv = self.app.post(Routes['vplayerLookup'], data={'player_name': 'XX'})
     self.output(loads(rv.data), )
     self.output(expect)
     self.assertEqual(expect, loads(rv.data),
              Routes['vteam'] + " Post: View of Team")
コード例 #41
0
ファイル: test.py プロジェクト: fras2560/mlsb-platform
 def testMain(self):
     self.addPlayersToTeam()
     # player not subscribed
     data = {"kik": "frase2560", "sponsor": "Domus", "amount": 1}
     expect = {"details": "frase2560", "message": PlayerNotSubscribed.message}
     rv = self.app.post(Routes["kiktransaction"], data=data, headers=kik)
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(
         rv.status_code,
         PlayerNotSubscribed.status_code,
         Routes["kiktransaction"] + " Post: transaction for player not subscribed",
     )
     self.assertEqual(
         expect, loads(rv.data), Routes["kiktransaction"] + " Post: transaction for player not subscribed"
     )
     # subscribe the player
     data = {"kik": "frase2560", "name": "Dallas Fraser", "team": 1}
     expect = True
     rv = self.app.post(Routes["kiksubscribe"], data=data, headers=kik)
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(rv.status_code, 200, Routes["kikcaptain"] + " POST: valid request")
     self.assertEqual(expect, loads(rv.data), Routes["kiksubscribe"] + " Post: subscribe")
     # sponsor does not exist
     data = {"kik": "frase2560", "sponsor": "FUCKINGDOESNOTEXIST", "amount": 1}
     expect = {"details": "FUCKINGDOESNOTEXIST", "message": SponsorDoesNotExist.message}
     rv = self.app.post(Routes["kiktransaction"], data=data, headers=kik)
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(
         rv.status_code, SponsorDoesNotExist.status_code, Routes["kiktransaction"] + " Post: sponsor does not exist"
     )
     self.assertEqual(expect, loads(rv.data), Routes["kiktransaction"] + " Post: sponsor does not exist")
コード例 #42
0
ファイル: test.py プロジェクト: fras2560/mlsb-platform
 def testParameters(self):
     expect = {   '1': {   'games': 3,
                          'hits_allowed': 3,
                          'hits_for': 3,
                          'losses': 1,
                          'runs_against': 4,
                          'name': 'Domus Green',
                          'runs_for': 4,
                          'ties': 1,
                          'wins': 1},
                 '2': {   'games': 3,
                          'hits_allowed': 3,
                          'hits_for': 3,
                          'losses': 1,
                          'name': 'Sentry Sky Blue',
                          'runs_against': 4,
                          'runs_for': 4,
                          'ties': 1,
                          'wins': 1}}
     self.addSeason()
     rv = self.app.post(Routes['vteam'], data={'league_id': 1})
     self.output(loads(rv.data), )
     self.output(expect)
     self.assertEqual(expect, loads(rv.data),
              Routes['vteam'] + " Post: View of Team")
     expect = {   '1': {   'games': 3,
                          'hits_allowed': 3,
                          'hits_for': 3,
                          'losses': 1,
                          'runs_against': 4,
                          'name': 'Domus Green',
                          'runs_for': 4,
                          'ties': 1,
                          'wins': 1}}
     rv = self.app.post(Routes['vteam'], data={'team_id': 1})
     self.output(loads(rv.data), )
     self.output(expect)
     self.assertEqual(expect, loads(rv.data),
              Routes['vteam'] + " Post: View of Team")
コード例 #43
0
ファイル: test.py プロジェクト: fras2560/mlsb-platform
    def testMain(self):
        
        # f**k this test isnt great since 
        self.mockLeaders()
        params = {'stat': "hr"}
        rv = self.app.post(Routes['vleagueleaders'], data=params)
        expect = [  {'hits': 3, 'id': 3, 'name': 'My Dream Girl', 'team': 'Sentry Sky Blue'},
                    {'hits': 3, 'id': 3, 'name': 'My Dream Girl', 'team': 'Brick Blue'},
                    {'hits': 3, 'id': 2, 'name': 'Dallas Fraser', 'team': 'Domus Green'},
                    {'hits': 3, 'id': 2, 'name': 'Dallas Fraser', 'team': 'Nightschool Navy'}
                ]
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(expect, loads(rv.data), Routes['vleagueleaders'] +
                         " View: on all years")
        params = {'stat': "hr", 'year': 2016}
        rv = self.app.post(Routes['vleagueleaders'], data=params)
        expect = [  {'hits': 1, 'id': 2, 'name': 'Dallas Fraser', 'team': 'Domus Green'},
                    {'hits': 1, 'id': 3, 'name': 'My Dream Girl', 'team': 'Sentry Sky Blue'}]

        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(expect, loads(rv.data), Routes['vleagueleaders'] +
                         " View: on 2016")
コード例 #44
0
ファイル: test.py プロジェクト: fras2560/mlsb-platform
 def testMain(self):
     self.mockScoreSubmission()
     # invalid captain
     data = {"kik": "frase2560", "game_id": 1, "score": 1, "hr": [1, 2], "ss": []}
     expect = {"details": "frase2560", "message": PlayerNotSubscribed.message}
     rv = self.app.post(Routes["kiksubmitscore"], data=data, headers=kik)
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(
         rv.status_code, PlayerNotSubscribed.status_code, Routes["kiksubmitscore"] + " POST: invalid kik user name"
     )
     self.assertEqual(expect, loads(rv.data), Routes["kiksubmitscore"] + " POST: invalid kik user name")
     player = Player.query.get(1)
     player.kik = "frase2560"  # add the kik name to the captain
     DB.session.commit()
     # invalid game
     data = {"kik": "frase2560", "game_id": -1, "score": 1, "hr": [1, 2], "ss": []}
     expect = {"details": -1, "message": GameDoesNotExist.message}
     rv = self.app.post(Routes["kiksubmitscore"], data=data, headers=kik)
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(
         rv.status_code, GameDoesNotExist.status_code, Routes["kiksubmitscore"] + " POST: invalid game id"
     )
     self.assertEqual(expect, loads(rv.data), Routes["kiksubmitscore"] + " POST: invalid game id")
     # more hr than runs scored
     data = {"kik": "frase2560", "game_id": 1, "score": 1, "hr": [1, 2], "ss": []}
     expect = {"details": "More hr than score", "message": InvalidField.message}
     rv = self.app.post(Routes["kiksubmitscore"], data=data, headers=kik)
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(
         rv.status_code, InvalidField.status_code, Routes["kiksubmitscore"] + " POST: more hr than runs"
     )
     self.assertEqual(expect, loads(rv.data), Routes["kiksubmitscore"] + " POST: more hr than runs")
     # normal request
     data = {"kik": "frase2560", "game_id": 1, "score": 5, "hr": [1, 2], "ss": []}
     expect = True
     rv = self.app.post(Routes["kiksubmitscore"], data=data, headers=kik)
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(rv.status_code, 200, Routes["kiksubmitscore"] + " POST: valid request")
     self.assertEqual(expect, loads(rv.data), Routes["kiksubmitscore"] + " POST: valid request")
コード例 #45
0
ファイル: test.py プロジェクト: fras2560/mlsb-platform
 def testMain(self):
     self.addCaptainToTeam()
     # valid request
     data = {"kik": "frase2560", "captain": "Dallas Fraser", "team": 1}
     expect = 1
     rv = self.app.post(Routes["kikcaptain"], data=data, headers=kik)
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(rv.status_code, 200, Routes["kikcaptain"] + " POST: Authenticate Captain")
     self.assertEqual(expect, loads(rv.data), Routes["kikcaptain"] + " Post: Authenticate Captain")
     # invalid team
     data = {"kik": "frase2560", "captain": "Dallas Fraser", "team": -1}
     expect = {"details": -1, "message": TeamDoesNotExist.message}
     rv = self.app.post(Routes["kikcaptain"], data=data, headers=kik)
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(rv.status_code, TeamDoesNotExist.status_code, Routes["kikcaptain"] + " POST: invalid team")
     self.assertEqual(expect, loads(rv.data), Routes["kikcaptain"] + " Post: invalid team")
     # captain name does not match
     data = {"kik": "frase2560", "captain": "F****r", "team": 1}
     expect = {"details": "Dallas Fraser", "message": NotTeamCaptain.message}
     rv = self.app.post(Routes["kikcaptain"], data=data, headers=kik)
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(
         rv.status_code, NotTeamCaptain.status_code, Routes["kikcaptain"] + " POST: name of captain does not match"
     )
     self.assertEqual(expect, loads(rv.data), Routes["kikcaptain"] + " Post: name of captain does not match")
     # if someone else tries to say captain with same name but different
     # kik name than one previously stated
     data = {"kik": "f****r", "captain": "Dallas Fraser", "team": 1}
     expect = {"details": "frase2560", "message": TeamAlreadyHasCaptain.message}
     rv = self.app.post(Routes["kikcaptain"], data=data, headers=kik)
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(
         rv.status_code, TeamAlreadyHasCaptain.status_code, Routes["kikcaptain"] + " POST: sketchy shit"
     )
     self.assertEqual(expect, loads(rv.data), Routes["kikcaptain"] + " Post: sketchy shit")
     # invalid credentials
     data = {"kik": "f****r", "captain": "Dallas Fraser", "team": 1}
     rv = self.app.post(Routes["kikcaptain"], data=data, headers=headers)
     self.assertEqual(rv.status_code, 401, Routes["kikcaptain"] + " POST: invalid credentials")
コード例 #46
0
ファイル: test.py プロジェクト: fras2560/mlsb-platform
    def testPostParameters(self):
        self.addBunchBats()
        rv = self.app.post(Routes['vplayer'])
        expect = {   'Dallas Fraser': {   'avg': 1.0,
                                         'bats': 1,
                                         'd': 0,
                                         'e': 0,
                                         'fc': 0,
                                         'fo': 0,
                                         'go': 0,
                                         'hr': 0,
                                         'id': 1,
                                         'k': 0,
                                         'rbi': 1,
                                         's': 1,
                                         'ss': 0},
                    'My Dream Girl': {   'avg': 0.0,
                                         'bats': 2,
                                         'd': 0,
                                         'e': 0,
                                         'fc': 0,
                                         'fo': 0,
                                         'go': 0,
                                         'hr': 0,
                                         'id': 2,
                                         'k': 2,
                                         'rbi': 2,
                                         's': 0,
                                         'ss': 0}}
        
        self.output(loads(rv.data))
        self.output(expect)
        
        self.assertEqual(expect, loads(rv.data),
                         Routes['vplayer'] + " Post: View of Player")
        # filter based on league
        rv = self.app.post(Routes['vplayer'], data={'league_id': 1})
        expect = {   'Dallas Fraser': {   'avg': 1.0,
                                         'bats': 1,
                                         'd': 0,
                                         'e': 0,
                                         'fc': 0,
                                         'fo': 0,
                                         'go': 0,
                                         'hr': 0,
                                         'id': 1,
                                         'k': 0,
                                         'rbi': 1,
                                         's': 1,
                                         'ss': 0}}

        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(expect, loads(rv.data),
                         Routes['vplayer'] + " Post: View of Player")
        # filter based on team
        rv = self.app.post(Routes['vplayer'], data={'team_id': 1})
        expect = {   'Dallas Fraser': {   'avg': 1.0,
                                         'bats': 1,
                                         'd': 0,
                                         'e': 0,
                                         'fc': 0,
                                         'fo': 0,
                                         'go': 0,
                                         'hr': 0,
                                         'id': 1,
                                         'k': 0,
                                         'rbi': 1,
                                         's': 1,
                                         'ss': 0},
                    'My Dream Girl': {   'avg': 0.0,
                                         'bats': 1,
                                         'd': 0,
                                         'e': 0,
                                         'fc': 0,
                                         'fo': 0,
                                         'go': 0,
                                         'hr': 0,
                                         'id': 2,
                                         'k': 1,
                                         'rbi': 1,
                                         's': 0,
                                         'ss': 0}}
        self.output(loads(rv.data))
        self.output(expect)
        self.assertEqual(expect, loads(rv.data),
                         Routes['vplayer'] + " Post: View of Player")
コード例 #47
0
ファイル: test.py プロジェクト: fras2560/mlsb-platform
 def testMain(self):
     self.addPlayersToTeam()
     # valid request
     data = {"kik": "frase2560", "name": "Dallas Fraser", "team": 1}
     expect = True
     rv = self.app.post(Routes["kiksubscribe"], data=data, headers=kik)
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(rv.status_code, 200, Routes["kiksubscribe"] + " POST: valid request")
     self.assertEqual(expect, loads(rv.data), Routes["kiksubscribe"] + " Post: subscribe")
     # team does not exist
     data = {"kik": "frase2560", "name": "Dallas Fraser", "team": -1}
     expect = {"details": -1, "message": TeamDoesNotExist.message}
     rv = self.app.post(Routes["kiksubscribe"], data=data, headers=kik)
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(
         rv.status_code, TeamDoesNotExist.status_code, Routes["kiksubscribe"] + " POST: team does not exist"
     )
     self.assertEqual(expect, loads(rv.data), Routes["kiksubscribe"] + " Post: team does not exist")
     # player not on team
     data = {"kik": "frase2560", "name": "f****r", "team": 1}
     expect = True
     rv = self.app.post(Routes["kiksubscribe"], data=data, headers=kik)
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(rv.status_code, 200, Routes["kiksubscribe"] + " POST: player not on team")
     self.assertEqual(expect, loads(rv.data), Routes["kiksubscribe"] + " Post: player not on team")
     # player already subscribed
     data = {"kik": "frase2560", "name": "Dallas Fraser", "team": 1}
     expect = True
     rv = self.app.post(Routes["kiksubscribe"], data=data, headers=kik)
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(rv.status_code, 200, Routes["kiksubscribe"] + " POST: already subscribed")
     self.assertEqual(expect, loads(rv.data), Routes["kiksubscribe"] + " Post: already subscribed")
     espys = Espys.query.all()
     # check to make sure not additional points were rewarded
     d = datetime.today().strftime("%Y-%m-%d")
     t = datetime.today().strftime("%H:%M")
     expect = [
         {
             "date": d,
             "description": "Dallas Fraser email:[email protected] awarded espy " "points for subscribing: 2",
             "espy_id": 1,
             "points": 2.0,
             "receipt": None,
             "sponsor": None,
             "team": "Domus Green",
             "time": t,
         },
         {
             "date": d,
             "description": "Dallas Fraser email:[email protected] SUBSCRIBED",
             "espy_id": 2,
             "points": 0.0,
             "receipt": None,
             "sponsor": None,
             "team": "Domus Green",
             "time": t,
         },
         {
             "date": d,
             "description": "f****r email:f****r@guest awarded espy points for " "subscribing: 2",
             "espy_id": 3,
             "points": 2.0,
             "receipt": None,
             "sponsor": None,
             "team": "Domus Green",
             "time": t,
         },
         {
             "date": d,
             "description": "f****r email:f****r@guest SUBSCRIBED",
             "espy_id": 4,
             "points": 0.0,
             "receipt": None,
             "sponsor": None,
             "team": "Domus Green",
             "time": t,
         },
     ]
     for index, espy in enumerate(espys):
         self.output(espy.json())
         # self.output(expect[index])
         self.assertEqual(espy.json(), expect[index])
     # invalid credentials
     data = {"kik": "f****r", "captain": "Dallas Fraser", "team": 1}
     rv = self.app.post(Routes["kiksubscribe"], data=data, headers=headers)
     self.assertEqual(rv.status_code, 401, Routes["kiksubscribe"] + " POST: invalid credentials")
コード例 #48
0
ファイル: test.py プロジェクト: fras2560/mlsb-platform
 def testMain(self):
     # non-subscribed player
     self.mockUpcomingGames()
     data = {"name": "DoesNotExist"}
     expect = {"details": "DoesNotExist", "message": PlayerDoesNotExist.message}
     rv = self.app.post(Routes["kikupcominggames"], data=data, headers=kik)
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(
         rv.status_code,
         PlayerDoesNotExist.status_code,
         Routes["kikupcominggames"] + " POST: Player DNE for upcoming games",
     )
     self.assertEqual(
         expect, loads(rv.data), Routes["kikupcominggames"] + " Post: Unsubscribed player for upcoming games"
     )
     # subscribed player upcoming games
     data = {"name": "Dallas Fraser"}
     d = date.today().strftime("%Y-%m-%d")
     d2 = (date.today() + timedelta(1)).strftime("%Y-%m-%d")
     d3 = (date.today() + timedelta(5)).strftime("%Y-%m-%d")
     expect = [
         {
             "away_team": "Chainsaw Black",
             "away_team_id": 2,
             "date": d,
             "field": "",
             "game_id": 1,
             "home_team": "Domus Green",
             "home_team_id": 1,
             "league_id": 1,
             "status": "",
             "time": "11:45",
         },
         {
             "away_team": "Domus Green",
             "away_team_id": 1,
             "date": d2,
             "field": "",
             "game_id": 2,
             "home_team": "Chainsaw Black",
             "home_team_id": 2,
             "league_id": 1,
             "status": "",
             "time": "11:45",
         },
         {
             "away_team": "Chainsaw Black",
             "away_team_id": 2,
             "date": d3,
             "field": "",
             "game_id": 3,
             "home_team": "Domus Green",
             "home_team_id": 1,
             "league_id": 1,
             "status": "",
             "time": "11:45",
         },
     ]
     rv = self.app.post(Routes["kikupcominggames"], data=data, headers=kik)
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(
         rv.status_code, 200, Routes["kikupcominggames"] + " POST: Subscribed player for upcoming games"
     )
     self.assertEqual(
         expect, loads(rv.data), Routes["kikupcominggames"] + " Post: Unsubscribed player for upcoming games"
     )
コード例 #49
0
ファイル: test.py プロジェクト: fras2560/mlsb-platform
 def testPost(self):
     # No games
     rv = self.app.post(Routes['vgame'])
     expect = []
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(expect, loads(rv.data),
                      Routes['vgame'] + " Post: View of Game")
     self.addBats()
     # just monday and wednesday
     rv = self.app.post(Routes['vgame'], data={"league_id": 1})
     expect = [   {   'away_bats': [],
                     'away_score': 0,
                     'away_team': {   'captain': None,
                                      'color': 'Black',
                                      'espys': 0,
                                      'league_id': None,
                                      'sponsor_id': 2,
                                      'team_id': 2,
                                      'team_name': 'Chainsaw Black',
                                      'year': 2016},
                     'date': '2014-08-23 11:37',
                     'game_id': 1,
                     'home_bats': [   {   'hit': 's',
                                          'inning': 5,
                                          'name': 'Dallas Fraser',
                                          'rbi': 1}],
                     'home_score': 1,
                     'home_team': {   'captain': None,
                                      'color': 'Green',
                                      'espys': 0,
                                      'league_id': None,
                                      'sponsor_id': 1,
                                      'team_id': 1,
                                      'team_name': 'Domus Green',
                                      'year': 2016},
                     'league': {'league_id': 1, 'league_name': 'Monday & Wedneday'},
                     'status': ''}]
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(expect, loads(rv.data),
                      Routes['vgame'] + " Post: View of Game")
     # no parameters
     rv = self.app.post(Routes['vgame'], data={})
     expect = [   {   'away_bats': [],
                     'away_score': 0,
                     'away_team': {   'captain': None,
                                      'color': 'Black',
                                      'espys': 0,
                                      'league_id': None,
                                      'sponsor_id': 2,
                                      'team_id': 2,
                                      'team_name': 'Chainsaw Black',
                                      'year': 2016},
                     'date': '2014-08-23 11:37',
                     'game_id': 1,
                     'home_bats': [   {   'hit': 's',
                                          'inning': 5,
                                          'name': 'Dallas Fraser',
                                          'rbi': 1}],
                     'home_score': 1,
                     'home_team': {   'captain': None,
                                      'color': 'Green',
                                      'espys': 0,
                                      'league_id': None,
                                      'sponsor_id': 1,
                                      'team_id': 1,
                                      'team_name': 'Domus Green',
                                      'year': 2016},
                     'league': {'league_id': 1, 'league_name': 'Monday & Wedneday'},
                     'status': ''},
                 {   'away_bats': [],
                     'away_score': 0,
                     'away_team': {   'captain': None,
                                      'color': 'Black',
                                      'espys': 0,
                                      'league_id': None,
                                      'sponsor_id': 2,
                                      'team_id': 2,
                                      'team_name': 'Chainsaw Black',
                                      'year': 2016},
                     'date': '2014-08-23 11:37',
                     'game_id': 2,
                     'home_bats': [   {   'hit': 'k',
                                          'inning': 5,
                                          'name': 'My Dream Girl',
                                          'rbi': 0}],
                     'home_score': 0,
                     'home_team': {   'captain': None,
                                      'color': 'Green',
                                      'espys': 0,
                                      'league_id': None,
                                      'sponsor_id': 1,
                                      'team_id': 1,
                                      'team_name': 'Domus Green',
                                      'year': 2016},
                     'league': {'league_id': 2, 'league_name': 'Tuesday & Thursday'},
                     'status': ''}]
     self.output(loads(rv.data))
     self.output(expect)
     self.assertEqual(expect, loads(rv.data),
                      Routes['vgame'] + " Post: View of Game")