本文整理汇总了Python中dao.Dao.delete_tournament方法的典型用法代码示例。如果您正苦于以下问题:Python Dao.delete_tournament方法的具体用法?Python Dao.delete_tournament怎么用?Python Dao.delete_tournament使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dao.Dao
的用法示例。
在下文中一共展示了Dao.delete_tournament方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import delete_tournament [as 别名]
def delete(self, region, id):
""" Deletes a tournament.
Route restricted to admins for this region.
Be VERY careful when using this """
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
tournament_to_delete = None
try:
tournament_to_delete = dao.get_pending_tournament_by_id(
ObjectId(id))
except:
return 'Invalid ObjectID', 400
if tournament_to_delete: # its a pending tournament
if not is_user_admin_for_regions(user, tournament_to_delete.regions):
return 'Permission denied', 403
dao.delete_pending_tournament(tournament_to_delete)
else: # not a pending tournament, might be a finalized tournament
tournament_to_delete = dao.get_tournament_by_id(
ObjectId(id)) # ID must be valid if we got here
if not tournament_to_delete: # can't find anything, whoops
return "No tournament (pending or finalized) found with that id.", 404
if not is_user_admin_for_regions(user, tournament_to_delete.regions):
return 'Permission denied', 403
dao.delete_tournament(tournament_to_delete)
return {"success": True}
示例2: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import delete_tournament [as 别名]
#.........这里部分代码省略.........
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)
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, tournament_2_name_new)
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)
def test_delete_tournament(self):
tournament = self.norcal_dao.get_tournament_by_id(self.tournament_id_1)
self.norcal_dao.delete_tournament(tournament)
deleted_tournament = self.norcal_dao.get_tournament_by_id(
self.tournament_id_1)
self.assertIsNone(deleted_tournament)
def test_get_all_tournament_ids(self):
tournament_ids = self.norcal_dao.get_all_tournament_ids()
self.assertEquals(len(tournament_ids), 2)
self.assertEquals(tournament_ids[0], self.tournament_id_2)
self.assertEquals(tournament_ids[1], self.tournament_id_1)
def test_get_all_tournaments(self):
tournaments = self.norcal_dao.get_all_tournaments()
self.assertEquals(len(tournaments), 2)
# tournament 1 is last in the list because it occurs later than
# tournament 2
tournament_1 = tournaments[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 = tournaments[0]
self.assertEquals(tournament_2.id, self.tournament_id_2)
self.assertEquals(tournament_2.type, self.tournament_type_2)
示例3: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import delete_tournament [as 别名]
#.........这里部分代码省略.........
tournament_2.raw = tournament_2_raw_new
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.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)
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.raw, tournament_2_raw_new)
self.assertEquals(tournament_2.date, self.tournament_date_2)
self.assertEquals(tournament_2.name, tournament_2_name_new)
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)
def test_update_tournament_empty_raw(self):
tournament_2 = self.norcal_dao.get_tournament_by_id(self.tournament_id_2)
tournament_2.raw = ''
with self.assertRaises(UpdateTournamentException):
self.norcal_dao.update_tournament(tournament_2)
def test_delete_tournament(self):
tournament = self.norcal_dao.get_tournament_by_id(self.tournament_id_1)
self.norcal_dao.delete_tournament(tournament)
deleted_tournament = self.norcal_dao.get_tournament_by_id(self.tournament_id_1)
self.assertIsNone(deleted_tournament)
def test_get_all_tournament_ids(self):
tournament_ids = self.norcal_dao.get_all_tournament_ids()
self.assertEquals(len(tournament_ids), 2)
self.assertEquals(tournament_ids[0], self.tournament_id_2)
self.assertEquals(tournament_ids[1], self.tournament_id_1)
def test_get_all_tournaments(self):
tournaments = self.norcal_dao.get_all_tournaments()
self.assertEquals(len(tournaments), 2)
# tournament 1 is last in the list because it occurs later than tournament 2
tournament_1 = tournaments[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.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 = tournaments[0]
self.assertEquals(tournament_2.id, self.tournament_id_2)
self.assertEquals(tournament_2.type, self.tournament_type_2)
self.assertEquals(tournament_2.raw, '')