本文整理汇总了Python中dao.Dao.insert_pending_tournament方法的典型用法代码示例。如果您正苦于以下问题:Python Dao.insert_pending_tournament方法的具体用法?Python Dao.insert_pending_tournament怎么用?Python Dao.insert_pending_tournament使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dao.Dao
的用法示例。
在下文中一共展示了Dao.insert_pending_tournament方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import insert_pending_tournament [as 别名]
def post(self, region):
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):
return 'Permission denied', 403
parser = reqparse.RequestParser()
parser.add_argument('type', type=str, location='json')
parser.add_argument('data', type=unicode, location='json')
parser.add_argument('bracket', type=str, location='json')
args = parser.parse_args()
print "in server post, actually got this far!"
if args['data'] is None:
return "data required", 400
the_bytes = bytearray(args['data'], "utf8")
if the_bytes[0] == 0xef:
print "found magic numbers"
return "magic numbers!", 503
type = args['type']
data = args['data']
if type == 'tio':
if args['bracket'] is None:
return "Missing bracket name", 400
data_bytes = bytes(data)
if data_bytes[0] == '\xef':
data = data[:3]
scraper = TioScraper(data, args['bracket'])
elif type == 'challonge':
scraper = ChallongeScraper(data)
else:
return "Unknown type", 400
pending_tournament = PendingTournament.from_scraper(type, scraper, region)
pending_tournament.alias_to_id_map = alias_service.get_alias_to_id_map_in_list_format(
dao, pending_tournament.players)
new_id = dao.insert_pending_tournament(pending_tournament)
return_dict = {
'id': str(new_id)
}
return return_dict
示例2: post
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import insert_pending_tournament [as 别名]
def post(self, region):
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):
return 'Permission denied', 403
parser = reqparse.RequestParser()
parser.add_argument('type', type=str, location='json')
parser.add_argument('data', type=unicode, location='json')
parser.add_argument('bracket', type=str, location='json')
args = parser.parse_args()
if args['data'] is None:
return "data required", 400
type = args['type']
data = args['data']
if type == 'tio':
if args['bracket'] is None:
return "Missing bracket name", 400
scraper = TioScraper(data, args['bracket'])
elif type == 'challonge':
scraper = ChallongeScraper(data)
else:
return "Unknown type", 400
pending_tournament = PendingTournament.from_scraper(type, scraper, region)
pending_tournament.alias_to_id_map = alias_service.get_alias_to_id_map_in_list_format(
dao, pending_tournament.players)
new_id = dao.insert_pending_tournament(pending_tournament)
return_dict = {
'id': str(new_id)
}
return return_dict
示例3: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import insert_pending_tournament [as 别名]
#.........这里部分代码省略.........
self.ranking_3 = Ranking('texas', self.ranking_time_2, self.tournament_ids,
[self.ranking_entry_1, self.ranking_entry_2])
self.rankings = [self.ranking_1, self.ranking_2, self.ranking_3]
self.user_id_1 = 'abc123'
self.user_admin_regions_1 = ['norcal', 'texas']
self.user_1 = User(self.user_id_1, self.user_admin_regions_1)
self.user_id_2 = 'asdfasdf'
self.user_full_name_2 = 'Full Name'
self.user_admin_regions_2 = []
self.user_2 = User(self.user_id_2, self.user_admin_regions_2, full_name=self.user_full_name_2)
self.users = [self.user_1, self.user_2]
self.region_1 = Region('norcal', 'Norcal')
self.region_2 = Region('texas', 'Texas')
self.regions = [self.region_1, self.region_2]
for region in self.regions:
Dao.insert_region(region, self.mongo_client, database_name=DATABASE_NAME)
self.norcal_dao = Dao('norcal', self.mongo_client, database_name=DATABASE_NAME)
for player in self.players:
self.norcal_dao.insert_player(player)
for tournament in self.tournaments:
self.norcal_dao.insert_tournament(tournament)
for pending_tournament in self.pending_tournaments:
self.norcal_dao.insert_pending_tournament(pending_tournament)
for ranking in self.rankings:
self.norcal_dao.insert_ranking(ranking)
for user in self.users:
self.norcal_dao.insert_user(user)
def tearDown(self):
self.mongo_client.drop_database(DATABASE_NAME)
def test_init_with_invalid_region(self):
# create a dao with an existing region
Dao('norcal', self.mongo_client, database_name=DATABASE_NAME)
# create a dao with a new region
with self.assertRaises(RegionNotFoundException):
Dao('newregion', self.mongo_client, database_name=DATABASE_NAME)
def test_get_all_regions(self):
# add another region
region = Region('newregion', 'New Region')
Dao.insert_region(region, self.mongo_client, database_name=DATABASE_NAME)
regions = Dao.get_all_regions(self.mongo_client, database_name=DATABASE_NAME)
self.assertEquals(len(regions), 3)
self.assertEquals(regions[0], region)
self.assertEquals(regions[1], self.region_1)
self.assertEquals(regions[2], self.region_2)
def test_get_player_by_id(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)
示例4: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import insert_pending_tournament [as 别名]
#.........这里部分代码省略.........
self.superadmin_id = '123456'
self.superadmin_full_name = 'superadmin'
self.superadmin_admin_regions = []
self.superadmin = User(
id=self.superadmin_id,
user_admin_regions=self.superadmin_admin_regions,
username=self.superadmin_full_name,
salt='nacl',
hashed_password='browns',
admin_level='SUPER'
)
self.users = [self.user_1, self.user_2, self.superadmin]
self.region_1 = Region(id='norcal', display_name='Norcal')
self.region_2 = Region(id='texas', display_name='Texas')
self.regions = [self.region_1, self.region_2]
for region in self.regions:
Dao.insert_region(region, self.mongo_client,
database_name=DATABASE_NAME)
self.norcal_dao = Dao('norcal', self.mongo_client,
database_name=DATABASE_NAME)
for player in self.players:
self.norcal_dao.insert_player(player)
for tournament in self.tournaments:
self.norcal_dao.insert_tournament(tournament)
for pending_tournament in self.pending_tournaments:
self.norcal_dao.insert_pending_tournament(pending_tournament)
for ranking in self.rankings:
self.norcal_dao.insert_ranking(ranking)
for user in self.users:
self.norcal_dao.insert_user(user)
def tearDown(self):
self.mongo_client.drop_database(DATABASE_NAME)
def test_init_with_invalid_region(self):
# create a dao with an existing region
Dao('norcal', self.mongo_client, database_name=DATABASE_NAME)
# create a dao with a non existant region, should return none
self.assertIsNone(Dao('newregion', self.mongo_client,
database_name=DATABASE_NAME))
def test_get_all_regions(self):
# add another region
region = Region(id='newregion', display_name='New Region')
Dao.insert_region(region, self.mongo_client,
database_name=DATABASE_NAME)
regions = Dao.get_all_regions(
self.mongo_client, database_name=DATABASE_NAME)
self.assertEquals(len(regions), 3)
self.assertEquals(regions[0], region)
self.assertEquals(regions[1], self.region_1)
self.assertEquals(regions[2], self.region_2)
示例5: post
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import insert_pending_tournament [as 别名]
def post(self, region):
print "in tournamentList POST"
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
if not is_user_admin_for_region(user, region):
return 'Permission denied', 403
parser = reqparse.RequestParser()
parser.add_argument('type', type=str, location='json')
parser.add_argument('data', type=unicode, location='json')
parser.add_argument('bracket', type=str, location='json')
parser.add_argument('included_phases', type=list, location='json')
args = parser.parse_args()
if args['data'] is None:
return "data required", 400
the_bytes = bytearray(args['data'], "utf8")
if the_bytes[0] == 0xef:
print "found magic numbers"
return "magic numbers!", 503
type = args['type']
data = args['data']
included_phases = args['included_phases']
pending_tournament = None
try:
if type == 'tio':
if args['bracket'] is None:
return "Missing bracket name", 400
data_bytes = bytes(data)
if data_bytes[0] == '\xef':
data = data[:3]
scraper = TioScraper(data, args['bracket'])
elif type == 'challonge':
scraper = ChallongeScraper(data)
elif type == 'smashgg':
scraper = SmashGGScraper(data, included_phases)
else:
return "Unknown type", 400
pending_tournament, raw_file = M.PendingTournament.from_scraper(
type, scraper, region)
except Exception as ex:
return 'Scraper encountered an error ' + str(ex), 400
if not pending_tournament or not raw_file:
return 'Scraper encountered an error', 400
try:
pending_tournament.alias_to_id_map = alias_service.get_alias_to_id_map_in_list_format(
dao, pending_tournament.players)
except:
return 'Alias service encountered an error', 400
# If the tournament is too large, don't insert the raw file into the db.
if len(pending_tournament.players) < 1000:
try:
raw_file = dao.insert_raw_file(raw_file)
except Exception as ex:
print ex
return 'Dao insert_raw_file encountered an error', 400
else:
print 'Skipping inserting raw file for tournament because it is too large'
try:
new_id = dao.insert_pending_tournament(pending_tournament)
return_dict = {
'id': str(new_id)
}
return return_dict
except Exception as ex:
print ex
return 'Dao insert_pending_tournament encountered an error', 400
return 'Unknown error!', 400