def test_mark_as_done(client, app): """test mark done page""" with app.app_context(): sburger = Stock(name="burger", amount=10) swrap = Stock(name="wrap", amount=10) db.session.add(sburger) db.session.add(swrap) imain = Item(name="main") iburger = Item(name="burger") iwrap = Item(name="wrap") gtype = IngredientGroup(name="type", min_item=1, max_item=1, min_option=1, max_option=1) db.session.add(imain) db.session.add(iburger) db.session.add(iwrap) db.session.add(gtype) sburger.items.append(iburger) swrap.items.append(iwrap) gtype.options.append(iburger) gtype.options.append(iwrap) imain.ingredientgroups.append(gtype) db.session.commit() user = User(name="Dickson", email="*****@*****.**", user_type=UserType.ADMIN) user.SetPassword("123456") user2 = User(name="Superman", email="*****@*****.**", user_type=UserType.CUSTOMER) user2.SetPassword("123456") order = Order(status=OrderStatus.PAID, price=100) user2.orders.append(order) order.AddRootItem(imain.GetID(), 1) order.AddIG("0.0", [iburger.GetID()], [1]) db.session.add(user) db.session.add(user2) db.session.add(order) db.session.commit() login(client, "*****@*****.**", "123456") order = Order.query.get(order.GetID()) response = client.get('/order/%d' % order.GetID()) assert b"paid" in response.data client.get('/admin/order/%d/done' % order.GetID()) response = client.get('/order/%d' % order.GetID()) assert b"ready" in response.data
def test_stock_list(app, client): """test inventory list""" names = [ "Muffin Bun", "Sesame Bun", "Standard Bun", "Wrap", "Chicken Patty", "Beef Patty", "Vegetarian Patty", "Tuna Patty", "Tomato", "Tomato Sauce", "BBQ Sauce", "Mint Sauce", "Chocolate Sauce", "Cheddar Cheese", "Nuggets", "Fries (g)", "Coke (ml)", "Sundaes (ml)" ] with app.app_context(): user = User(name="Dickson", email="*****@*****.**", user_type=UserType.ADMIN) user.SetPassword("123456") db.session.add(user) db.session.commit() stock_amount = 100 for name in names: db.session.add(Stock(name=name, amount=stock_amount)) stock_amount += 1 db.session.commit() response = client.get('/admin/inventory') assert response.status == '302 FOUND' login(client, "*****@*****.**", "123456") response = client.get('/admin/inventory') rsp = str(response.data) print(rsp) stock_amount = 100 for name in names: assert name in rsp rsp = rsp[rsp.find(name) + 1:] assert str(stock_amount) in rsp rsp = rsp[rsp.find(str(stock_amount)) + 1:] stock_amount += 1
def test_checkout_page(client, app): """ Test checkout page """ with app.app_context(): sburger = Stock(name="burger", amount=10) swrap = Stock(name="wrap", amount=10) db.session.add(sburger) db.session.add(swrap) imain = Item(name="main") iburger = Item(name="burger") iwrap = Item(name="wrap") gtype = IngredientGroup( name="type", min_item=1, max_item=1, min_option=1, max_option=1) db.session.add(imain) db.session.add(iburger) db.session.add(iwrap) db.session.add(gtype) sburger.items.append(iburger) swrap.items.append(iwrap) gtype.options.append(iburger) gtype.options.append(iwrap) imain.ingredientgroups.append(gtype) db.session.commit() user = User( name="Dickson", email="*****@*****.**", user_type=UserType.ADMIN) user.SetPassword("123456") user2 = User( name="Superman", email="*****@*****.**", user_type=UserType.CUSTOMER) user2.SetPassword("123456") order = Order(status=OrderStatus.PAID, price=100) user2.orders.append(order) order.AddRootItem(imain.GetID(), 1) order.AddIG("0.0", [iburger.GetID()], [1]) db.session.add(user) db.session.add(user2) db.session.add(order) db.session.commit() login(client, "*****@*****.**", "123456") order = Order.query.get(order.GetID()) response = client.get('/order/%d' % order.GetID()) # Check if the customer can see the unique ID for the order. assert str(order.GetID()).encode("utf-8") in response.data client.get('/admin/order/%d/done' % order.GetID()) # Check if the customer can see the details of his order. assert order.GetDetailsString().encode("utf-8") in response.data
def test_user_password(): """ Test user password """ user = User(email="*****@*****.**", user_type=0) user.SetPassword("test_pwd") assert user.VerifyPassword("test_pwd") assert not user.VerifyPassword("wrong_pwd") assert not user.VerifyPassword(None)
def test_invalid_length_for_new_password(): """ Test new password with invalid length (< 4 or > 20) provided by user """ user = User(email="*****@*****.**", user_type=0) user_password = "******" user.SetPassword(user_password) new_password1 = "pwd" with pytest.raises(ValueError): user.SetPassword(new_password1) assert not user.VerifyPassword(new_password1) assert user.VerifyPassword(user_password) new_password2 = "I love meatball and tuna." with pytest.raises(ValueError): user.SetPassword(new_password2) assert not user.VerifyPassword(new_password2) assert user.VerifyPassword(user_password)
def test_index(client, app): """ Test customer index """ with app.app_context(): response = client.get('/') assert b"Welcome!" in response.data user = User( name="Jeff", email="*****@*****.**", user_type=UserType.CUSTOMER) user.SetPassword("123456") db.session.add(user) db.session.commit() login(client, "*****@*****.**", "123456") response = client.get('/') assert b"Welcome, Jeff" in response.data
def test_order_list(client, app): """test order list page""" with app.app_context(): order = Order(price=123, status=OrderStatus.PAID) db.session.add(order) db.session.commit() timestamp = order.GetCreatedAt() user = User(name="Dickson", email="*****@*****.**", user_type=UserType.ADMIN) user.SetPassword("123456") db.session.add(user) db.session.commit() login(client, "*****@*****.**", "123456") response = client.get('/admin/orderlist') rsp = str(response.data) assert "ID" in rsp assert "User Name" in rsp assert "Price" in rsp assert "Created at" in rsp assert "Updated at" in rsp assert "Status" in rsp assert "123" in rsp assert "paid" in rsp assert str(timestamp) in rsp with app.app_context(): order1 = Order(price=231, status=OrderStatus.PAID) db.session.add(order1) db.session.commit() response = client.get('/admin/orderlist') rsp = str(response.data) assert "231" in rsp position = rsp.find("123") position1 = rsp.find("231") assert position1 < position
def test_order_details(client, app): """ Test correct order details on front end """ with app.app_context(): sburger = Stock(name="burger", amount=10) swrap = Stock(name="wrap", amount=10) db.session.add(sburger) db.session.add(swrap) imain = Item(name="main") iburger = Item(name="burger") iwrap = Item(name="wrap") gtype = IngredientGroup(name="type", min_item=1, max_item=1, min_option=1, max_option=1) db.session.add(imain) db.session.add(iburger) db.session.add(iwrap) db.session.add(gtype) sburger.items.append(iburger) swrap.items.append(iwrap) gtype.options.append(iburger) gtype.options.append(iwrap) imain.ingredientgroups.append(gtype) db.session.commit() user = User(name="Dickson", email="*****@*****.**", user_type=UserType.ADMIN) user.SetPassword("123456") user1 = User(name="123", email="*****@*****.**", user_type=UserType.CUSTOMER) user1.SetPassword("123456") user2 = User(name="Superman", email="*****@*****.**", user_type=UserType.CUSTOMER) user2.SetPassword("123456") order = Order(status=OrderStatus.PAID, price=100) user2.orders.append(order) order.AddRootItem(imain.GetID(), 1) order.AddIG("0.0", [iburger.GetID()], [1]) db.session.add(user) db.session.add(user1) db.session.add(user2) db.session.add(order) db.session.commit() login(client, "*****@*****.**", "654321") response = client.get('/order/%d' % order.GetID()) assert response.status == '302 FOUND' login(client, "*****@*****.**", "123456") response = client.get('/order/%d' % order.GetID()) assert b"Superman" in response.data assert order.GetDetailsString().encode("utf-8") in response.data if order.GetStatusText() != "ready": assert b"Mark as done" in response.data login(client, "*****@*****.**", "123456") response = client.get('/order/%d' % order.GetID()) assert response.status == '302 FOUND' login(client, "*****@*****.**", "123456") response = client.get('/order/%d' % order.GetID()) assert b"Superman" in response.data # Check if the user can see his unique order ID in the details page. assert "ORDER {0}".format( order.GetID()).encode("utf-8") in response.data # Customer shouldn't have access to details page of unpaid orders order.SetStatus(OrderStatus.CREATED) db.session.commit() response = client.get('/order/%d' % order.GetID()) assert response.status == '302 FOUND'