Ejemplo n.º 1
0
def test_invalid_reward(client):
    """
    Test that a user can't complete an invalid reward.
    """
    with app.app_context():
        rpm = RestaurantProfileManager("junaid")
        rm = RewardsManager(rpm)
        code = "junaid+5f03a9fd7aae4a086d810102+7".split("+")
        msg = rm.complete_reward(code[0], "junaid+5f03a9fd7aae4a086d810102+7")
        assert msg == "Invalid QR code!"
Ejemplo n.º 2
0
def test_valid_completed_reward(client):
    """
    Test that a user can mark a valid reward as complete.
    """
    with app.app_context():
        rpm = RestaurantProfileManager("junaid")
        rm = RewardsManager(rpm)
        code = "junaid+5f03a9fd7aae4a086d810102+6".split("+")
        msg = rm.complete_reward(code[0], "junaid+5f03a9fd7aae4a086d810102+6")
        assert msg == "Code has already been redeemed!"
Ejemplo n.º 3
0
def test_duplicate_completed_reward(client):
    """
    Test that a duplicate reward can't be completed again.
    """
    with app.app_context():
        rpm = RestaurantProfileManager("junaid")
        rm = RewardsManager(rpm)
        code = "junaid+5f03a9fd7aae4a086d810102+6".split("+")
        msg = rm.complete_reward(code[0], "junaid+5f03a9fd7aae4a086d810102+6")
        assert msg == "Code has already been redeemed!"
def test_get_rewards_old_user():
    """
    Test that get_rewards() inrestaurant_profile_manager.py for an existin
    user retrieves a list of their available rewards.
    """
    with app.app_context():
        rpm = RestaurantProfileManager("vchang")
        rm = RewardsManager(rpm)
        rewards = rm.get_rewards()
        expected_rewards = [{
            '_id': ObjectId('5f03a9df7aae4a086d810100'),
            'reward': '$5 off a purchase of $30+'
        }, {
            '_id': ObjectId('5f03a9fd7aae4a086d810102'),
            'reward': 'Free drink'
        }, {
            '_id':
            ObjectId('5f03aa287aae4a086d810105'),
            'reward':
            'Buy one entree, get another 50% off (of lesser or equal value)'
        }, {
            '_id': ObjectId('5f03aa1a7aae4a086d810104'),
            'reward': 'Free dessert'
        }, {
            '_id': ObjectId('5f03a9c87aae4a086d8100ff'),
            'reward': '$10 off a purchase of $50+'
        }, {
            '_id': ObjectId('5f03aa0b7aae4a086d810103'),
            'reward': 'Free appetizer'
        }, {
            '_id': ObjectId('5f03a9967aae4a086d8100fd'),
            'reward': '10% off a purchase'
        }, {
            '_id': ObjectId('5f03aa377aae4a086d810106'),
            'reward': '$3 off any entree'
        }, {
            '_id': ObjectId('5f03aa437aae4a086d810107'),
            'reward': 'One free drink refill'
        }, {
            '_id': ObjectId('5f03aa507aae4a086d810108'),
            'reward': 'All desserts $6 each'
        }, {
            '_id': ObjectId('5f03a9b57aae4a086d8100fe'),
            'reward': '15% off a purchase'
        }, {
            '_id': ObjectId('5f03a9ec7aae4a086d810101'),
            'reward': '$5 gift voucher'
        }]
        assert rewards == expected_rewards
def test_get_custom_rewards():
    """
    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")
        rm = RewardsManager(rpm)
        rewards = rm.get_custom_rewards()
        has_fields = True
        for reward in rewards:
            if reward['_id'] is None and reward['goal'] is None:
                has_fields = False

        assert len(rewards) >= 0 and has_fields
Ejemplo n.º 6
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
            }
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
def add_reward():
    """
    When posting to this route, add the reward given in form.
    Redirect to the customization page on completion.
    Prerequisite: User is logged in.
    """
    reward = request.form["reward"]
    added = RewardsManager(current_user).add_custom_reward(reward)
    if not added:
        flash("This is a duplicate reward. Reward not added.")
    return redirect("/customize")
def test_add_custom_reward():
    """
    Test that add_custom_reward() function in restaurant_profile_manager.py
    adds a custom reward to the restaurant profile, given that it is not in
    the database.
    """
    with app.app_context():
        rpm = RestaurantProfileManager("vchang")
        rm = RewardsManager(rpm)
        existing_reward_dict = rm.get_rewards()
        existing_reward_list = [x['reward'] for x in existing_reward_dict]
        count = 2
        in_list = True
        while in_list:
            expected_reward = "Get " + str(
                count) + " free desserts in one visit"
            count += 1
            if expected_reward not in existing_reward_list:
                in_list = False
        rm.add_custom_reward(expected_reward)
        reward_list = rm.get_rewards()

        reward = [x for x in reward_list if x['reward'] == expected_reward]

        assert expected_reward in reward[0]['reward']
Ejemplo n.º 10
0
def delete_reward():
    """
    When retrieving this route, delete the reward given by reward_id.
    Redirect to the customization page on completion.
    Prerequisite: User is logged in.
    """
    reward_id = request.form["deleted-reward"]
    removed = RewardsManager(current_user).remove_custom_reward(reward_id)
    if removed == "current":
        flash("This reward in on your current game board; cannot be deleted")
    elif removed == "future":
        flash(
            "This reward in on your future game board; replace and try again")
    return redirect("/customize")
Ejemplo n.º 11
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!"})
Ejemplo n.º 12
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"])
Ejemplo n.º 13
0
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_add__duplicate_custom_reward():
    """
    Test that add_custom_reward() function in restaurant_profile_manager.py
    does not add a custom reward to the restaurant profile, given that it is in
    the database.
    """
    with app.app_context():
        rpm = RestaurantProfileManager("vchang")
        rm = RewardsManager(rpm)
        existing_reward_dict = rm.get_rewards()
        existing_reward_list = [x['reward'] for x in existing_reward_dict]
        dupe_reward = existing_reward_list[0]
        rm.add_custom_reward(dupe_reward)
        reward_list = rm.get_rewards()

        reward = [x for x in reward_list if x['reward'] == dupe_reward]

        assert len(reward) == 1
Ejemplo n.º 15
0
def test_remove_custom_reward():
    """
    Test that the remove_custom_reward() function in
    restaurant_profile_manager.py can be used to remove
    a user's custom reward.
    """
    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"]
        found = False
        for i in range(0, len(old_rewards)):
            if ObjectId(old_rewards[i]['_id']) not in board_rewards:
                found = True
                rm.remove_custom_reward(old_rewards[i]['_id'])
                break
        new_rewards = rm.get_custom_rewards()
        assert (len(new_rewards) == len(old_rewards) and not found) or \
               (len(new_rewards) == (len(old_rewards) - 1) and found)