def setUpTestData(cls): #def setUpClass(cls): test_db = UnitTestDatabase() test_db.load_historical_data_for_year(2013) test_db.setup_pool_not_started(1975) test_db.setup_week_not_started(1978, 1) test_db.setup_week_in_progress(1979, 1) test_db.setup_simple_week(1980, 1) # final week # data for the enter_picks tests, make deadline 1 day after current time test_db.setup_week_not_started(1981, 1) week = get_week(1981, 1) deadline = tz.now() + timedelta(days=1) week.pick_deadline = deadline week.lock_picks = False week.save() # setup week with locked_picks and before deadline test_db.setup_week_final(1982, 1) test_db.setup_week_not_started(1982, 2) week = get_week(1982, 2) deadline = tz.now() + timedelta(days=1) week.pick_deadline = deadline week.lock_picks = True week.save() test_db.setup_week_final(1983, 1) test_db.setup_week_with_no_games(1983, 2) super(PoolStateTest, cls).setUpTestData()
def populate_picks(): year = 2014 week = 1 user = '******' add_pick(get_week(year, week), get_user_by_username(user), get_game(year, week, 1), game_winner=1) add_pick(get_week(year, week), get_user_by_username(user), get_game(year, week, 2), game_winner=1) add_pick(get_week(year, week), get_user_by_username(user), get_game(year, week, 3), game_winner=1) add_pick(get_week(year, week), get_user_by_username(user), get_game(year, week, 4), game_winner=1) add_pick(get_week(year, week), get_user_by_username(user), get_game(year, week, 5), game_winner=1) add_pick(get_week(year, week), get_user_by_username(user), get_game(year, week, 6), game_winner=1) add_pick(get_week(year, week), get_user_by_username(user), get_game(year, week, 7), game_winner=1) add_pick(get_week(year, week), get_user_by_username(user), get_game(year, week, 8), game_winner=1) add_pick(get_week(year, week), get_user_by_username(user), get_game(year, week, 9), game_winner=1) add_pick(get_week(year, week), get_user_by_username(user), get_game(year, week, 10), game_winner=1)
def __bad_year_or_week_number(self, year, week_number): try: year_int = int(year) week_int = int(week_number) w = get_week(year_int, week_int) except Exception: return True return False
def __get_week_in_database(self, year, week_number): return get_week(year, week_number)
def post(self, request, year, week_number): if self.__bad_year_or_week_number(year, week_number): data = {'year': year, 'week_number': week_number} return render(request, "pick10/bad_week.html", data) d = Database() year = int(year) week_number = int(week_number) weeks_in_year = d.get_week_numbers(year) cancel_clicked = request.POST.get("cancel_form") if cancel_clicked: return redirect("week_results", year=year, week_number=week_number) if request.user.is_superuser: unlocked_clicked = request.POST.get("unlock_form") if unlocked_clicked: w = get_week(year, week_number) w.lock_scores = False w.save() return redirect("update_games", year=year, week_number=week_number) locked_clicked = request.POST.get("lock_form") if locked_clicked: w = get_week(year, week_number) w.lock_scores = True w.save() return redirect("update_games", year=year, week_number=week_number) submit_clicked = request.POST.get("submit_form") if not submit_clicked: errmsg = "Unexpected Error! Expected submit button to be clicked but wasn't" return render(request, "pick10/error_message.html", message=errmsg) # check user/player privileges # superuser is allowed to access page no matter what access = UserAccess(request.user) if access.is_superuser() == False: # only private player can update scores if access.is_public_user(): data = {'year': year, 'error': 'user_not_participant'} data['years_in_pool'] = sorted(d.get_years(), reverse=True) WeekNavbar(year, week_number, 'update_games', request.user).add_parameters(data) return render(request, "pick10/update_games_error.html", data) # user's player not in the pool this year if access.is_player_in_year(year) == False: player_id = access.get_player().id data = { 'year': year, 'player_id': player_id, 'error': 'bad_year' } data['years_in_pool'] = sorted(d.get_years(), reverse=True) WeekNavbar(year, week_number, 'update_games', request.user).add_parameters(data) return render(request, "pick10/update_games_error.html", data) if d.is_week_being_setup(year, week_number): data = {'year': year, 'error': 'week_not_setup'} data['years_in_pool'] = sorted(d.get_years(), reverse=True) WeekNavbar(year, week_number, 'update_games', request.user).add_parameters(data) return render(request, "pick10/update_games_error.html", data) if self.__is_week_scores_locked(year, week_number): data = { 'year': year, 'week_number': week_number, 'error': 'scores_locked' } data['years_in_pool'] = sorted(d.get_years(), reverse=True) WeekNavbar(year, week_number, 'update_games', request.user).add_parameters(data) return render(response, "pick10/update_games_error.html", data) u = UpdateGames(year, week_number) week_games = u.get_games() try: for game_number in range(1, 11): input_data = self.__get_game_input_data(request, game_number) index = game_number - 1 assert week_games[index].number == game_number week_games[index].team1_score = input_data['team1_score'] week_games[index].team2_score = input_data['team2_score'] week_games[index].quarter = input_data['quarter'] week_games[index].time_left = input_data['time_left'] week_games[index].state = input_data['state'] except BadInputException as e: return render(request, "pick10/error_message.html", message=e.errmsg) u.update_games(week_games) return redirect("update_pages", year=year, week_number=week_number)
def __is_week_scores_locked(self, year, week_number): week = get_week(year, week_number) return week.lock_scores