当前位置: 首页>>代码示例>>Python>>正文


Python Dao.update_tournament方法代码示例

本文整理汇总了Python中dao.Dao.update_tournament方法的典型用法代码示例。如果您正苦于以下问题:Python Dao.update_tournament方法的具体用法?Python Dao.update_tournament怎么用?Python Dao.update_tournament使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dao.Dao的用法示例。


在下文中一共展示了Dao.update_tournament方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: delete

# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import update_tournament [as 别名]
    def delete(self, region, id, region_to_change):
        dao = Dao(region, mongo_client=mongo_client)
        user = get_user_from_access_token(request.headers, dao)
        if not is_user_admin_for_region(user, region_to_change):
            return 'Permission denied', 403

        tournament = dao.get_tournament_by_id(ObjectId(id))
        if region_to_change in tournament.regions:
            tournament.regions.remove(region_to_change)
            dao.update_tournament(tournament)

        return convert_tournament_to_response(dao.get_tournament_by_id(tournament.id), dao)
开发者ID:MrMonacle,项目名称:garpr,代码行数:14,代码来源:server.py

示例2: put

# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import update_tournament [as 别名]
    def put(self, region, id, region_to_change):
        dao = Dao(region, mongo_client=mongo_client)
        user = get_user_from_request(request, dao)
        if not user:
            return 'Permission denied', 403
        if not is_user_admin_for_region(user, region_to_change):
            return 'Permission denied', 403

        tournament = dao.get_tournament_by_id(ObjectId(id))
        if not region_to_change in tournament.regions:
            tournament.regions.append(region_to_change)
            dao.update_tournament(tournament)

        return convert_tournament_to_response(dao.get_tournament_by_id(tournament.id), dao)
开发者ID:acoulon99,项目名称:garpr,代码行数:16,代码来源:server.py

示例3: TestDAO

# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import update_tournament [as 别名]

#.........这里部分代码省略.........
        pending_tournament_1 = self.norcal_dao.get_pending_tournament_by_id(self.pending_tournament_id_1)
        self.assertEquals(pending_tournament_1.id, self.pending_tournament_id_1)
        self.assertEquals(pending_tournament_1.type, self.pending_tournament_type_1)
        self.assertEquals(pending_tournament_1.raw, self.pending_tournament_raw_1)
        self.assertEquals(pending_tournament_1.date, self.pending_tournament_date_1)
        self.assertEquals(pending_tournament_1.name, self.pending_tournament_name_1)
        self.assertEquals(pending_tournament_1.matches, self.pending_tournament_matches_1)
        self.assertEquals(pending_tournament_1.players, self.pending_tournament_players_1)
        self.assertEquals(pending_tournament_1.regions, self.pending_tournament_regions_1)

        pending_tournament_1_raw_new = 'asdfasdf'
        pending_tournament_1_name_new = 'new pending tournament name'

        pending_tournament_1.raw = pending_tournament_1_raw_new
        pending_tournament_1.name = pending_tournament_1_name_new

        self.norcal_dao.update_pending_tournament(pending_tournament_1)

        pending_tournament_1 = self.norcal_dao.get_pending_tournament_by_id(self.pending_tournament_id_1)
        self.assertEquals(pending_tournament_1.id, self.pending_tournament_id_1)
        self.assertEquals(pending_tournament_1.type, self.pending_tournament_type_1)
        self.assertEquals(pending_tournament_1.raw, pending_tournament_1_raw_new)
        self.assertEquals(pending_tournament_1.date, self.pending_tournament_date_1)
        self.assertEquals(pending_tournament_1.name, pending_tournament_1_name_new)
        self.assertEquals(pending_tournament_1.matches, self.pending_tournament_matches_1)
        self.assertEquals(pending_tournament_1.players, self.pending_tournament_players_1)
        self.assertEquals(pending_tournament_1.regions, self.pending_tournament_regions_1)

    def test_update_pending_tournament_empty_raw(self):
        pending_tournament = self.norcal_dao.get_pending_tournament_by_id(self.pending_tournament_id_1)
        pending_tournament.raw = ''

        with self.assertRaises(UpdateTournamentException):
            self.norcal_dao.update_tournament(pending_tournament)

    def test_get_all_pending_tournaments(self):
        pending_tournaments = self.norcal_dao.get_all_pending_tournaments()

        self.assertEquals(len(pending_tournaments), 1)

        pending_tournament = pending_tournaments[0]
        self.assertEquals(pending_tournament.id, self.pending_tournament_id_1)
        self.assertEquals(pending_tournament.type, self.pending_tournament_type_1)
        self.assertEquals(pending_tournament.raw, '')
        self.assertEquals(pending_tournament.date, self.pending_tournament_date_1)
        self.assertEquals(pending_tournament.name, self.pending_tournament_name_1)
        self.assertEquals(pending_tournament.matches, self.pending_tournament_matches_1)
        self.assertEquals(pending_tournament.players, self.pending_tournament_players_1)
        self.assertEquals(pending_tournament.regions, self.pending_tournament_regions_1)

    def test_get_all_pending_tournaments_for_region(self):
        pending_tournaments = self.norcal_dao.get_all_pending_tournaments(regions=['norcal'])

        self.assertEquals(len(pending_tournaments), 1)

        pending_tournament = pending_tournaments[0]
        self.assertEquals(pending_tournament.id, self.pending_tournament_id_1)
        self.assertEquals(pending_tournament.type, self.pending_tournament_type_1)
        self.assertEquals(pending_tournament.raw, '')
        self.assertEquals(pending_tournament.date, self.pending_tournament_date_1)
        self.assertEquals(pending_tournament.name, self.pending_tournament_name_1)
        self.assertEquals(pending_tournament.matches, self.pending_tournament_matches_1)
        self.assertEquals(pending_tournament.players, self.pending_tournament_players_1)
        self.assertEquals(pending_tournament.regions, self.pending_tournament_regions_1)

    def test_get_pending_tournament_by_id(self):
