Example #1
0
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_reward_progress_empty():
    """
    Test that get_reward_progress() returns empty data for users with no reward progress.
    """
    with app.app_context():
        cpm = CustomerProfileManager("newuser")
        assert get_reward_progress(cpm) == ([], [])
Example #3
0
def test_get_favourite_doc():
    """
    Test that get_favourite_doc() returns a dictionary of favourite
    restaurant profiles.
    """
    with app.app_context():
        cpm = CustomerProfileManager("testuser")
        rpm = RestaurantProfileManager("")
        ppm = PublicProfileModifier(rpm)
        all_profiles = ppm.get_public_profiles()
        favourite = get_favourite(cpm)
        profiles = get_favourite_doc(all_profiles, favourite)
        expected_fields = ["name", "category", "image", "is_public"]

        has_id = True
        has_fields = True
        is_public = True
        for key in list(profiles.keys()):
            if type(key) != ObjectId:
                has_id = False
                break
            fields = list(profiles[key].keys())
            for f in expected_fields:
                if f not in fields:
                    has_fields = False
                    break
            if profiles[key]["is_public"] == False:
                is_public = False
                break

    assert len(profiles) > 0 and has_id and has_fields and is_public
Example #4
0
def test_get_no_favourite():
    """
    Test that get_favourite() returns an empty list of restaurant ids
    if user has no favourites.
    """
    with app.app_context():
        cpm = CustomerProfileManager("unittestuser")
        favourite = get_favourite(cpm)
        assert len(favourite) == 0
Example #5
0
def test_get_favourites():
    """
    Test that get_favourite() returns a list of restaurant ids.
    """
    with app.app_context():
        rpm = RestaurantProfileManager("")
        cpm = CustomerProfileManager("ksawyer")
        favourite = get_favourite(cpm)
        assert len(favourite) > 0
Example #6
0
def test_set_board_progress_no_progress():
    """
    Test that set_board_progress() updates all goals on a bingo board to incomplete.
    """
    with app.app_context():
        rpm = RestaurantProfileManager("")
        board = GameBoardManager(rpm).get_restaurant_board_by_id(
            "5f15c084143cb39bfc5619b8")
        cpm = CustomerProfileManager("newuser")

        set_board_progress(cpm, board, "5f15c084143cb39bfc5619b8")

        for goal in board["board"]:
            assert not goal["is_complete"]
Example #7
0
def test_update_favourite():
    """
    Test that update_favourite() updates the user's list of favourite
    restaurant Ids.
    """
    with app.app_context():
        cpm = CustomerProfileManager("ksawyer")
        old_favourite = get_favourite(cpm)
        if ObjectId('5f15c084143cb39bfc5619b8') in old_favourite:
            expected = len(old_favourite) - 1
        else:
            expected = len(old_favourite) + 1
        new_favourite = update_favourite(cpm, '5f15c084143cb39bfc5619b8')
    assert len(new_favourite) == expected
def test_show_rewards_qr_code(client):
    """
    Test that the shwo rewards interface contains the correct QR code for each active reward.
    """
    client.post("/login",
                data={
                    "username": "******",
                    "password": "******"
                })
    res = client.get("/personal/rewards", follow_redirects=True)

    progress = get_reward_progress(CustomerProfileManager("showrewardsuser"))

    for reward in progress[0]:
        assert str.encode(reward["redemption_code"]) in res.data
Example #9
0
def test_set_board_progress_some_progress():
    """
    Test that set_board_progress() updates all goals on a bingo board to the correct progress info.
    """
    with app.app_context():
        rpm = RestaurantProfileManager("")
        board = GameBoardManager(rpm).get_restaurant_board_by_id(
            "5f15c084143cb39bfc5619b8")
        cpm = CustomerProfileManager("unittestuser")

        set_board_progress(cpm, board, "5f15c084143cb39bfc5619b8")

        for i in range(len(board["board"])):
            if i in [0, 8, 14, 23]:
                assert board["board"][i]["is_complete"]
            else:
                assert not board["board"][i]["is_complete"]
def test_get_reward_progress_non_empty():
    """
    Test that get_reward_progress() returns correct data for users with reward progress.
    """
    with app.app_context():
        cpm = CustomerProfileManager("showrewardsuser")
        expected_progress = ([{
            'is_redeemed': False,
            'redemption_code': '4209cf81f02e409690930032ed771465',
            'restaurant_name': 'KFC',
            'text': 'One Free Drink Refill'
        }, {
            'is_redeemed': False,
            'redemption_code': '43adf2823896a666d8000fb5ffea7666',
            'restaurant_name': 'KFC',
            'text': '15% Off A Purchase'
        }, {
            'is_redeemed': False,
            'redemption_code': '06e9ac1d92cbfad29f55a3efee01bd41',
            'restaurant_name': 'Too Good To Be True',
            'text': '$3 Off Any Entree'
        }], [{
            'is_redeemed': True,
            'redemption_code': '14991fd515dbd032152e59d9db6bd4b5',
            'redemption_date': 'July 28, 2020',
            'restaurant_name': 'KFC',
            'text': '$10 Off Any $50+ Purchase'
        }, {
            'is_redeemed': True,
            'redemption_code': '54a3c1b86dfbfa0cc00cf1c7c7e8d211',
            'redemption_date': 'May 20, 2018',
            'restaurant_name': 'KFC',
            'text': 'Free Dessert'
        }, {
            'is_redeemed': True,
            'redemption_code': '43adf2823896a666d8000fb5ffea7666',
            'redemption_date': 'July 11, 2006',
            'restaurant_name': 'KFC',
            'text': '10% Off A Purchase'
        }])
        assert get_reward_progress(cpm) == expected_progress