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


Python Dao.delete_player方法代码示例

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


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

示例1: delete

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

        try:
            player = dao.get_player_by_id(ObjectId(id))
        except:
            return 'Invalid ObjectID', 400
        if not player:
            return "No player found with that region/id.", 404

        if not is_user_admin_for_regions(user, player.regions):
            return 'Permission denied', 403

        if dao.get_all_tournaments(players=[player]):
            return 'Player still has matches', 400

        dao.delete_player(player)
        return {"success": True}
开发者ID:garsh0p,项目名称:garpr,代码行数:25,代码来源:server.py

示例2: TestDAO

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

#.........这里部分代码省略.........

    def test_get_players_by_alias_from_all_regions(self):
        self.assertEquals(self.norcal_dao.get_players_by_alias_from_all_regions('gar'), [self.player_1, self.player_3])
        self.assertEquals(self.norcal_dao.get_players_by_alias_from_all_regions('GAR'), [self.player_1, self.player_3])
        self.assertEquals(self.norcal_dao.get_players_by_alias_from_all_regions('garr'), [self.player_1])
        self.assertEquals(self.norcal_dao.get_players_by_alias_from_all_regions('sfat'), [self.player_2])
        self.assertEquals(self.norcal_dao.get_players_by_alias_from_all_regions('miom | sfat'), [self.player_2])
        self.assertEquals(self.norcal_dao.get_players_by_alias_from_all_regions('mango'), [self.player_3])

        self.assertEquals(self.norcal_dao.get_players_by_alias_from_all_regions('miom|sfat'), [])
        self.assertEquals(self.norcal_dao.get_players_by_alias_from_all_regions(''), [])

    def test_get_player_id_map_from_player_aliases(self):
        aliases = ['GAR', 'sfat', 'asdf', 'mango']
        expected_map = [
            {'player_alias': 'GAR', 'player_id': self.player_1_id},
            {'player_alias': 'sfat', 'player_id': self.player_2_id},
            {'player_alias': 'asdf', 'player_id': None},
            {'player_alias': 'mango', 'player_id': None},
        ]
        map = self.norcal_dao.get_player_id_map_from_player_aliases(aliases)
        self.assertEquals(map, expected_map)

    def test_get_all_players(self):
        self.assertEquals(self.norcal_dao.get_all_players(), [self.player_1, self.player_2])

    def test_get_all_players_all_regions(self):
        self.assertEquals(self.norcal_dao.get_all_players(all_regions=True), [self.player_1, self.player_3, self.player_2])

    def test_add_player_duplicate(self):
        with self.assertRaises(DuplicateKeyError):
            self.norcal_dao.insert_player(self.player_1)

    def test_delete_player(self):
        self.assertEquals(self.norcal_dao.get_player_by_id(self.player_1_id), self.player_1)
        self.assertEquals(self.norcal_dao.get_player_by_id(self.player_2_id), self.player_2)
        self.assertEquals(self.norcal_dao.get_player_by_id(self.player_3_id), self.player_3)

        self.norcal_dao.delete_player(self.player_2)
        self.assertEquals(self.norcal_dao.get_player_by_id(self.player_1_id), self.player_1)
        self.assertIsNone(self.norcal_dao.get_player_by_id(self.player_2_id))
        self.assertEquals(self.norcal_dao.get_player_by_id(self.player_3_id), self.player_3)

        self.norcal_dao.delete_player(self.player_3)
        self.assertEquals(self.norcal_dao.get_player_by_id(self.player_1_id), self.player_1)
        self.assertIsNone(self.norcal_dao.get_player_by_id(self.player_2_id))
        self.assertIsNone(self.norcal_dao.get_player_by_id(self.player_3_id))

        self.norcal_dao.delete_player(self.player_1)
        self.assertIsNone(self.norcal_dao.get_player_by_id(self.player_1_id))
        self.assertIsNone(self.norcal_dao.get_player_by_id(self.player_2_id))
        self.assertIsNone(self.norcal_dao.get_player_by_id(self.player_3_id))

    def test_update_player(self):
        self.assertEquals(self.norcal_dao.get_player_by_id(self.player_1_id), self.player_1)
        self.assertEquals(self.norcal_dao.get_player_by_id(self.player_2_id), self.player_2)
        self.assertEquals(self.norcal_dao.get_player_by_id(self.player_3_id), self.player_3)

        player_1_clone = Player(
                'gaR', 
                ['gar', 'garr'], 
                {'norcal': TrueskillRating(), 'texas': TrueskillRating()}, 
                ['norcal', 'texas'], 
                id=self.player_1_id)
        player_1_clone.name = 'garrr'
        player_1_clone.aliases.append('garrr')
开发者ID:MrMonacle,项目名称:garpr,代码行数:70,代码来源:test_dao.py

示例3: TestDAO

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

