def test_get_custom_goals():
    """
    Test that the get_custom_goals() function in restaurant_profile_manager.py retrieves the user's custom goals
    """
    rpm = RestaurantProfileManager("unittestuser")
    gm = GoalsManager(rpm)
    goals = gm.get_custom_goals()
    assert len(goals) == 2
def test_get_goals():
    """
    Test that the get_goals() function in restaurant_profile_manager.py retrieves all the user's goals, there are
    20 shared goals, then anything extra will custom goals
    """
    rpm = RestaurantProfileManager("vchang")
    gm = GoalsManager(rpm)
    goals = gm.get_goals()
    assert len(goals) >= 20
def test_get_custom_goals():
    """
    Test that get_custom_goals function in restaurant_profile_manager.py
    returns the user's list of custom goals.
    """
    with app.app_context():
        rpm = RestaurantProfileManager("vchang")
        gm = GoalsManager(rpm)
        goals = gm.get_custom_goals()
        hasFields = True
        for goal in goals:
            if goal['_id'] == None and goal['goal'] == None:
                hasFields = False

        assert len(goals) > 0 and hasFields
def test_get_custom_goals():
    """
    Test that get_custom_goals() function in restaurant_profile_manager.py
    retrieves the correct list of custom goals of a restaurant profile.
    """
    rpm = RestaurantProfileManager("janedoe")
    gm = GoalsManager(rpm)
    custom_goals = gm.get_custom_goals()
    expected_custom_goals = [{
        '_id': ObjectId("5f11c9721a52881b3573c029"),
        'goal': "This is a custom goal."
    }, {
        '_id': ObjectId("5f11c99a1a52881b3573c02a"),
        'goal': "This is another custom goal."
    }]
    assert custom_goals == expected_custom_goals
Esempio n. 5
0
    def get_bingo_board(self):
        """
        Return the current restaurant user's bingo board. The board will include
        text info for goals and rewards.
        """
        try:
            goals = GoalsManager(self.rpm).get_goals()
            rewards = RewardsManager(self.rpm).get_rewards()
            board = self.rpm.db.query(
                "restaurant_users",
                {"username": self.rpm.get_id()})[0]["bingo_board"]

            board["board"] = [
                copy.deepcopy(goal)
                for index in board["board"]
                for goal in goals
                if index == goal["_id"]
            ]

            board["board_reward"] = [
                copy.deepcopy(reward)
                for index in board["board_reward"]
                for reward in rewards
                if index == reward["_id"]
            ]
            return board
        except (QueryFailureException, IndexError, KeyError):
            print("Something's wrong with the query.")
            return {
                "name": "",
                "board": [],
                "board_reward": [],
                "expiry_date": None,
                "size": 4
            }
Esempio n. 6
0
def view_customize():
    """
    When retrieving this route, render a restaurant profile's list of
    customized goals and rewards.
    Prerequisite: User is logged in.
    """
    goals = GoalsManager(current_user).get_custom_goals()
    rewards = RewardsManager(current_user).get_custom_rewards()
    return render_template('customization.j2', goals=goals, rewards=rewards)
Esempio n. 7
0
def add_goal():
    """
    When posting to this route, add the goal given in form.
    Redirect to the customization page on completion.
    Prerequisite: User is logged in.
    """
    goal = request.form["goal"]
    added = GoalsManager(current_user).add_custom_goal(goal)
    if not added:
        flash("This is a duplicate goal. Goal not added.")
    return redirect("/customize")
Esempio n. 8
0
def delete_goal():
    """
    When retrieving this route, delete the goal given by goal_id.
    Redirect to the customization page on completion.
    Prerequisite: User is logged in.
    """
    goal_id = request.form["deleted-goal"]
    removed = GoalsManager(current_user).remove_custom_goal(goal_id)
    if removed == "current":
        flash("This goal in on your current game board; cannot be deleted")
    elif removed == "future":
        flash("This goal in on your future game board; replace and try again")
    return redirect("/customize")
Esempio n. 9
0
def verify():
    """
    This route is used in the ajax call to return a json object for when a qr code is scanned.
    """
    data = request.form["data"].split("+")

    if len(data) == 3:
        goals = GoalsManager(current_user).get_goals()
        for goal in goals:
            if str(goal['_id']) == data[1]:
                return jsonify({'goal': goal['goal']})

    elif len(data) == 4:
        rewards = RewardsManager(current_user).get_rewards()
        for reward in rewards:
            if str(reward['_id']) == data[1]:
                return jsonify({'reward': reward['reward']})

    return jsonify({'message': "Invalid QR Code!"})
Esempio n. 10
0
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 test_add__duplicate_custom_goal():
    """
    Test that add_custom_goal() function in restaurant_profile_manager.py
    does not add a custom goal to the restaurant profile, given that it is in 
    the database.
    """
    with app.app_context():
        rpm = RestaurantProfileManager("vchang")
        gm = GoalsManager(rpm)
        existing_goal_dict = gm.get_goals()
        existing_goal_list = [x['goal'] for x in existing_goal_dict]
        dupe_goal = existing_goal_list[0]
        gm.add_custom_goal(dupe_goal)
        goal_list = gm.get_goals()

        goal = [x for x in goal_list if x['goal'] == dupe_goal]

        assert len(goal) == 1
Esempio n. 12
0
def test_remove_custom_goal_on_board():
    """
    Test that the remove_custom_goal() function in 
    restaurant_profile_manager.py will not remove a goal
    that is on the board.
    """
    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"]
        for i in range(0, len(old_goals)):
            if ObjectId(old_goals[i]['_id']) in board_goals or ObjectId(
                    old_goals[i]['_id']) in future_goals:
                gm.remove_custom_goal(old_goals[i]['_id'])
                break
        new_goals = gm.get_custom_goals()
        assert len(new_goals) == len(old_goals)
Esempio n. 13
0
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)
def test_add_custom_goal():
    """
    Test that add_custom_goal() function in restaurant_profile_manager.py
    adds a custom goal to the restaurant profile, given that it is not in 
    the database.
    """
    with app.app_context():
        rpm = RestaurantProfileManager("vchang")
        gm = GoalsManager(rpm)
        existing_goal_dict = gm.get_goals()
        existing_goal_list = [x['goal'] for x in existing_goal_dict]
        count = 2
        inList = True
        while inList:
            expected_goal = "Buy " + str(count) + " desserts in one visit"
            count += 1
            if expected_goal not in existing_goal_list:
                inList = False
        gm.add_custom_goal(expected_goal)
        goal_list = gm.get_goals()

        goal = [x for x in goal_list if x['goal'] == expected_goal]

        assert (expected_goal in goal[0]['goal'])