本文整理汇总了Python中dao.Dao.get_tournament_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Dao.get_tournament_by_id方法的具体用法?Python Dao.get_tournament_by_id怎么用?Python Dao.get_tournament_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dao.Dao
的用法示例。
在下文中一共展示了Dao.get_tournament_by_id方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_tournament_by_id [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)
示例2: put
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_tournament_by_id [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)
示例3: delete
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_tournament_by_id [as 别名]
def delete(self, region, id):
""" Deletes a pending tournament.
If a (non-pending) tournament with this id exists, tell the user they can't do that.
Route restricted to admins for this region. """
dao = Dao(region, mongo_client=mongo_client)
user = get_user_from_request(request, dao)
if not user:
return 'Permission denied', 403
pending_tournament = dao.get_pending_tournament_by_id(ObjectId(id))
if not pending_tournament:
tournament = dao.get_tournament_by_id(ObjectId(id))
if not tournament:
return "No pending tournament found with that id.", 400
else:
if not is_user_admin_for_regions(user, tournament.regions):
return 'Permission denied', 403
else:
return "Cannot delete a finalized tournament.", 400
if not is_user_admin_for_regions(user, pending_tournament.regions):
return 'Permission denied', 403
dao.delete_pending_tournament(pending_tournament)
return {"success": True}
示例4: put
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_tournament_by_id [as 别名]
def put(self, region, id):
dao = Dao(region, mongo_client=mongo_client)
user = get_user_from_request(request, dao)
args = tournament_details_add_match_parser.parse_args()
tournament = dao.get_tournament_by_id(ObjectId(id))
if not user:
return 'Permission denied', 403
if not is_user_admin_for_regions(user, tournament.regions):
return 'Permission denied', 403
winner_id = args['winner_id']
loser_id = args['loser_id']
if winner_id is None or loser_id is None:
print "winner and loser IDs not present. Cannot continue"
return "winner and loser IDs not present. Cannot continue", 400
try:
dao.add_match_by_tournament_id(ObjectId(id), ObjectId(winner_id), ObjectId(loser_id))
return 'Successful addition', 200
except Exception as e:
print 'error adding match to tournament: ' + str(e)
return 'error adding match to tournament: ' + str(e), 400
示例5: delete
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_tournament_by_id [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}
示例6: get
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_tournament_by_id [as 别名]
def get(self, region, id):
dao = Dao(region, mongo_client=mongo_client)
if not dao:
return 'Dao not found', 404
response = None
tournament = None
try:
tournament = dao.get_tournament_by_id(ObjectId(id))
except:
return 'Invalid ObjectID', 400
if tournament is not None:
response = convert_tournament_to_response(tournament, dao)
else:
user = get_user_from_request(request, dao)
# this usage is safe, if the ID was fake, we would have already
# blown the coop above
pending_tournament = dao.get_pending_tournament_by_id(ObjectId(id))
if not pending_tournament:
return 'Not found!', 404
if not user:
return 'Permission denied', 403
if not is_user_admin_for_regions(user, pending_tournament.regions):
return 'Permission denied', 403
response = pending_tournament.dump(context='web')
return response
示例7: get
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_tournament_by_id [as 别名]
def get(self, region, id):
dao = Dao(region, mongo_client=mongo_client)
response = None
tournament = dao.get_tournament_by_id(ObjectId(id))
if tournament is not None:
response = convert_tournament_to_response(tournament, dao)
else:
pending_tournament = dao.get_pending_tournament_by_id(ObjectId(id))
response = convert_pending_tournament_to_response(pending_tournament, dao)
return response
示例8: post
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_tournament_by_id [as 别名]
def post(self, region):
dao = Dao(region, mongo_client=mongo_client)
args = rankings_criteria_get_parser.parse_args()
if not dao:
return 'Dao not found', 404
user = get_user_from_request(request, dao)
if not user:
return 'Permission denied', 403
if not is_user_admin_for_region(user, region):
return 'Permission denied', 403
# we pass in now so we can mock it out in tests
now = datetime.now()
try:
try:
ranking_num_tourneys_attended = int(args['ranking_num_tourneys_attended'])
ranking_activity_day_limit = int(args['ranking_activity_day_limit'])
tournament_qualified_day_limit = int(args['tournament_qualified_day_limit'])
tournament_id_to_diff = ObjectId(args['tournament_id_to_diff'])
#TODO Get stored rankings from the db
dao.update_region_ranking_criteria(region.lower(),
ranking_num_tourneys_attended=ranking_num_tourneys_attended,
ranking_activity_day_limit=ranking_activity_day_limit,
tournament_qualified_day_limit=tournament_qualified_day_limit)
print 'Running rankings. day_limit: ' + str(ranking_activity_day_limit) + ' and num_tourneys: ' \
+ str(ranking_num_tourneys_attended) + ' and tournament_qualified_day_limit: ' + str(tournament_qualified_day_limit)
tournament_to_diff = dao.get_tournament_by_id(tournament_id_to_diff)
rankings.generate_ranking(dao, now=now,
day_limit=ranking_activity_day_limit,
num_tourneys=ranking_num_tourneys_attended,
tournament_qualified_day_limit=tournament_qualified_day_limit,
tournament_to_diff=tournament_to_diff)
except:
rankings.generate_ranking(dao, now=now)
except Exception as e:
print str(e)
return 'There was an error updating rankings', 400
return self.get(region)
示例9: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_tournament_by_id [as 别名]
#.........这里部分代码省略.........
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.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):
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'
示例10: TestServer
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_tournament_by_id [as 别名]
#.........这里部分代码省略.........
@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')
response = self.app.delete('/norcal/players/' + str(player.id) + '/region/texas')
self.assertEquals(response.status_code, 403)
self.assertEquals(response.data, '"Permission denied"')
def test_get_tournament_list(self):
def for_region(data, dao):
json_data = json.loads(data)
self.assertEquals(json_data.keys(), ['tournaments'])
tournaments_list = json_data['tournaments']
tournaments_from_db = dao.get_all_tournaments(regions=[dao.region_id])
self.assertEquals(len(tournaments_list), len(tournaments_from_db))
for tournament in tournaments_list:
tournament_from_db = dao.get_tournament_by_id(ObjectId(tournament['id']))
expected_keys = set(['id', 'name', 'date', 'regions'])
self.assertEquals(set(tournament.keys()), expected_keys)
self.assertEquals(tournament['id'], str(tournament_from_db.id))
self.assertEquals(tournament['name'], tournament_from_db.name)
self.assertEquals(tournament['date'], tournament_from_db.date.strftime('%x'))
self.assertEquals(tournament['regions'], [dao.region_id])
data = self.app.get('/norcal/tournaments').data
for_region(data, self.norcal_dao)
data = self.app.get('/texas/tournaments').data
for_region(data, self.texas_dao)
def test_get_tournament(self):
tournament = self.norcal_dao.get_all_tournaments(regions=['norcal'])[0]
data = self.app.get('/norcal/tournaments/' + str(tournament.id)).data
json_data = json.loads(data)
self.assertEquals(len(json_data.keys()), 7)
self.assertEquals(json_data['id'], str(tournament.id))
self.assertEquals(json_data['name'], 'BAM: 4 stocks is not a lead')
self.assertEquals(json_data['type'], 'tio')
self.assertEquals(json_data['date'], tournament.date.strftime('%x'))
self.assertEquals(json_data['regions'], ['norcal'])
self.assertEquals(len(json_data['players']), len(tournament.players))
self.assertEquals(len(json_data['matches']), len(tournament.matches))
for player in json_data['players']:
db_player = self.norcal_dao.get_player_by_id(ObjectId(player['id']))
self.assertEquals(len(player.keys()), 2)
self.assertEquals(player['id'], str(db_player.id))
self.assertEquals(player['name'], db_player.name)
示例11: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_tournament_by_id [as 别名]
#.........这里部分代码省略.........
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)
self.assertEquals(tournament_1.matches, self.tournament_matches_1)
示例12: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_tournament_by_id [as 别名]
#.........这里部分代码省略.........
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):
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.raw, self.pending_tournament_raw_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_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.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, 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)
self.assertEquals(tournament_2.regions, self.tournament_regions_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.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)
示例13: get
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_tournament_by_id [as 别名]
def get(self, region, id):
dao = Dao(region, mongo_client=mongo_client)
tournament = dao.get_tournament_by_id(ObjectId(id))
return convert_tournament_to_response(tournament, dao)