开发者ID:MrMonacle,项目名称:garpr,代码行数:70,代码来源:test_dao.py

示例4: TestDAO

# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import update_tournament [as 别名]

#.........这里部分代码省略.........
        self.assertEquals(self.dao.get_player_by_id(self.player_1_id).aliases, old_expected_aliases)
        self.assertEquals(self.player_1.aliases, old_expected_aliases)
        self.dao.add_alias_to_player(self.player_1, new_alias)
        self.assertEquals(self.dao.get_player_by_id(self.player_1_id).aliases, new_expected_aliases)
        self.assertEquals(self.player_1.aliases, new_expected_aliases)

    def test_add_alias_to_player_duplicate(self):
        with self.assertRaises(DuplicateAliasException):
            self.dao.add_alias_to_player(self.player_1, 'garr')

    def test_update_player_name(self):
        self.assertEquals(self.dao.get_player_by_id(self.player_1_id).name, 'gaR')
        self.assertEquals(self.player_1.name, 'gaR')
        self.dao.update_player_name(self.player_1, 'gaRR')
        self.assertEquals(self.dao.get_player_by_id(self.player_1_id).name, 'gaRR')
        self.assertEquals(self.player_1.name, 'gaRR')

    def test_update_player_name_non_alias(self):
        with self.assertRaises(InvalidNameException):
            self.dao.update_player_name(self.player_1, 'asdf')

    def test_reset_all_player_ratings(self):
        self.assertEquals(self.dao.get_player_by_id(self.player_1_id).rating, TrueskillRating())
        self.assertEquals(self.dao.get_player_by_id(self.player_2_id).rating, TrueskillRating())
        self.assertEquals(self.dao.get_player_by_id(self.player_3_id).rating, 
                          TrueskillRating(trueskill_rating=trueskill.Rating(mu=2, sigma=3)))

        self.dao.reset_all_player_ratings()

        self.assertEquals(self.dao.get_player_by_id(self.player_1_id).rating, TrueskillRating())
        self.assertEquals(self.dao.get_player_by_id(self.player_2_id).rating, TrueskillRating())
        self.assertEquals(self.dao.get_player_by_id(self.player_3_id).rating, TrueskillRating())

    def test_update_tournament(self):
        tournament_1 = self.dao.get_tournament_by_id(self.tournament_id_1)
        self.assertEquals(tournament_1.id, self.tournament_id_1)
        self.assertEquals(tournament_1.type, self.tournament_type_1)
        self.assertEquals(tournament_1.raw, self.tournament_raw_1)
        self.assertEquals(tournament_1.date, self.tournament_date_1)
        self.assertEquals(tournament_1.name, self.tournament_name_1)
        self.assertEquals(tournament_1.matches, self.tournament_matches_1)
        self.assertEquals(tournament_1.players, self.tournament_players_1)

        tournament_2 = self.dao.get_tournament_by_id(self.tournament_id_2)
        self.assertEquals(tournament_2.id, self.tournament_id_2)
        self.assertEquals(tournament_2.type, self.tournament_type_2)
        self.assertEquals(tournament_2.raw, self.tournament_raw_2)
        self.assertEquals(tournament_2.date, self.tournament_date_2)
        self.assertEquals(tournament_2.name, self.tournament_name_2)
        self.assertEquals(tournament_2.matches, self.tournament_matches_2)
        self.assertEquals(tournament_2.players, self.tournament_players_2)

        tournament_2_raw_new = 'asdfasdf'
        tournament_2_name_new = 'new tournament 2 name'

        tournament_2.raw = tournament_2_raw_new
        tournament_2.name = tournament_2_name_new

        self.dao.update_tournament(tournament_2)

        tournament_1 = self.dao.get_tournament_by_id(self.tournament_id_1)
        self.assertEquals(tournament_1.id, self.tournament_id_1)
        self.assertEquals(tournament_1.type, self.tournament_type_1)
        self.assertEquals(tournament_1.raw, self.tournament_raw_1)
        self.assertEquals(tournament_1.date, self.tournament_date_1)
        self.assertEquals(tournament_1.name, self.tournament_name_1)