#.........这里部分代码省略.........
            Dao('newregion', mongo_client=self.mongo_client, new=False)

    def test_get_all_regions(self):
        # add another region
        region = 'newregion'
        Dao(region, mongo_client=self.mongo_client, new=True)

        self.assertEquals(set(Dao.get_all_regions(mongo_client=self.mongo_client)), set([self.region, region]))

    def test_get_player_by_id(self):
        self.assertEquals(self.dao.get_player_by_id(self.player_1_id), self.player_1)
        self.assertEquals(self.dao.get_player_by_id(self.player_2_id), self.player_2)
        self.assertEquals(self.dao.get_player_by_id(self.player_3_id), self.player_3)
        self.assertIsNone(self.dao.get_player_by_id(ObjectId()))

    def test_get_player_by_alias(self):
        self.assertEquals(self.dao.get_player_by_alias('gar'), self.player_1)
        self.assertEquals(self.dao.get_player_by_alias('GAR'), self.player_1)
        self.assertEquals(self.dao.get_player_by_alias('garr'), self.player_1)
        self.assertEquals(self.dao.get_player_by_alias('sfat'), self.player_2)
        self.assertEquals(self.dao.get_player_by_alias('miom | sfat'), self.player_2)
        self.assertEquals(self.dao.get_player_by_alias('mango'), self.player_3)

        self.assertIsNone(self.dao.get_player_by_alias('miom|sfat'))
        self.assertIsNone(self.dao.get_player_by_alias(''))

    def test_get_all_players(self):
        self.assertEquals(self.dao.get_all_players(), [self.player_1, self.player_3, self.player_2])

    def test_add_player_duplicate(self):
        with self.assertRaises(DuplicateKeyError):
            self.dao.add_player(self.player_1)

    def test_delete_player(self):
        self.assertEquals(self.dao.get_player_by_id(self.player_1_id), self.player_1)
        self.assertEquals(self.dao.get_player_by_id(self.player_2_id), self.player_2)
        self.assertEquals(self.dao.get_player_by_id(self.player_3_id), self.player_3)

        self.dao.delete_player(self.player_2)
        self.assertEquals(self.dao.get_player_by_id(self.player_1_id), self.player_1)
        self.assertIsNone(self.dao.get_player_by_id(self.player_2_id))
        self.assertEquals(self.dao.get_player_by_id(self.player_3_id), self.player_3)

        self.dao.delete_player(self.player_3)
        self.assertEquals(self.dao.get_player_by_id(self.player_1_id), self.player_1)
        self.assertIsNone(self.dao.get_player_by_id(self.player_2_id))
        self.assertIsNone(self.dao.get_player_by_id(self.player_3_id))

        self.dao.delete_player(self.player_1)
        self.assertIsNone(self.dao.get_player_by_id(self.player_1_id))
        self.assertIsNone(self.dao.get_player_by_id(self.player_2_id))
        self.assertIsNone(self.dao.get_player_by_id(self.player_3_id))

    def test_update_player(self):
        self.assertEquals(self.dao.get_player_by_id(self.player_1_id), self.player_1)
        self.assertEquals(self.dao.get_player_by_id(self.player_2_id), self.player_2)
        self.assertEquals(self.dao.get_player_by_id(self.player_3_id), self.player_3)

        player_1_clone = Player('gar', ['gar', 'garr'], TrueskillRating(), False, id=self.player_1_id)
        player_1_clone.name = 'garrr'
        player_1_clone.aliases.append('garrr')
        player_1_clone.exclude = True
        self.assertNotEquals(self.dao.get_player_by_id(self.player_1_id), player_1_clone)

        self.dao.update_player(player_1_clone)
开发者ID:novacourtois,项目名称:garpr,代码行数:69,代码来源:test_dao.py

示例4: TestDAO

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

