def test_update_expired_future_expiry_date(): """ Tests update_board will update an expired future game board to be 90 days from current time. """ with app.app_context(): rpm = RestaurantProfileManager('testuser') pm = PublicProfileModifier(rpm) gm = GameBoardManager(rpm) public_users = pm.get_public_users() expired_board = [] expected = True for user in public_users: # expired current and future board if 'expiry_date' in user['bingo_board'] and user['bingo_board'][ 'expiry_date'] < datetime.now( ) and user['future_board']['expiry_date'] < datetime.now(): expired_board.append(user) gm.update_board(user['_id']) public_users = rpm.get_public_users() for expired_user in expired_board: for user in public_users: #searches for users whose boards were updated if user['username'] == expired_user['username']: # future exp date was not updated if user['future_board']['expiry_date'] < datetime.now(): expected = False assert expected
def test_update_current_with_future(): """ Tests that update_board replaces an expired bingo board with a future board that has an expiry date that is in the future and updates the future board to have an expiration date of 90 more days, and customer's completed goals are removed. """ with app.app_context(): rpm = RestaurantProfileManager('testuser') pm = PublicProfileModifier(rpm) gm = GameBoardManager(rpm) public_users = pm.get_public_users() expired_board_user = [] current_boards = [] actual_future = [] expected_boards = [] expected_future = [] customer_update = True for user in public_users: # expired current but not future board if 'expiry_date' in user['bingo_board'] and user['bingo_board'][ 'expiry_date'] < datetime.now( ) and user['future_board']['expiry_date'] > datetime.now(): expired_board_user.append(user['_id']) # expected current board is future board expected_boards.append(user['future_board']) to_add = copy.deepcopy(user['future_board']) to_add['expiry_date'] = user['future_board'][ 'expiry_date'] + timedelta(days=90) # expected future board has increased exp date expected_future.append(to_add) gm.update_board(user['_id']) public_users = pm.get_public_users() for user in public_users: #searches for users whose boards were updated if user['_id'] in expired_board_user: current_boards.append(user['bingo_board']) actual_future.append(user['future_board']) customers = rpm.db.query('customers') for c in customers: if 'progress' in c: for rest in c['progress']: # searches for customers whose progress was updated if rest['restaurant_id'] in expired_board_user and 'completed_goals' in rest: # completed goals were not updated if len(rest['completed_goals']) > 0: customer_update = False assert current_boards == expected_boards and actual_future == expected_future and customer_update
def view_board(obj_id): """ Allows users to view the chosen restaurant's game board. """ username = current_user.get_id() rpm = RestaurantProfileManager("") gpm = GameBoardManager(rpm) gpm.update_board(obj_id) board = gpm.get_restaurant_board_by_id(obj_id) set_board_progress(current_user, board, obj_id) board["expiry_date"] = board["expiry_date"].strftime( "%B X%d, %Y - X%I:%M %p UTC").replace("X0", "X").replace("X", "") return render_template('view_game_board.j2', goals=board["board"], name=board["name"], rewards=board["board_reward"], cust_id=username, size=board["size"], date=board["expiry_date"])
def edit_board(): """ When retrieving this route, get a restaurant profile's goals, rewards and future board. Render these items together to show a bingo editor. """ rest_id = current_user.get_restaurant_id() gbm = GameBoardManager(current_user) gbm.update_board(rest_id) bingo_board = gbm.get_future_board() current_expiry = gbm.get_current_board_expiry() goals = GoalsManager(current_user).get_goals() rewards = RewardsManager(current_user).get_rewards() return render_template('edit_game_board.j2', goals=goals, board_name=bingo_board["name"], rewards=rewards, board=bingo_board["board"], board_reward=bingo_board["board_reward"], board_size=bingo_board["size"], current_expiry=current_expiry, future_expiry=bingo_board["expiry_date"])
def view_board(): """ When retrieving this route, get a restaurant profile's current bingo board. Render these items together to show current bingo board and expiration date. """ rest_id = current_user.get_restaurant_id() try: gbm = GameBoardManager(current_user) gbm.update_board(rest_id) bingo_board = gbm.get_restaurant_board_by_id(rest_id) if bingo_board["board"] == []: return redirect("/board/edit") return render_template( 'view_game_board.j2', goals=[x['goal'] for x in bingo_board["board"]], board_name=bingo_board["name"], rewards=[x['reward'] for x in bingo_board["board_reward"]], board_size=bingo_board["size"], current_expiry=str(bingo_board["expiry_date"])) except KeyError: return redirect("/board/edit")