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


Python Dao.insert_player方法代码示例

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


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

示例1: post

# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import insert_player [as 别名]
    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
开发者ID:acoulon99,项目名称:garpr,代码行数:33,代码来源:server.py

示例2: post

# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import insert_player [as 别名]
    def post(self, region, id):
        print "finalize tournament post"
        dao = Dao(region, mongo_client=mongo_client)
        if not dao:
            return 'Dao not found', 404
        pending_tournament = None
        try:
            pending_tournament = dao.get_pending_tournament_by_id(ObjectId(id))
        except:
            return 'Invalid ObjectID', 400
        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

        # Make sure multiple player aliases don't map to a single player ID.
        player_ids = set()
        for mapping in pending_tournament.alias_to_id_map:
            if mapping.player_id is not None:
                if mapping.player_id in player_ids:
                    return "Player id %s is already mapped" % mapping.player_id, 400
                else:
                    player_ids.add(mapping.player_id)

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

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

        # validate players in this tournament
        for mapping in pending_tournament.alias_to_id_map:
            try:
                player_id = mapping.player_id
                # TODO: reduce queries to DB by batching
                player = dao.get_player_by_id(player_id)
                if player.merged:
                    return "Player {} has already been merged".format(player.name), 400
            except:
                return "Not all player ids are valid", 400

        try:
            dao.update_pending_tournament(pending_tournament)
            tournament = M.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 as e:
            print e
            return 'Not all player aliases in this pending tournament have been mapped to player ids.', 400
        except:
            return 'Dao threw an error somewhere', 400
开发者ID:garsh0p,项目名称:garpr,代码行数:62,代码来源:server.py

示例3: TestRankings

# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import insert_player [as 别名]
class TestRankings(unittest.TestCase):
    def setUp(self):
        self.region_id = 'norcal'
        self.region = Region(id=self.region_id,
                             display_name='Norcal')

        self.mongo_client = mongomock.MongoClient()
        Dao.insert_region(self.region, self.mongo_client)

        self.dao = Dao(self.region_id, mongo_client=self.mongo_client)

        self.player_1_id = ObjectId()
        self.player_2_id = ObjectId()
        self.player_3_id = ObjectId()
        self.player_4_id = ObjectId()
        self.player_5_id = ObjectId()
        self.player_1 = Player(
                name='gaR',
                aliases=['gar', 'garr'],
                ratings={'norcal': Rating(), 'texas': Rating()},
                regions=['norcal', 'texas'],
                id=self.player_1_id)
        self.player_2 = Player(
                name='sfat',
                aliases=['sfat', 'miom | sfat'],
                ratings={'norcal': Rating()},
                regions=['norcal'],
                id=self.player_2_id)
        self.player_3 = Player(
                name='mango',
                aliases=['mango'],
                ratings={'norcal': Rating(mu=2, sigma=3)},
                regions=['socal'],
                id=self.player_3_id)
        self.player_4 = Player(
                name='shroomed',
                aliases=['shroomed'],
                ratings={'norcal': Rating()},
                regions=['norcal'],
                id=self.player_4_id)
        self.player_5 = Player(
                name='pewpewu',
                aliases=['pewpewu'],
                ratings={'norcal': Rating()},
                regions=['norcal'],
                id=self.player_5_id)

        self.players = [self.player_1, self.player_2, self.player_3, self.player_4, self.player_5]

        self.tournament_id_1 = ObjectId()
        self.tournament_type_1 = 'tio'
        self.tournament_raw_1 = 'raw1'
        self.tournament_date_1 = datetime(2013, 10, 16)
        self.tournament_name_1 = 'tournament 1'
        self.tournament_players_1 = [self.player_1_id, self.player_2_id, self.player_3_id, self.player_4_id]
        self.tournament_matches_1 = [
                Match(winner=self.player_1_id, loser=self.player_2_id),
                Match(winner=self.player_3_id, loser=self.player_4_id)
        ]
        self.tournament_regions_1 = ['norcal']

        # tournament 2 is earlier than tournament 1, but inserted after
        self.tournament_id_2 = ObjectId()
        self.tournament_type_2 = 'challonge'
        self.tournament_raw_2 = 'raw2'
        self.tournament_date_2 = datetime(2013, 10, 10)
        self.tournament_name_2 = 'tournament 2'
        self.tournament_players_2 = [self.player_5_id, self.player_2_id, self.player_3_id, self.player_4_id]
        self.tournament_matches_2 = [
                Match(winner=self.player_5_id, loser=self.player_2_id),
                Match(winner=self.player_3_id, loser=self.player_4_id)
        ]
        self.tournament_regions_2 = ['norcal', 'texas']

        self.tournament_1 = Tournament(
                    type=self.tournament_type_1,
                    raw=self.tournament_raw_1,
                    date=self.tournament_date_1,
                    name=self.tournament_name_1,
                    players=self.tournament_players_1,
                    matches=self.tournament_matches_1,
                    regions=self.tournament_regions_1,
                    id=self.tournament_id_1)

        self.tournament_2 = Tournament(
                    type=self.tournament_type_2,
                    raw=self.tournament_raw_2,
                    date=self.tournament_date_2,
                    name=self.tournament_name_2,
                    players=self.tournament_players_2,
                    matches=self.tournament_matches_2,
                    regions=self.tournament_regions_2,
                    id=self.tournament_id_2)

        self.tournament_ids = [self.tournament_id_1, self.tournament_id_2]
        self.tournaments = [self.tournament_1, self.tournament_2]

        for player in self.players:
            self.dao.insert_player(player)