开发者ID:novacourtois,项目名称:garpr,代码行数:70,代码来源:test_dao.py

示例5: TestDAO

# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import update_tournament [as 别名]

#.........这里部分代码省略.........
                          self.pending_tournament_matches_1)
        self.assertEquals(pending_tournament.players,
                          self.pending_tournament_players_1)
        self.assertEquals(pending_tournament.regions,
                          self.pending_tournament_regions_1)

    def test_get_pending_tournament_by_id(self):
        pending_tournament = self.norcal_dao.get_pending_tournament_by_id(
            self.pending_tournament_id_1)
        self.assertEquals(pending_tournament.id, self.pending_tournament_id_1)
        self.assertEquals(pending_tournament.type,
                          self.pending_tournament_type_1)
        self.assertEquals(pending_tournament.date,
                          self.pending_tournament_date_1)
        self.assertEquals(pending_tournament.name,
                          self.pending_tournament_name_1)
        self.assertEquals(pending_tournament.matches,
                          self.pending_tournament_matches_1)
        self.assertEquals(pending_tournament.players,
                          self.pending_tournament_players_1)
        self.assertEquals(pending_tournament.regions,
                          self.pending_tournament_regions_1)

        self.assertIsNone(self.norcal_dao.get_tournament_by_id(ObjectId()))

    def test_delete_pending_tournament(self):
        pending_tournament = self.norcal_dao.get_pending_tournament_by_id(
            self.pending_tournament_id_1)
        self.norcal_dao.delete_pending_tournament(pending_tournament)
        deleted_tournament = self.norcal_dao.get_pending_tournament_by_id(
            self.pending_tournament_id_1)
        self.assertIsNone(deleted_tournament)

    def test_update_tournament(self):
        tournament_1 = self.norcal_dao.get_tournament_by_id(
            self.tournament_id_1)
        self.assertEquals(tournament_1.id, self.tournament_id_1)
        self.assertEquals(tournament_1.type, self.tournament_type_1)
        self.assertEquals(tournament_1.date, self.tournament_date_1)
        self.assertEquals(tournament_1.name, self.tournament_name_1)
        self.assertEquals(tournament_1.matches, self.tournament_matches_1)
        self.assertEquals(tournament_1.players, self.tournament_players_1)
        self.assertEquals(tournament_1.regions, self.tournament_regions_1)

        tournament_2 = self.norcal_dao.get_tournament_by_id(
            self.tournament_id_2)
        self.assertEquals(tournament_2.id, self.tournament_id_2)
        self.assertEquals(tournament_2.type, self.tournament_type_2)
        self.assertEquals(tournament_2.date, self.tournament_date_2)
        self.assertEquals(tournament_2.name, self.tournament_name_2)
        self.assertEquals(tournament_2.matches, self.tournament_matches_2)
        self.assertEquals(tournament_2.players, self.tournament_players_2)
        self.assertEquals(tournament_2.regions, self.tournament_regions_2)

        tournament_2_name_new = 'new tournament 2 name'

        tournament_2.name = tournament_2_name_new

        self.norcal_dao.update_tournament(tournament_2)

        tournament_1 = self.norcal_dao.get_tournament_by_id(
            self.tournament_id_1)
        self.assertEquals(tournament_1.id, self.tournament_id_1)
        self.assertEquals(tournament_1.type, self.tournament_type_1)
        self.assertEquals(tournament_1.date, self.tournament_date_1)
        self.assertEquals(tournament_1.name, self.tournament_name_1)
