Exemplo n.º 1
0
    def testJoinLeagueRequestInit(self):
        """ Test the constructor validates the given data"""
        player = str(uuid.uuid1())
        email = player + "@mlsb.ca"
        some_gender = "m"
        color = str(uuid.uuid1())
        league = self.add_league(str(uuid.uuid1()))
        sponsor = self.add_sponsor(str(uuid.uuid1()))
        no_team = Team(color="Black",
                       sponsor_id=sponsor['sponsor_id'],
                       league_id=league['league_id'])
        team_json = self.add_team(color, sponsor=sponsor, league=league)
        team = Team.query.get(team_json['team_id'])

        # good request and test json method
        league_request = JoinLeagueRequest(email, player, team, some_gender)
        league_request.json()

        # bad stuff
        try:
            JoinLeagueRequest(1, player, team, some_gender)
            self.assertEqual(False, True, "Should raise invalid field")
        except InvalidField:
            pass
        try:
            JoinLeagueRequest(email, 1, team, some_gender)
            self.assertEqual(False, True, "Should raise invalid field")
        except InvalidField:
            pass
        try:
            JoinLeagueRequest(email, player, "wrong team", some_gender)
            self.assertEqual(False, True, "Should raise team does not exist")
        except TeamDoesNotExist:
            pass
        try:
            JoinLeagueRequest(email, player, no_team, some_gender)
            self.assertEqual(False, True, "Should raise team does not exist")
        except TeamDoesNotExist:
            pass
        try:
            JoinLeagueRequest(email, player, team, "XX")
            self.assertEqual(False, True, "Should raise invalid field")
        except InvalidField:
            pass
def request_to_join_team(team_id):
    # know the team will be found since decorator checks team exists
    team = Team.query.get(team_id)
    join = JoinLeagueRequest(current_user.email, current_user.name, team,
                             current_user.gender)
    DB.session.add(join)
    DB.session.commit()
    return Response(json.dumps(join.json()),
                    status=200,
                    mimetype="application/json")
def create_league_request():
    """Creates a league request for testing purposes."""
    request_info = request.get_json(silent=True)
    team = Team.query.get(request_info.get("team_id"))
    league_request = JoinLeagueRequest(request_info.get("email"),
                                       request_info.get("player_name"), team,
                                       request_info.get('gender'))
    LOGGER.info(f"Creating join league request: {request_info}")
    DB.session.add(league_request)
    DB.session.commit()
    return Response(json.dumps(league_request.json()),
                    200,
                    mimetype='application/json')