#.........这里部分代码省略.........
        self.assertEquals(self.norcal_dao.get_players_by_alias_from_all_regions(
            'miom | sfat'), [self.player_2])
        self.assertEquals(self.norcal_dao.get_players_by_alias_from_all_regions(
            'mango'), [self.player_3])

        self.assertEquals(
            self.norcal_dao.get_players_by_alias_from_all_regions('miom|sfat'), [])
        self.assertEquals(
            self.norcal_dao.get_players_by_alias_from_all_regions(''), [])

    def test_get_player_id_map_from_player_aliases(self):
        aliases = ['GAR', 'sfat', 'asdf', 'mango']
        expected_map = [
            AliasMapping(player_alias='GAR', player_id=self.player_1_id),
            AliasMapping(player_alias='sfat', player_id=self.player_2_id),
            AliasMapping(player_alias='asdf', player_id=None),
            AliasMapping(player_alias='mango', player_id=None),
        ]
        map = self.norcal_dao.get_player_id_map_from_player_aliases(aliases)
        self.assertEquals(map, expected_map)

    def test_get_all_players(self):
        self.assertEquals(self.norcal_dao.get_all_players(),
                          [self.player_1, self.player_2])

    def test_get_all_players_all_regions(self):
        self.assertEquals(self.norcal_dao.get_all_players(all_regions=True), [
                          self.player_1, self.player_3, self.player_2])

    def test_add_player_duplicate(self):
        with self.assertRaises(DuplicateKeyError):
            self.norcal_dao.insert_player(self.player_1)

    def test_delete_player(self):
        self.assertEquals(self.norcal_dao.get_player_by_id(
            self.player_1_id), self.player_1)
        self.assertEquals(self.norcal_dao.get_player_by_id(
            self.player_2_id), self.player_2)
        self.assertEquals(self.norcal_dao.get_player_by_id(
            self.player_3_id), self.player_3)

        self.norcal_dao.delete_player(self.player_2)
        self.assertEquals(self.norcal_dao.get_player_by_id(
            self.player_1_id), self.player_1)
        self.assertIsNone(self.norcal_dao.get_player_by_id(self.player_2_id))
        self.assertEquals(self.norcal_dao.get_player_by_id(
            self.player_3_id), self.player_3)

        self.norcal_dao.delete_player(self.player_3)
        self.assertEquals(self.norcal_dao.get_player_by_id(
            self.player_1_id), self.player_1)
        self.assertIsNone(self.norcal_dao.get_player_by_id(self.player_2_id))
        self.assertIsNone(self.norcal_dao.get_player_by_id(self.player_3_id))

        self.norcal_dao.delete_player(self.player_1)
        self.assertIsNone(self.norcal_dao.get_player_by_id(self.player_1_id))
        self.assertIsNone(self.norcal_dao.get_player_by_id(self.player_2_id))
        self.assertIsNone(self.norcal_dao.get_player_by_id(self.player_3_id))

    def test_update_player(self):
        self.assertEquals(self.norcal_dao.get_player_by_id(
            self.player_1_id), self.player_1)
        self.assertEquals(self.norcal_dao.get_player_by_id(
            self.player_2_id), self.player_2)
        self.assertEquals(self.norcal_dao.get_player_by_id(
            self.player_3_id), self.player_3)
开发者ID:BrandonCookeDev,项目名称:garpr,代码行数:70,代码来源:test_dao.py

示例5: TestServer

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

#.........这里部分代码省略.........

        response = self.app.put('/norcal/players/' + str(player.id) + '/region/nyc')
        json_data = json.loads(response.data)

        player = self.norcal_dao.get_player_by_alias('gar')
        self.assertEquals(set(player.regions), set(['norcal', 'nyc']))

        self.assertEquals(len(json_data.keys()), 5)
        self.assertEquals(set(json_data['regions']), set(['norcal', 'nyc']))

    @patch('server.get_user_from_access_token')
    def test_put_player_region_already_exists(self, mock_get_user_from_access_token):
        mock_get_user_from_access_token.return_value = self.user
        player = self.norcal_dao.get_player_by_alias('gar')
        self.assertEquals(player.regions, ['norcal'])

        response = self.app.put('/norcal/players/' + str(player.id) + '/region/norcal')
        json_data = json.loads(response.data)

        self.assertEquals(player.regions, ['norcal'])

        self.assertEquals(len(json_data.keys()), 5)
        self.assertEquals(json_data['regions'], ['norcal'])

    @patch('server.get_user_from_access_token')
    def test_put_player_region_invalid_permissions(self, mock_get_user_from_access_token):
        mock_get_user_from_access_token.return_value = self.user
        player = self.norcal_dao.get_player_by_alias('gar')
        response = self.app.put('/norcal/players/' + str(player.id) + '/region/texas')
        self.assertEquals(response.status_code, 403)
        self.assertEquals(response.data, '"Permission denied"')

    @patch('server.get_user_from_access_token')
    def test_delete_player_region(self, mock_get_user_from_access_token):
        mock_get_user_from_access_token.return_value = self.user
        player = self.norcal_dao.get_player_by_alias('gar')
        self.assertEquals(player.regions, ['norcal'])

        response = self.app.delete('/norcal/players/' + str(player.id) + '/region/norcal')
        json_data = json.loads(response.data)

        player = self.norcal_dao.get_player_by_id(player.id)
        self.assertEquals(player.regions, [])

        self.assertEquals(len(json_data.keys()), 5)
        self.assertEquals(json_data['regions'], [])

    @patch('server.get_user_from_access_token')
    def test_delete_player_region_does_not_exist(self, mock_get_user_from_access_token):
        mock_get_user_from_access_token.return_value = self.user
        player = self.norcal_dao.get_player_by_alias('gar')
        self.assertEquals(player.regions, ['norcal'])

        response = self.app.delete('/norcal/players/' + str(player.id) + '/region/nyc')
        json_data = json.loads(response.data)

        player = self.norcal_dao.get_player_by_alias('gar')
        self.assertEquals(player.regions, ['norcal'])

        self.assertEquals(len(json_data.keys()), 5)
        self.assertEquals(json_data['regions'], ['norcal'])

    @patch('server.get_user_from_access_token')
    def test_delete_player_region_invalid_permissions(self, mock_get_user_from_access_token):
        mock_get_user_from_access_token.return_value = self.user
        player = self.norcal_dao.get_player_by_alias('gar')
开发者ID:AJAnderson,项目名称:garpr,代码行数:70,代码来源:test_server.py


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