本文整理汇总了Python中dao.Dao.update_player方法的典型用法代码示例。如果您正苦于以下问题:Python Dao.update_player方法的具体用法?Python Dao.update_player怎么用?Python Dao.update_player使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dao.Dao
的用法示例。
在下文中一共展示了Dao.update_player方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: put
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import update_player [as 别名]
def put(self, region, id):
dao = Dao(region, mongo_client=mongo_client)
player = dao.get_player_by_id(ObjectId(id))
if not player:
return "No player found with that region/id.", 400
# 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, player.regions):
return 'Permission denied', 403
args = player_put_parser.parse_args()
if args['name']:
player.name = args['name']
if args['aliases']:
for a in args['aliases']:
if not isinstance(a, unicode):
return "each alias must be a string", 400
new_aliases = [a.lower() for a in args['aliases']]
if player.name.lower() not in new_aliases:
return "aliases must contain the players name!", 400
player.aliases = new_aliases
if args['regions']:
for a in args['regions']:
if not isinstance(a, unicode):
return "each region must be a string", 400
player.regions = args['regions']
dao.update_player(player)
示例2: delete
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import update_player [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
player = dao.get_player_by_id(ObjectId(id))
if region_to_change in player.regions:
player.regions.remove(region_to_change)
dao.update_player(player)
return_dict = dao.get_player_by_id(player.id).get_json_dict()
convert_object_id(return_dict)
return return_dict
示例3: put
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import update_player [as 别名]
def put(self, region, id):
dao = Dao(region, mongo_client=mongo_client)
if not dao:
return 'Dao not found', 404
player = None
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
# 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
# remove auth for now (for players not part of any regions)
# I think possibly we should remove admin_regions or at least
# figure out how we want them to work;
# if not is_user_admin_for_regions(user, player.regions):
# return 'Permission denied', 403
args = player_put_parser.parse_args()
if args['name']:
player.name = args['name']
if args['aliases'] is not None:
for a in args['aliases']:
if not isinstance(a, unicode):
return "each alias must be a string", 400
new_aliases = [a.lower() for a in args['aliases']]
if player.name.lower() not in new_aliases:
return "aliases must contain the players name!", 400
player.aliases = new_aliases
if args['regions'] is not None:
for a in args['regions']:
if not isinstance(a, unicode):
return "each region must be a string", 400
player.regions = args['regions']
dao.update_player(player)
return player.dump(context='web')
示例4: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import update_player [as 别名]
#.........这里部分代码省略.........
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')
del player_1_clone.ratings['texas']
self.assertNotEquals(self.norcal_dao.get_player_by_id(self.player_1_id), player_1_clone)
self.norcal_dao.update_player(player_1_clone)
self.assertNotEquals(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.assertEquals(self.norcal_dao.get_player_by_id(self.player_1_id), player_1_clone)
def test_add_alias_to_player(self):
new_alias = 'gaRRR'
lowercase_alias = 'garrr'
old_expected_aliases = ['gar', 'garr']
new_expected_aliases = ['gar', 'garr', 'garrr']
self.assertEquals(self.norcal_dao.get_player_by_id(self.player_1_id).aliases, old_expected_aliases)
self.assertEquals(self.player_1.aliases, old_expected_aliases)
self.norcal_dao.add_alias_to_player(self.player_1, new_alias)
self.assertEquals(self.norcal_dao.get_player_by_id(self.player_1_id).aliases, new_expected_aliases)
示例5: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import update_player [as 别名]
#.........这里部分代码省略.........
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)
self.assertNotEquals(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.assertEquals(self.dao.get_player_by_id(self.player_1_id), player_1_clone)
def test_get_excluded_players(self):
self.assertEquals(self.dao.get_excluded_players(), [self.player_3])
def test_exclude_player(self):
self.assertEquals(self.dao.get_excluded_players(), [self.player_3])
self.assertFalse(self.player_1.exclude)
self.dao.exclude_player(self.player_1)
self.assertTrue(self.player_1.exclude)
excluded_players = sorted(self.dao.get_excluded_players(), key=lambda p: p.name)
self.assertEquals(len(excluded_players), 2)
self.assertEquals(excluded_players[0], self.player_1)
self.assertEquals(excluded_players[1], self.player_3)
示例6: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import update_player [as 别名]
#.........这里部分代码省略.........
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(
name='gaR',
aliases=['gar', 'garr'],
ratings={'norcal': Rating(), 'texas': Rating()},
regions=['norcal', 'texas'],
id=self.player_1_id)
player_1_clone.name = 'garrr'
player_1_clone.aliases.append('garrr')
del player_1_clone.ratings['texas']
self.assertNotEquals(self.norcal_dao.get_player_by_id(
self.player_1_id), player_1_clone)
self.norcal_dao.update_player(player_1_clone)
self.assertNotEquals(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.assertEquals(self.norcal_dao.get_player_by_id(
self.player_1_id), player_1_clone)
def test_add_alias_to_player(self):
new_alias = 'gaRRR'