def test_get_board_by_id(): """ Test that get_restaurant_board_by_id() returns the correct bingo board information. """ with app.app_context(): rpm = RestaurantProfileManager("") board = GameBoardManager(rpm).get_restaurant_board_by_id( "5f15c084143cb39bfc5619b8") assert board["name"] == "KFC Rewards" assert board["board"][0] == { "_id": ObjectId("5f15c1b3143cb39bfc5619b9"), "goal": "resignation" } assert board["board"][12] == { "_id": ObjectId("5f15c1de143cb39bfc5619c5"), "goal": "inch" } assert board["board"][24] == { "_id": ObjectId("5f15c200143cb39bfc5619d1"), "goal": "transmission" } assert board["board_reward"][0] == { "_id": ObjectId("5f03aa437aae4a086d810107"), "reward": "One free drink refill" } assert board["board_reward"][5] == { "_id": ObjectId("5f03aa0b7aae4a086d810103"), "reward": "Free appetizer" } assert board["board_reward"][11] == { "_id": ObjectId("5f03aa437aae4a086d810107"), "reward": "One free drink refill" }
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) == ([], [])
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
def test_get_restaurant_name_by_id_invalid(): """ Test that get_restaurant_name_by_id() returns "" for invalid ids. """ with app.app_context(): rpm = RestaurantProfileManager("") username = rpm.get_restaurant_name_by_id("not a real id") assert username == ""
def test_get_restaurant_name_by_id_valid(): """ Test that get_restaurant_name_by_id() returns the restaurant name of a valid user correctly. """ with app.app_context(): rpm = RestaurantProfileManager("") username = rpm.get_restaurant_name_by_id("5f15c084143cb39bfc5619b8") assert username == "KFC"
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
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
def test_get_restaurant_users(): """ Test that the get_restaurant_users() function in customer_profile_manager.py retrieves all all restaurant users. """ with app.app_context(): user = RestaurantProfileManager("vchang") ppm = PublicProfileModifier(user) users = ppm.get_public_profiles() assert len(users) != 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"]
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_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_restaurant_profile_by_id(): """ Test that get_restaurant_profile_by_id() returns the correct restaurant profile information. """ with app.app_context(): rpm = RestaurantProfileManager("") ppm = PublicProfileModifier(rpm) profile = ppm.get_restaurant_profile_by_id("5f15c084143cb39bfc5619b8") assert profile["name"] == "KFC" assert profile["category"] == "Chicken" assert profile["description"] == "The best fried chicken on the block." assert profile["phone_number"] == "416-267-0439"
def test_view_board_goal_qr_code_data(client): """ Test that the data for goal QR codes are being set correctly. """ with app.app_context(): client.post("/login", data={ "username": "******", "password": "******" }) res = client.get("/restaurants/5f0df6a10bb07c8199d4405a/board", follow_redirects=True) rpm = RestaurantProfileManager("") bpm = GameBoardManager(rpm) board = bpm.get_restaurant_board_by_id("5f0df6a10bb07c8199d4405a") for i in range(len(board["board"])): assert str.encode("unittestuser+{}+{}".format( board["board"][i]["_id"], i)) in res.data
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
def create_app(): app = Flask(__name__) with app.app_context(): init_db() return app
def db(client): """ Return a database instance. """ with app.app_context(): return Database.get_instance()