Example #1
0
    def test_from_pending_tournament_throws_exception(self):
        # we need MatchResults with aliases (instead of IDs)
        match_1 = AliasMatch(winner=self.player_1.name,
                             loser=self.player_2.name)
        match_2 = AliasMatch(winner=self.player_3.name,
                             loser=self.player_4.name)

        player_aliases = [p.name for p in self.players]
        matches = [match_1, match_2]
        alias_to_id_map = [AliasMapping(player_alias=self.player_1.name,
                                        player_id=None)]
        pending_tournament = PendingTournament(
            name=self.name,
            type=self.type,
            date=self.date,
            regions=['norcal'],
            raw_id=self.raw_id,
            players=player_aliases,
            matches=matches,
            alias_to_id_map=alias_to_id_map)

        with self.assertRaises(Exception) as e:
            Tournament.from_pending_tournament(pending_tournament)

        self.assertTrue('Alias gar has no ID in map' in str(e.exception))
Example #2
0
    def test_from_pending_tournament_throws_exception(self):
        # we need MatchResults with aliases (instead of IDs)
        match_1 = AliasMatch(winner=self.player_1.name,
                             loser=self.player_2.name)
        match_2 = AliasMatch(winner=self.player_3.name,
                             loser=self.player_4.name)

        player_aliases = [p.name for p in self.players]
        matches = [match_1, match_2]
        alias_to_id_map = [
            AliasMapping(player_alias=self.player_1.name, player_id=None)
        ]
        pending_tournament = PendingTournament(name=self.name,
                                               type=self.type,
                                               date=self.date,
                                               regions=['norcal'],
                                               raw_id=self.raw_id,
                                               players=player_aliases,
                                               matches=matches,
                                               alias_to_id_map=alias_to_id_map)

        with self.assertRaises(Exception) as e:
            Tournament.from_pending_tournament(pending_tournament)

        self.assertTrue('Alias gar has no ID in map' in str(e.exception))
Example #3
0
    def test_from_pending_tournament(self):
        # we need MatchResults with aliases (instead of IDs)
        match_1 = AliasMatch(winner=self.player_1.name,
                             loser=self.player_2.name)
        match_2 = AliasMatch(winner=self.player_3.name,
                             loser=self.player_4.name)

        player_aliases = [p.name for p in self.players]
        matches = [match_1, match_2]
        pending_tournament = PendingTournament(
            name=self.name,
            type=self.type,
            date=self.date,
            raw_id=self.raw_id,
            regions=['norcal'],
            players=player_aliases,
            matches=matches,
            alias_to_id_map=self.alias_to_id_map)

        tournament = Tournament.from_pending_tournament(pending_tournament)

        self.assertIsNone(tournament.id)
        self.assertEqual(tournament.type, self.type)
        self.assertEqual(tournament.raw_id, self.raw_id)
        self.assertEqual(tournament.date, self.date)
        self.assertEqual(tournament.name, self.name)
        self.assertEqual(tournament.matches[0].winner, self.matches[0].winner)
        self.assertEqual(tournament.matches[0].loser, self.matches[0].loser)
        self.assertEqual(tournament.matches[1].winner, self.matches[1].winner)
        self.assertEqual(tournament.matches[1].loser, self.matches[1].loser)
        self.assertEqual(tournament.players, self.player_ids)
        self.assertEqual(tournament.regions, ['norcal'])
Example #4
0
    def test_from_pending_tournament(self):
        # we need MatchResults with aliases (instead of IDs)
        match_1 = AliasMatch(winner=self.player_1.name,
                             loser=self.player_2.name)
        match_2 = AliasMatch(winner=self.player_3.name,
                             loser=self.player_4.name)

        player_aliases = [p.name for p in self.players]
        matches = [match_1, match_2]
        pending_tournament = PendingTournament(
            name=self.name,
            type=self.type,
            date=self.date,
            raw_id=self.raw_id,
            regions=['norcal'],
            players=player_aliases,
            matches=matches,
            alias_to_id_map=self.alias_to_id_map)

        tournament = Tournament.from_pending_tournament(pending_tournament)

        self.assertIsNone(tournament.id)
        self.assertEqual(tournament.type, self.type)
        self.assertEqual(tournament.raw_id, self.raw_id)
        self.assertEqual(tournament.date, self.date)
        self.assertEqual(tournament.name, self.name)
        self.assertEqual(tournament.matches[0].winner, self.matches[0].winner)
        self.assertEqual(tournament.matches[0].loser, self.matches[0].loser)
        self.assertEqual(tournament.matches[1].winner, self.matches[1].winner)
        self.assertEqual(tournament.matches[1].loser, self.matches[1].loser)
        self.assertEqual(tournament.players, self.player_ids)
        self.assertEqual(tournament.regions, ['norcal'])
Example #5
0
    def post(self, region, id):
        dao = Dao(region, mongo_client=mongo_client)

        pending_tournament = dao.get_pending_tournament_by_id(ObjectId(id))
        if not pending_tournament:
            return 'No pending tournament found with that id.', 400
        user = get_user_from_request(request, dao)
        if not user:
            return 'Permission denied', 403
        if not is_user_admin_for_regions(user, pending_tournament.regions):
            return 'Permission denied', 403

        new_player_names = []
        for mapping in pending_tournament.alias_to_id_map:
            if mapping["player_id"] == None:
                new_player_names.append(mapping["player_alias"])

        for player_name in new_player_names:
            player = Player.create_with_default_values(player_name, region)
            player_id = dao.insert_player(player)
            pending_tournament.set_alias_id_mapping(player_name, player_id)

        dao.update_pending_tournament(pending_tournament)

        try:
            tournament = Tournament.from_pending_tournament(pending_tournament)
            tournament_id = dao.insert_tournament(tournament)
            dao.delete_pending_tournament(pending_tournament)
            return {"success": True, "tournament_id": str(tournament_id)}
        except ValueError:
            return 'Not all player aliases in this pending tournament have been mapped to player ids.', 400
Example #6
0
    def post(self, region, id):
        dao = Dao(region, mongo_client=mongo_client)

        pending_tournament = dao.get_pending_tournament_by_id(ObjectId(id))
        if not pending_tournament:
            return 'No pending tournament found with that id.', 400
        user = get_user_from_request(request, dao)
        if not user:
            return 'Permission denied', 403
        if not is_user_admin_for_region(user, pending_tournament.regions):
            return 'Permission denied', 403

        new_player_names = []
        for mapping in pending_tournament.alias_to_id_map:
            if mapping["player_id"] == None:
                new_player_names.append(mapping["player_alias"])

        for player_name in new_player_names:
            player = Player.create_with_default_values(player_name, region)
            player_id = dao.insert_player(player)
            pending_tournament.set_alias_id_mapping(player_name, player_id)

        dao.update_pending_tournament(pending_tournament)
        
        try:
            tournament = Tournament.from_pending_tournament(pending_tournament)
            tournament_id = dao.insert_tournament(tournament)
            dao.delete_pending_tournament(pending_tournament)
            return {"success": True, "tournament_id": str(tournament_id)}
        except ValueError:
            return 'Not all player aliases in this pending tournament have been mapped to player ids.', 400