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
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
def test_from_scraper(self): mock_scraper = mock.Mock(spec=ChallongeScraper) mock_scraper.get_players.return_value = self.players mock_scraper.get_matches.return_value = self.matches mock_scraper.get_raw.return_value = '' mock_scraper.get_date.return_value = self.date mock_scraper.get_name.return_value = self.name mock_scraper.get_url.return_value = '' pending_tournament, _ = PendingTournament.from_scraper( self.type, mock_scraper, 'norcal') self.assertEqual(pending_tournament.type, self.type) self.assertEqual(pending_tournament.date, self.date) self.assertEqual(pending_tournament.name, self.name) self.assertEqual(pending_tournament.matches, self.matches) self.assertEqual(pending_tournament.players, self.players) self.assertEqual(pending_tournament.regions, ['norcal'])
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
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