本文整理汇总了Python中dao.Dao.get_all_tournaments方法的典型用法代码示例。如果您正苦于以下问题:Python Dao.get_all_tournaments方法的具体用法?Python Dao.get_all_tournaments怎么用?Python Dao.get_all_tournaments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dao.Dao
的用法示例。
在下文中一共展示了Dao.get_all_tournaments方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_all_tournaments [as 别名]
def get(self, region):
dao = Dao(region, mongo_client=mongo_client)
return_dict = {}
return_dict['tournaments'] = [t.get_json_dict() for t in dao.get_all_tournaments(regions=[region])]
convert_object_id_list(return_dict['tournaments'])
for t in return_dict['tournaments']:
t['date'] = t['date'].strftime("%x")
# remove extra fields
del t['raw']
del t['matches']
del t['players']
del t['type']
return return_dict
示例2: get
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_all_tournaments [as 别名]
def get(self, region):
dao = Dao(region, mongo_client=mongo_client)
if not dao:
return 'Dao not found', 404
include_pending_tournaments = False
args = tournament_list_get_parser.parse_args()
if args['includePending'] and args['includePending'] == 'true':
user = get_user_from_request(request, dao)
include_pending_tournaments = user and is_user_admin_for_region(
user, region)
tournaments = dao.get_all_tournaments(regions=[region])
only_properties = ('id',
'name',
'date',
'regions')
# temporary fix
all_tournament_jsons = []
for t in tournaments:
try:
all_tournament_jsons.append(t.dump(context='web',
only=only_properties))
except:
print 'error inserting tournament', t
if include_pending_tournaments:
# add a pending field for all existing tournaments
for t in all_tournament_jsons:
t['pending'] = False
pending_tournaments = dao.get_all_pending_tournaments(regions=[
region])
if pending_tournaments:
for p in pending_tournaments:
try:
p = p.dump(context='web',
only=only_properties)
p['pending'] = True
all_tournament_jsons.append(p)
except:
print 'error inserting pending tournament', p
return_dict = {}
return_dict['tournaments'] = all_tournament_jsons
return return_dict
示例3: get
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_all_tournaments [as 别名]
def get(self, region, id):
dao = Dao(region, mongo_client=mongo_client)
args = matches_get_parser.parse_args()
return_dict = {}
player = dao.get_player_by_id(ObjectId(id))
return_dict['player'] = {'id': str(player.id), 'name': player.name}
player_list = [player]
opponent_id = args['opponent']
if opponent_id is not None:
opponent = dao.get_player_by_id(ObjectId(args['opponent']))
return_dict['opponent'] = {'id': str(opponent.id), 'name': opponent.name}
player_list.append(opponent)
match_list = []
return_dict['matches'] = match_list
return_dict['wins'] = 0
return_dict['losses'] = 0
tournaments = dao.get_all_tournaments(players=player_list)
for tournament in tournaments:
for match in tournament.matches:
if (opponent_id is not None and match.contains_players(player.id, opponent.id)) or \
(opponent_id is None and match.contains_player(player.id)):
match_dict = {}
match_dict['tournament_id'] = str(tournament.id)
match_dict['tournament_name'] = tournament.name
match_dict['tournament_date'] = tournament.date.strftime("%x")
match_dict['opponent_id'] = str(match.get_opposing_player_id(player.id))
match_dict['opponent_name'] = dao.get_player_by_id(ObjectId(match_dict['opponent_id'])).name
if match.did_player_win(player.id):
match_dict['result'] = 'win'
return_dict['wins'] += 1
else:
match_dict['result'] = 'lose'
return_dict['losses'] += 1
match_list.append(match_dict)
return return_dict
示例4: delete
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_all_tournaments [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}
示例5: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_all_tournaments [as 别名]
#.........这里部分代码省略.........
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_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, '')
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)
def test_get_all_tournaments_for_region(self):
tournaments = self.norcal_dao.get_all_tournaments(regions=['norcal'])
self.assertEquals(len(tournaments), 2)
# tournament 1 is last in the list because it occurs later than tournament 2
tournament_1 = tournaments[1]
示例6: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_all_tournaments [as 别名]
#.........这里部分代码省略.........
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)
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, 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)
def test_get_all_tournaments(self):
tournaments = self.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.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 = 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, 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)
def test_get_all_tournaments_containing_players(self):
players = [self.player_5]
tournaments = self.dao.get_all_tournaments(players=players)
self.assertEquals(len(tournaments), 1)
tournament = tournaments[0]
self.assertEquals(tournament.id, self.tournament_id_2)
self.assertEquals(tournament.type, self.tournament_type_2)
示例7: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_all_tournaments [as 别名]
#.........这里部分代码省略.........
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)
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)
def test_get_all_tournaments_for_region(self):
tournaments = self.norcal_dao.get_all_tournaments(regions=['norcal'])
self.assertEquals(len(tournaments), 2)
# tournament 1 is last in the list because it occurs later than
# tournament 2
tournament_1 = tournaments[1]
示例8: TestServer
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_all_tournaments [as 别名]
class TestServer(unittest.TestCase):
def setUp(self):
self.mongo_client_patcher = patch('server.mongo_client', new=mongomock.MongoClient())
self.mongo_client = self.mongo_client_patcher.start()
server.app.config['TESTING'] = True
self.app = server.app.test_client()
self.norcal_dao = Dao(NORCAL_REGION_NAME, mongo_client=self.mongo_client, new=True)
self.texas_dao = Dao(TEXAS_REGION_NAME, mongo_client=self.mongo_client, new=True)
self._import_files()
rankings.generate_ranking(self.norcal_dao)
rankings.generate_ranking(self.texas_dao)
def _import_files(self):
for f in NORCAL_FILES:
scraper = TioScraper(f[0], f[1])
self._import_players(scraper, self.norcal_dao)
self.norcal_dao.insert_tournament(Tournament.from_scraper('tio', scraper, self.norcal_dao))
for f in TEXAS_FILES:
scraper = TioScraper(f[0], f[1])
self._import_players(scraper, self.texas_dao)
self.texas_dao.insert_tournament(Tournament.from_scraper('tio', scraper, self.texas_dao))
def _import_players(self, scraper, dao):
for player in scraper.get_players():
db_player = dao.get_player_by_alias(player)
if db_player is None:
db_player = Player(player, [player.lower()], TrueskillRating(), False)
dao.add_player(db_player)
def test_get_region_list(self):
data = self.app.get('/regions').data
self.assertEquals(json.loads(data), {'regions': ['norcal', 'texas']})
def test_get_player_list(self):
def for_region(data, dao):
json_data = json.loads(data)
self.assertEquals(json_data.keys(), ['players'])
players_list = json_data['players']
players_from_db = dao.get_all_players()
self.assertEquals(len(players_list), len(players_from_db))
for player in players_list:
expected_keys = set(['id', 'name'])
self.assertEquals(set(player.keys()), expected_keys)
self.assertEquals(ObjectId(player['id']), dao.get_player_by_alias(player['name']).id)
data = self.app.get('/norcal/players').data
for_region(data, self.norcal_dao)
data = self.app.get('/texas/players').data
for_region(data, self.texas_dao)
def test_get_player(self):
player = self.norcal_dao.get_player_by_alias('gar')
data = self.app.get('/norcal/players/' + str(player.id)).data
json_data = json.loads(data)
self.assertEquals(len(json_data.keys()), 5)
self.assertEquals(json_data['id'], str(player.id))
self.assertEquals(json_data['name'], 'gar')
self.assertEquals(json_data['aliases'], ['gar'])
self.assertEquals(json_data['exclude'], False)
self.assertTrue(json_data['rating']['mu'] > 25.9)
self.assertTrue(json_data['rating']['sigma'] > 3.89)
player = self.texas_dao.get_player_by_alias('wobbles')
data = self.app.get('/texas/players/' + str(player.id)).data
json_data = json.loads(data)
self.assertEquals(len(json_data.keys()), 5)
self.assertEquals(json_data['id'], str(player.id))
self.assertEquals(json_data['name'], 'Wobbles')
self.assertEquals(json_data['aliases'], ['wobbles'])
self.assertEquals(json_data['exclude'], False)
self.assertTrue(json_data['rating']['mu'] > 44.5)
self.assertTrue(json_data['rating']['sigma'] > 3.53)
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()
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'])
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'))
data = self.app.get('/norcal/tournaments').data
#.........这里部分代码省略.........
示例9: TestServer
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_all_tournaments [as 别名]
#.........这里部分代码省略.........
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')
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']: