def test_set_board_rewards(): """ Test that the set_bingo_board() function in restaurant_profile_manager.py can be used to update a user's list of rewards. """ with app.app_context(): rpm = RestaurantProfileManager("vchang") gbm = GameBoardManager(rpm) board = gbm.get_bingo_board() old_rewards = board["board_reward"] new_rewards = [ ObjectId('5ef50127ccd1e88ead4cd07b'), ObjectId('5ef50127ccd1e88ead4cd07b'), ObjectId('5ef50127ccd1e88ead4cd07b'), ObjectId('5ef50127ccd1e88ead4cd07b'), ObjectId('5ef50127ccd1e88ead4cd07b'), ObjectId('5ef50127ccd1e88ead4cd07b'), ObjectId('5ef50127ccd1e88ead4cd07b'), ObjectId('5ef50127ccd1e88ead4cd07b'), ObjectId('5ef50127ccd1e88ead4cd07b'), ObjectId('5ef50127ccd1e88ead4cd07b'), ObjectId('5ef50127ccd1e88ead4cd07b'), ObjectId('5ef50127ccd1e88ead4cd07b') ] board["board_reward"] = new_rewards gbm.set_bingo_board(board) assert (gbm.get_bingo_board())["board_reward"] == new_rewards board["board_reward"] = old_rewards gbm.set_bingo_board(board)
def test_reset_board(db): """ Test that reset board resets goals on the board when the board is full. """ rpm = RestaurantProfileManager("boardtest3x3") cpm = CustomerProfileManager("tester2") bpm = GameBoardManager(rpm) board = bpm.get_bingo_board() vpm = Validator(rpm) for i in range(board['size']): vpm.complete_goal("tester", board['board'][i], str(i)) rest_id = rpm.get_restaurant_id() reset_complete_board(cpm, rest_id) rest_board = db.query("customers", { "username": "******", "progress.restaurant_id": rest_id }) user_board = [ x for x in rest_board[0]['progress'] if x['restaurant_id'] == rest_id ] assert len(user_board[0]["completed_goals"]) == 0
def test_get_rewards_from_board(): """ Test that the get_bingo_board() function in restaurant_profile_manager.py retrieves a user's list of rewards on their bingo board. """ with app.app_context(): rpm = RestaurantProfileManager("unittestuser") gbm = GameBoardManager(rpm) board = gbm.get_bingo_board() rewards = board["board_reward"] expected_rewards = [ ObjectId('5f03aa437aae4a086d810107'), ObjectId('5f03a9b57aae4a086d8100fe'), ObjectId('5f03a9c87aae4a086d8100ff'), ObjectId('5f03a9ec7aae4a086d810101'), ObjectId('5f03aa507aae4a086d810108'), ObjectId('5f03a9c87aae4a086d8100ff'), ObjectId('5f03aa287aae4a086d810105'), ObjectId('5f03a9967aae4a086d8100fd'), ObjectId('5f03a9fd7aae4a086d810102'), ObjectId('5f03a9fd7aae4a086d810102'), ObjectId('5f03a9fd7aae4a086d810102'), ObjectId('5f03a9ec7aae4a086d810101') ] assert rewards == expected_rewards
def test_get_rewards_new_user(): """ Test that the get_bingo_board() function in restaurant_profile_manager.py retrieves an empty board and reward list when a new user is detected. """ with app.app_context(): rpm = RestaurantProfileManager("newuser") gbm = GameBoardManager(rpm) rewards = (gbm.get_bingo_board())["board_reward"] assert rewards == []
def test_remove_custom_reward_on_board(): """ Test that the remove_custom_reward() function in restaurant_profile_manager.py will not remove a goal that is on the board. """ with app.app_context(): rpm = RestaurantProfileManager("vchang") rm = RewardsManager(rpm) gm = GameBoardManager(rpm) old_rewards = rm.get_custom_rewards() board_rewards = gm.get_bingo_board()["board_reward"] for i in range(0, len(old_rewards)): if ObjectId(old_rewards[i]['_id']) in board_rewards or ObjectId(old_rewards[i]['_id']) in future_rewards: rm.remove_custom_reward(old_rewards[i]['_id']) break new_rewards = rm.get_custom_rewards() assert len(new_rewards) == len(old_rewards)
def test_remove_custom_goal(): """ Test that the remove_custom_goal() function in restaurant_profile_manager.py can be used to remove a user's custom goal. """ with app.app_context(): rpm = RestaurantProfileManager("vchang") gm = GoalsManager(rpm) old_goals = gm.get_custom_goals() gbm = GameBoardManager(rpm) board_goals = gbm.get_bingo_board()["board"] found = False for i in range(0, len(old_goals)): if ObjectId(old_goals[i]['_id']) not in board_goals: found = True gm.remove_custom_goal(old_goals[i]['_id']) break new_goals = gm.get_custom_goals() assert (len(new_goals) == len(old_goals) and found == False) or \ (len(new_goals) == (len(old_goals) - 1) and found == True)