#.........这里部分代码省略.........
开发者ID:BrandonCookeDev,项目名称:garpr,代码行数:103,代码来源:test_rankings.py

示例4: TestDAO

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

#.........这里部分代码省略.........
        self.ranking_time_1 = datetime(2013, 4, 20)
        self.ranking_time_2 = datetime(2013, 4, 21)
        self.ranking_1 = Ranking('norcal', self.ranking_time_1, self.tournament_ids, 
                                 [self.ranking_entry_1, self.ranking_entry_2, self.ranking_entry_3])
        self.ranking_2 = Ranking('norcal', self.ranking_time_2, self.tournament_ids, 
                                 [self.ranking_entry_1, self.ranking_entry_2, self.ranking_entry_4])
        self.ranking_3 = Ranking('texas', self.ranking_time_2, self.tournament_ids, 
                                 [self.ranking_entry_1, self.ranking_entry_2])

        self.rankings = [self.ranking_1, self.ranking_2, self.ranking_3]

        self.user_id_1 = 'abc123'
        self.user_admin_regions_1 = ['norcal', 'texas']
        self.user_1 = User(self.user_id_1, self.user_admin_regions_1)

        self.user_id_2 = 'asdfasdf'
        self.user_full_name_2 = 'Full Name'
        self.user_admin_regions_2 = []
        self.user_2 = User(self.user_id_2, self.user_admin_regions_2, full_name=self.user_full_name_2)

        self.users = [self.user_1, self.user_2]

        self.region_1 = Region('norcal', 'Norcal')
        self.region_2 = Region('texas', 'Texas')

        self.regions = [self.region_1, self.region_2]

        for region in self.regions:
            Dao.insert_region(region, self.mongo_client, database_name=DATABASE_NAME)

        self.norcal_dao = Dao('norcal', self.mongo_client, database_name=DATABASE_NAME)

        for player in self.players:
            self.norcal_dao.insert_player(player)

        for tournament in self.tournaments:
            self.norcal_dao.insert_tournament(tournament)

        for pending_tournament in self.pending_tournaments:
            self.norcal_dao.insert_pending_tournament(pending_tournament)

        for ranking in self.rankings:
            self.norcal_dao.insert_ranking(ranking)

        for user in self.users:
            self.norcal_dao.insert_user(user)

    def tearDown(self):
        self.mongo_client.drop_database(DATABASE_NAME)

    def test_init_with_invalid_region(self):
        # create a dao with an existing region
        Dao('norcal', self.mongo_client, database_name=DATABASE_NAME)

        # create a dao with a new region
        with self.assertRaises(RegionNotFoundException):
            Dao('newregion', self.mongo_client, database_name=DATABASE_NAME)

    def test_get_all_regions(self):
        # add another region
        region = Region('newregion', 'New Region')
        Dao.insert_region(region, self.mongo_client, database_name=DATABASE_NAME)

        regions = Dao.get_all_regions(self.mongo_client, database_name=DATABASE_NAME)
        self.assertEquals(len(regions), 3)
        self.assertEquals(regions[0], region)
开发者ID:MrMonacle,项目名称:garpr,代码行数:70,代码来源:test_dao.py

示例5: TestDAO

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