开发者ID:BrandonCookeDev,项目名称:garpr,代码行数:70,代码来源:test_dao.py

示例6: put

# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import update_tournament [as 别名]
    def put(self, region, id):
        dao = Dao(region, mongo_client=mongo_client)
        if not dao:
            return 'Dao not found', 404
        tournament = None

        args = tournament_put_parser.parse_args()

        try:
            if args['pending']:
                tournament = dao.get_pending_tournament_by_id(ObjectId(id))
            else:
                tournament = dao.get_tournament_by_id(ObjectId(id))
        except:
            return 'Invalid ObjectID', 400
        if not tournament:
            return "No tournament found with that id.", 404

        # TODO auth for this needs to be different, otherwise an admin can tag
        # with their region and then edit everything
        user = get_user_from_request(request, dao)
        if not user:
            return 'Permission denied', 403
        if not is_user_admin_for_regions(user, tournament.regions):
            return 'Permission denied', 403

        if args['name']:
            tournament.name = args['name']
        if args['date']:
            try:
                tournament.date = datetime.strptime(
                    args['date'].strip(), '%m/%d/%y')
            except:
                return "Invalid date format", 400
        if args['players']:
            # this should rarely be used (if it is used, players will not unmerge reliably)
            for p in args['players']:
                if not isinstance(p, dict):
                    return "each player must be a dict", 400
            tournament.players = [ObjectId(p['id']) for p in args['players']]
            tournament.orig_ids = [pid for pid in tournament.players]
        if args['matches']:
            for m in args['matches']:
                if not isinstance(m, dict):
                    return "matches must be a dict", 400
                if (not isinstance(m['winner_id'], unicode) or
                    not isinstance(m['winner_name'], unicode) or
                    not isinstance(m['loser_id'], unicode) or
                    not isinstance(m['loser_name'], unicode) or
                    not isinstance(m['excluded'], bool) or
                    not isinstance(m['match_id'], int)):
                    return "invalid arguments for match", 400
            # turn the list of dicts into list of matchresults
            matches = [
                M.Match(
                    winner=ObjectId(m['winner_id']),
                    loser=ObjectId(m['loser_id']),
                    match_id=m['match_id'],
                    excluded=m['excluded'])
                for m in args['matches']]
            tournament.matches = matches
        if args['regions']:
            for p in args['regions']:
                if not isinstance(p, unicode):
                    return "each region must be a string", 400
            tournament.regions = args['regions']

        if args['pending']:
            dao.update_pending_tournament(tournament)
        else:
            print tournament
            dao.update_tournament(tournament)

        if args['pending']:
            return dao.get_pending_tournament_by_id(tournament.id).dump(context='web')
        else:
            return convert_tournament_to_response(dao.get_tournament_by_id(tournament.id), dao)
开发者ID:garsh0p,项目名称:garpr,代码行数:79,代码来源:server.py


注:本文中的dao.Dao.update_tournament方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。