def testLeagueInit(self): League(str(uuid.uuid1())) # now bad stuff try: League(1) self.assertEqual(False, True, "Should raise invalid field") except InvalidField: pass
def testLeagueInit(self): League("Monday & Wednesday") # now bad stuff try: League(1) self.assertEqual(False, True, "Should raise invalid field") except InvalidField: pass
def mock_league(league_name="Demo League"): """Returns a mock league that was added to local DB.""" # add a demo league league = League(name=league_name) DB.session.add(league) DB.session.commit() return league
def post(self): """ POST request for League List Route: Route['league'] Parameters : tournament_name: The league's name (string) Returns: if successful status: 200 mimetype: application/json data: the created user league id (int) if missing required parameter status: 400 mimetype: application/json data: the created user league id (int) if invalid parameter status: IFSC mimetype: application/json data: the created user league id (int) """ # create a new user args = post_parser.parse_args() league_name = None if args['league_name']: league_name = args['league_name'] league = League(league_name) DB.session.add(league) DB.session.commit() result = league.id return Response(dumps(result), status=201, mimetype="application/json")
def testLeagueUpdate(self): league = League(str(uuid.uuid1())) league.update(str(uuid.uuid1())) try: league.update(1) self.assertEqual(False, True, "Should raise invalid field") except InvalidField: pass
def testLeagueUpdate(self): league = League("Monday & Wednesday") league.update("Tuesday & Thursday") try: league.update(1) self.assertEqual(False, True, "Should raise invalid field") except InvalidField: pass
def pull_leagues(url): """ pull_leagues Returns a lookup of leagues that were pulled from the website into local DB Parameters: url: the url of the main site Returns: a dictionary lookup for the website league id to local league object e.g. league_lookup = {1: League(), etc..} """ _leagues = requests.get(url + "/api/leagues").json() if isinstance(_leagues, dict): _leagues = pull_all_pages(url, _leagues) leagues_lookup = {} for league in tqdm(_leagues, desc="Pulling leagues from {}".format(url)): temp = League(name=league['league_name']) leagues_lookup[league['league_id']] = temp DB.session.add(temp) DB.session.commit() return leagues_lookup