#.........这里部分代码省略.........
                           admin_regions=self.user_admin_regions_2,
                           username=self.user_full_name_2,
                           salt='nacl',
                           hashed_password='browns',
                           admin_level='REGION')

        self.superadmin_id = '123456'
        self.superadmin_full_name = 'superadmin'
        self.superadmin_admin_regions = []
        self.superadmin = User(
            id=self.superadmin_id,
            user_admin_regions=self.superadmin_admin_regions,
            username=self.superadmin_full_name,
            salt='nacl',
            hashed_password='browns',
            admin_level='SUPER'
        )

        self.users = [self.user_1, self.user_2, self.superadmin]

        self.region_1 = Region(id='norcal', display_name='Norcal')
        self.region_2 = Region(id='texas', display_name='Texas')

        self.regions = [self.region_1, self.region_2]

        for region in self.regions:
            Dao.insert_region(region, self.mongo_client,
                              database_name=DATABASE_NAME)

        self.norcal_dao = Dao('norcal', self.mongo_client,
                              database_name=DATABASE_NAME)

        for player in self.players:
            self.norcal_dao.insert_player(player)

        for tournament in self.tournaments:
            self.norcal_dao.insert_tournament(tournament)

        for pending_tournament in self.pending_tournaments:
            self.norcal_dao.insert_pending_tournament(pending_tournament)

        for ranking in self.rankings:
            self.norcal_dao.insert_ranking(ranking)

        for user in self.users:
            self.norcal_dao.insert_user(user)



    def tearDown(self):
        self.mongo_client.drop_database(DATABASE_NAME)

    def test_init_with_invalid_region(self):
        # create a dao with an existing region
        Dao('norcal', self.mongo_client, database_name=DATABASE_NAME)

        # create a dao with a non existant region, should return none
        self.assertIsNone(Dao('newregion', self.mongo_client,
                              database_name=DATABASE_NAME))

    def test_get_all_regions(self):
        # add another region
        region = Region(id='newregion', display_name='New Region')
        Dao.insert_region(region, self.mongo_client,
                          database_name=DATABASE_NAME)
开发者ID:BrandonCookeDev,项目名称:garpr,代码行数:69,代码来源:test_dao.py

示例6: TestAliasService

# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import insert_player [as 别名]
class TestAliasService(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        config = ConfigParser()
        config.read(CONFIG_LOCATION)
        username = config.get('database', 'user')
        host = config.get('database', 'host')
        auth_db = config.get('database', 'auth_db')
        password = config.get('database', 'password')
        self.mongo_client = MongoClient(host='mongodb://%s:%[email protected]%s/%s' % (username, password, host, auth_db))
        self.mongo_client.drop_database(DATABASE_NAME)

    def setUp(self):
        self.maxDiff = None

        self.player_1_id = ObjectId()
        self.player_2_id = ObjectId()
        self.player_3_id = ObjectId()
        self.player_4_id = ObjectId()
        self.player_5_id = ObjectId()
        self.player_1 = Player(
                name='gaR',
                aliases=['gar', 'garr'],
                ratings={'norcal': Rating(), 'texas': Rating()},
                regions=['norcal', 'texas'],
                id=self.player_1_id)
        self.player_2 = Player(
                name='sfat',
                aliases=['sfat', 'miom | sfat'],
                ratings={'norcal': Rating()},
                regions=['norcal'],
                id=self.player_2_id)
        self.player_3 = Player(
                name='mango',
                aliases=['mango', 'gar'],
                ratings={'norcal': Rating(mu=2, sigma=3)},
                regions=['socal'],
                id=self.player_3_id)
        self.player_4 = Player(
                name='garpr|gar',
                aliases=['garpr|gar'],
                ratings={'norcal': Rating(mu=2, sigma=3)},
                regions=['norcal'],
                id=self.player_4_id)

        self.players = [self.player_1, self.player_2, self.player_3, self.player_4]

        self.user_id_1 = 'abc123'
        self.user_admin_regions_1 = ['norcal']
        self.username1 = 'Full Name'
        #    def __init__(self, id, admin_regions, username, salt, hashed_password):
        self.user_1 = User(id=self.user_id_1,
                           admin_regions=self.user_admin_regions_1,
                           username=self.username1,
                           salt='nacl',
                           hashed_password='browns')

        self.users = [self.user_1]

        self.region_1 = Region(id='norcal', display_name='Norcal')
        Dao.insert_region(self.region_1, self.mongo_client, database_name=DATABASE_NAME)
        self.norcal_dao = Dao('norcal', self.mongo_client, database_name=DATABASE_NAME)

        for player in self.players:
            self.norcal_dao.insert_player(player)


    def tearDown(self):
        self.mongo_client.drop_database(DATABASE_NAME)

    def test_get_player_suggestions_from_player_aliases(self):
        self.assertEquals(alias_service.get_player_suggestions_from_player_aliases(self.norcal_dao, ['gar', 'garpr | gar', 'g a r r']),
            {
                "gar": [self.player_1, self.player_3],
                "garpr | gar": [self.player_1, self.player_3, self.player_4],
                "g a r r": [self.player_1]
            })

    def test_get_player_or_suggestions_from_player_aliases(self):
        self.assertEquals(alias_service.get_player_or_suggestions_from_player_aliases(self.norcal_dao, ['gar', 'garpr | gar', 'g a r r']),
            {
                "gar": {
                    "player": self.player_1,
                    "suggestions": [self.player_1, self.player_3]
                },
                "garpr | gar": {
                    "player": None,
                    "suggestions": [self.player_1, self.player_3, self.player_4],
                },
                "g a r r": {
                    "player": None,
                    "suggestions": [self.player_1]
                }
            })

    def test_get_top_suggestion_for_aliases(self):
        suggestions = alias_service.get_top_suggestion_for_aliases(self.norcal_dao, ['gar', 'garpr | gar'])
        expected_suggestions = {
            "gar": self.player_1,
            "garpr | gar": self.player_1,
#.........这里部分代码省略.........
开发者ID:BrandonCookeDev,项目名称:garpr,代码行数:103,代码来源:test_alias_service.py

示例7: TestAliasService

# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import insert_player [as 别名]
class TestAliasService(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        MongoClient().drop_database(DATABASE_NAME)

    def setUp(self):
        self.maxDiff = None
        self.mongo_client = MongoClient()

        self.player_1_id = ObjectId()
        self.player_2_id = ObjectId()
        self.player_3_id = ObjectId()
        self.player_4_id = ObjectId()
        self.player_5_id = ObjectId()
        self.player_1 = Player(
                'gaR', 
                ['gar', 'garr'], 
                {'norcal': TrueskillRating(), 'texas': TrueskillRating()}, 
                ['norcal', 'texas'], 
                id=self.player_1_id)
        self.player_2 = Player(
                'sfat', 
                ['sfat', 'miom | sfat'], 
                {'norcal': TrueskillRating()}, 
                ['norcal'], 
                id=self.player_2_id)
        self.player_3 = Player(
                'mango', 
                ['mango', 'gar'], 
                {'norcal': TrueskillRating(trueskill_rating=trueskill.Rating(mu=2, sigma=3))}, 
                ['socal'], 
                id=self.player_3_id)
        self.player_4 = Player(
                'garpr|gar', 
                ['garpr|gar'], 
                {'norcal': TrueskillRating(trueskill_rating=trueskill.Rating(mu=2, sigma=3))}, 
                ['norcal'], 
                id=self.player_4_id)

        self.players = [self.player_1, self.player_2, self.player_3, self.player_4]

        self.user_id_1 = 'abc123'
        self.user_full_name_1 = 'Full Name'
        self.user_admin_regions_1 = ['norcal']
        self.user_1 = User(self.user_id_1, self.user_admin_regions_1, full_name=self.user_full_name_1)

        self.users = [self.user_1]

        self.region_1 = Region('norcal', 'Norcal')
        Dao.insert_region(self.region_1, self.mongo_client, database_name=DATABASE_NAME)
        self.norcal_dao = Dao('norcal', self.mongo_client, database_name=DATABASE_NAME)

        for player in self.players:
            self.norcal_dao.insert_player(player)

        for user in self.users:
            self.norcal_dao.insert_user(user)

    def tearDown(self):
        self.mongo_client.drop_database(DATABASE_NAME)

    def test_get_player_suggestions_from_player_aliases(self):
        self.assertEquals(alias_service.get_player_suggestions_from_player_aliases(self.norcal_dao, ['gar', 'garpr | gar', 'g a r r']), 
            {
                "gar": [self.player_1, self.player_3],
                "garpr | gar": [self.player_1, self.player_3, self.player_4],
                "g a r r": [self.player_1]
            })

    def test_get_player_or_suggestions_from_player_aliases(self):
        self.assertEquals(alias_service.get_player_or_suggestions_from_player_aliases(self.norcal_dao, ['gar', 'garpr | gar', 'g a r r']), 
            {
                "gar": {
                    "player": self.player_1,
                    "suggestions": [self.player_1, self.player_3]
                },
                "garpr | gar": {
                    "player": None,
                    "suggestions": [self.player_1, self.player_3, self.player_4],
                },
                "g a r r": {
                    "player": None,
                    "suggestions": [self.player_1]
                }
            })

    def test_get_top_suggestion_for_aliases(self):
        suggestions = alias_service.get_top_suggestion_for_aliases(self.norcal_dao, ['gar', 'garpr | gar'])
        expected_suggestions = {
            "gar": self.player_1,
            "garpr | gar": self.player_1,
        }

        self.assertEquals(suggestions, expected_suggestions)

    def test_get_top_suggestion_for_aliases_none(self):
        suggestions = alias_service.get_top_suggestion_for_aliases(self.norcal_dao, ['gar', 'garpr | gar', 'ASDFASDF'])
        expected_suggestions = {
            "gar": self.player_1,
            "garpr | gar": self.player_1,
#.........这里部分代码省略.........
开发者ID:MrMonacle,项目名称:garpr,代码行数:103,代码来源:test_alias_service.py


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