def test_checkout_ubereats_already_complete():
    app.test_client().get('/order')
    drink = Drink("coke", 1.88).serialize()
    response = app.test_client().post('/order/3/drink',
                                      json=drink,
                                      headers=HEADERS)
    address = "123 Banana Street"
    order_details = {
        "dietcoke": {
            "price": 1.66,
            "quantity": 1
        },
        "medium-pepperoni": {
            "price": 13.98,
            "quantity": 1
        },
        "subtotal": 15.64,
        "total": 17.67
    }
    order = {
        "order_number": 3,
        "address": address,
        "order_details": order_details
    }
    response = app.test_client().post('/checkout/ubereats',
                                      json=order,
                                      headers=HEADERS)

    assert response.status_code == 400
    assert response.data == b'Order 3 is already complete'
def test_checkout_pickup():
    drink = Drink("coke", 1.88).serialize()
    response = app.test_client().post('/order/2/drink',
                                      json=drink,
                                      headers=HEADERS)
    address = "123 Banana Street"
    order_details = {
        "dietcoke": {
            "price": 1.66,
            "quantity": 1
        },
        "medium-pepperoni": {
            "price": 13.98,
            "quantity": 1
        },
        "subtotal": 15.64,
        "total": 17.67
    }
    order = {
        "order_number": 2,
        "address": address,
        "order_details": order_details
    }
    response = app.test_client().post('/checkout/pickup',
                                      json=order,
                                      headers=HEADERS)

    assert response.status_code == 200
    assert response.data == b'Order 2 complete. Ready for pickup. Subtotal is $1.88. Total is $2.12'
def test_checkout_pickup_order_does_not_exist():
    drink = Drink("coke", 1.88).serialize()

    response = app.test_client().post('/order/6/drink',
                                      json=drink,
                                      headers=HEADERS)
    assert response.status_code == 400
    assert response.data == b'Order does not exist'
def test_remove_drink():
    drink = Drink("coke", 1.88).serialize()
    response = app.test_client().delete('/order/1/drink',
                                        json=drink,
                                        headers=HEADERS)

    assert response.status_code == 200
    assert response.data == b'coke item removed!'
def add_or_remove_drink(order_number):
    order = orders.get_order(int(order_number))
    # Check if order exists or if order has been checked out
    valid_error = is_valid_order(order)
    if (valid_error):
        return valid_error
    # Otherwise, Add drink if POST
    req_data = request.get_json()
    drink_name = req_data['name']
    if request.method == 'POST':
        drink_price = req_data['price']
        order.add_item(Drink(drink_name, drink_price))
        return str(drink_name) + " item added!"
    # Or Remove drink if DELETE
    elif request.method == 'DELETE':
        removeResult = order.remove_item(drink_name)
        if removeResult:
            return removeResult
        else:
            return str(drink_name) + " item removed!"
def test_checkout_foodora():
    app.test_client().get('/order')
    drink = Drink("coke", 1.88).serialize()
    response = app.test_client().post('/order/4/drink',
                                      json=drink,
                                      headers=HEADERS)
    address = "123 Banana Street"
    order_details = {
        "dietcoke": {
            "price": 1.66,
            "quantity": 1
        },
        "medium-pepperoni": {
            "price": 13.98,
            "quantity": 1
        },
        "subtotal": 15.64,
        "total": 17.67
    }
    order = {
        "order_number": 4,
        "address": address,
        "order_details": order_details
    }
    csv_columns = ['order_number', "carrier", 'address', 'order_details']
    csvfile = io.StringIO()
    writer = csv.DictWriter(csvfile, fieldnames=csv_columns)
    writer.writeheader()
    writer.writerow(order)
    csv_string = csvfile.getvalue()
    response = app.test_client().post('/checkout/foodora',
                                      data=csv_string,
                                      headers=HEADERS)

    assert response.status_code == 200
    assert response.data == b'Order 4 complete. Delivering to 123 Banana Street via Foodora. Subtotal is $1.88. Total is $2.12'
Esempio n. 7
0
from MenuItem import PredefinedPizza, Pizza, Drink, Topping, Menu


def priceReader(filename):
    d = dict()
    with open("prices/" + filename) as f:
        for line in f:
            (key, val) = line.split()
            d[key] = float(val)
    return d


drinkPrices = priceReader("drinks.txt")
toppingPrices = priceReader("toppings.txt")
pizzaPrices = priceReader("pizzas.txt")

menu = Menu()

for key in pizzaPrices:
    p = PredefinedPizza(key, pizzaPrices[key])
    menu.add_pizza(p)

for key in drinkPrices:
    d = Drink(key, drinkPrices[key])
    menu.add_drink(d)

for key in toppingPrices:
    d = Topping(key, toppingPrices[key])
    menu.add_topping(d)