Esempio n. 1
0
def test_set_size_price():
    mock_data = {
        "size": "large",
        "price": 4
    }
    response = app.test_client().patch('/set_size_price', json=mock_data)
    json_data = response.get_json()
    assert response.status_code == 200
    assert json_data["large"] == _read_pizza_data()["sizes"]["large"]
Esempio n. 2
0
def test_set_pizza_price():
    mock_data = {
        "name": "pepperoni",
        "price": 4
    }
    response = app.test_client().patch('/set_pizza_price', json=mock_data)
    json_data = response.get_json()
    assert response.status_code == 200
    assert json_data["pepperoni"] == _read_pizza_data()["types"]["pepperoni"]
Esempio n. 3
0
def test_add_new_topping():
    mock_data = {
        "name": "cheddar",
        "price": 2
    }
    response = app.test_client().post('/new_topping', json=mock_data)
    json_data = response.get_json()
    assert response.status_code == 200
    assert json_data["name"] in _read_pizza_data()["toppings"]
Esempio n. 4
0
def test_invalid_pizza_attribute():
    req = {
        "pizza": {
            "crust": "small",
            "type": "pepperoni",
            "toppings": ["chicken", "mushrooms"]
        }
    }
    response = app.test_client().get('display_menu_item', json=req)
    assert response.status_code == 400
Esempio n. 5
0
def test_menu_item_invalid_toppings():
    req = {
        "pizza": {
            "size": "small", 
            "type": "pepperoni", 
            "toppings": ["chick", "fajita"]
            }
        }
    response = app.test_client().get('display_menu_item', json=req)
    assert response.status_code == 400
Esempio n. 6
0
def test_menu_item_invalid_pizza_type():
    req = {
        "pizza": {
            "size": "small", 
            "type": "cheeto", 
            "toppings": ["chicken", "mushrooms"]
            }
        }
    response = app.test_client().get('display_menu_item', json=req)
    assert response.status_code == 400
Esempio n. 7
0
def test_add_new_pizza_type():
    mock_data = {
        "name": "meat lovers",
        "price": 6,
        "ingredients": ["chicken", "beef"]
    }
    response = app.test_client().post('/new_pizza', json=mock_data)
    json_data = response.get_json()
    assert response.status_code == 200
    assert json_data["name"] in _read_pizza_data()["types"]
Esempio n. 8
0
def test_order_pizzas_drinks_json():
    num_pizzas = '1'
    num_drinks = '1'
    size = ['Medium']
    type = ['Pepperoni']
    toppings = ['Beef']
    drinks = ['Coke']
    json_string = order_pizzas_drinks_json(num_pizzas, num_drinks, size, type,
                                           toppings, drinks)
    check = app.test_client().post('/new_order', json=json_string)
    assert (check.status_code == 200)
Esempio n. 9
0
def test_modify_drink_json():
    order_to_edit = '2'
    num_drink_to_update = '2'
    new_drink = 'Pepsi'
    json_string = modify_drink_json(order_to_edit, num_drink_to_update,
                                    new_drink)
    check = app.test_client().post('/modify_order/modify_drink',
                                   json=json_string)

    assert (check.status_code == 200)
    assert (check.data == b"Changes succcefully made")
Esempio n. 10
0
def test_drinks():
    for item in drinks:
        response = app.test_client().get(
            f'/pizza/drink_menu?name={item["name"]}')
        data = response.get_json()
        assert response.status_code == 200
        assert not response.data == b'not found'
        assert response.get_json()
        assert data['name'] == item['name']

    set_pizza_prices()
    response = app.test_client().get(f'/pizza/drink_menu?name=C**k')
    assert response.status_code == 200
    data = response.get_json()
    assert data['name'] == 'C**k'

    response = app.test_client().get(f'/pizza/drink_menu')
    assert response.status_code == 200
    data = response.get_json()
    assert len(data) == len(drinks)
Esempio n. 11
0
def test_get_menu():
    response = app.test_client().get('/print_menu')

    assert response.status_code == 200

    with open("Classes/Menu.json", "r") as f:
        data = json.load(f)

    menu = data

    assert json.loads(response.data) == menu
Esempio n. 12
0
def test_add_one_pizza_json():
    test_order_pizzas_drinks_json()
    order_to_edit = '2'
    size = 'Small'
    type = 'Pepperoni'
    toppings = 'Mushroom,Tomatoes'
    json_string = add_one_pizza_json(order_to_edit, size, type, toppings)
    check = app.test_client().post('/modify_order/add_pizza', json=json_string)

    assert (check.status_code == 200)
    assert (check.data == b"New pizza successfully added")
Esempio n. 13
0
def test_update_order_fail():

    data = {
        "_order_id": "11111111111111111",
        "_type": "cheese",
        "_size": "small",
        "_extra_toppings": ["feta cheese"],
        "_drink": "coke"
    }
    response = app.test_client().post('/update', json=data)

    assert response.status_code == 404
Esempio n. 14
0
def test_update_order():

    data = {
        "_order_id": "20201112165232710",
        "_type": "cheese",
        "_size": "small",
        "_extra_toppings": [],
        "_drink": "coke"
    }
    response = app.test_client().post('/update', json=data)

    assert response.status_code == 201
Esempio n. 15
0
def test_new_valid_order():
    mock_data = {
        "pizzas": [
            {"size": "small", "type": "pepperoni", "toppings": ["olives", "tomatoes"]},
            {"size": "small", "type": "margherita", "toppings": ["olives", "tomatoes"]},
            {"size": "small", "type": "vegetarian", "toppings": ["olives", "tomatoes"]},
            {"size": "small", "type": "neapolitan", "toppings": ["olives", "tomatoes"]}
                   ],
        "drinks": ["coke", "pepsi"]
    }
    response = app.test_client().post('/new_order', json=mock_data)
    assert response.status_code == 200
Esempio n. 16
0
def test_create_pizza():

    data = {
        "_type": "cheese",
        "_size": "small",
        "_extra_toppings": ["feta cheese"],
        "_drink": "coke"
    }
    response = app.test_client().post('/create', json=data)

    assert response.json["_status"] == 201
    assert response.status_code == 201
Esempio n. 17
0
def test_update_order():
    request_json = {
        'C**k': 2,
        'mushrooms': 2,
        'Pepperoni': 2,
        'order_number': 1000
    }

    response = app.test_client().post('/pizza/orders/1000', json=request_json)
    data = response.get_json()
    assert response.status_code == 200
    assert data['C**k'] == 2

    response = app.test_client().get('/pizza/orders/1001')
    assert response.status_code == 200
    data = response.get_json()
    assert data == {'order_number': 1001, 'Margherita': 2, 'Juice': 4}

    response = app.test_client().get('/pizza/orders/1001?cancel=true')
    data = response.data
    assert data == b'Order Deleted!'
Esempio n. 18
0
def test_deliver_foodora():
    data = {
        "_order_id": "20201112165232710",
        "_delivery": "foodora",
        "_address": "123 meric st"
    }
    response = app.test_client().get('/deliver', json=data)

    assert response.status_code == 200
    assert type(response.json["_order"]) == str
    assert response.json["_address"] == "123 meric st"
    assert response.json["_delivery"] == "foodora"
def test_update():
    update_order = {
        "0": {"drinks": {"water": 1}, "pizza": [{"toppings": [], "pizzaType": "pepperoni", "pizzaSize": "small"}]}}
    response = app.test_client().post("/update_order", content_type="application/json", data=json.dumps(update_order))
    assert response.data == "Order updated\n"
    assert response.status_code == 200

    with open('./order.json', 'r') as items:
        order = json.load(items)

    assert order["0"] == {"drinks": {"water": 1},
                          "pizza": [{"toppings": [], "pizzaType": "pepperoni", "pizzaSize": "small"}]}
Esempio n. 20
0
def test_get_delivery():

    response = app.test_client().get('/pizza/delivery/1000')
    data = response.get_json()
    assert response.status_code == 200
    assert data == {
        'order_number': 1000,
        'delivery': 'Uber',
        'items': {
            'Pepperoni': 2,
            'Water': 4
        }
    }
Esempio n. 21
0
def test_deliver_ubereats():
    data = {
        "_order_id": "20201112165232710",
        "_delivery": "ubereats",
        "_address": "123 depresso st"
    }
    response = app.test_client().get('/deliver', json=data)

    assert response.status_code == 200
    assert type(response.json["_order"]) == dict
    assert response.json["_address"] == "123 depresso st"
    assert response.json["_delivery"] == "ubereats"
    assert response.json["_order"]["_type"] == "cheese"
Esempio n. 22
0
def test_deliver_inhouse():
    data = {
        "_order_id": "20201112165232710",
        "_delivery": "in-house",
        "_address": "123 mertler st"
    }
    response = app.test_client().get('/deliver', json=data)

    assert response.status_code == 200
    assert type(response.json["_order"]) == dict
    assert response.json["_address"] == "123 mertler st"
    assert response.json["_delivery"] == "in-house"
    assert response.json["_order"]["_type"] == "cheese"
Esempio n. 23
0
def test_change_price_for_item():
    data = {"item": "olives", "price": 5}
    response = app.test_client().patch('/change-price-for-item', json = data)
    parsed_response = (json.loads(response.data))
    assert parsed_response == {'drink': {'Coke': 2, 'Coke Zero': 4, 'Diet Coke': 3, 'Diet Pepsi': 1, 'Dr. Pepper': 3, 'Juice': 2, 'Pepsi': 2, 'Water': 4}, 'pizza': {'size': {'L': 1.5, 'M': 1.0, 'S': 0.8}, 'topping': {'beef': 4.5, 'chicken': 2, 'jalapenos': 6, 'mushrooms': 2, 'olives': 5, 'pepperoni': 2.5, 'tomatoes': 1}, 'type': {'Neapolitan': 9, 'New': 47.0, 'margherita': 6, 'pepperonis': 12, 'vegetarian': 14.5}}}

    data = {"item": "Coke", "price": 50}
    response = app.test_client().patch('/change-price-for-item', json = data)
    parsed_response = (json.loads(response.data))
    assert parsed_response == {'drink': {'Coke': 50, 'Coke Zero': 4, 'Diet Coke': 3, 'Diet Pepsi': 1, 'Dr. Pepper': 3, 'Juice': 2, 'Pepsi': 2, 'Water': 4}, 'pizza': {'size': {'L': 1.5, 'M': 1.0, 'S': 0.8}, 'topping': {'beef': 4.5, 'chicken': 2, 'jalapenos': 6, 'mushrooms': 2, 'olives': 5, 'pepperoni': 2.5, 'tomatoes': 1}, 'type': {'Neapolitan': 9, 'New': 47.0, 'margherita': 6, 'pepperonis': 12, 'vegetarian': 14.5}}}

    data = {"item": "L", "price": 2.0}
    response = app.test_client().patch('/change-price-for-item', json = data)
    parsed_response = (json.loads(response.data))
    assert parsed_response == {'drink': {'Coke': 50, 'Coke Zero': 4, 'Diet Coke': 3, 'Diet Pepsi': 1, 'Dr. Pepper': 3, 'Juice': 2, 'Pepsi': 2, 'Water': 4}, 'pizza': {'size': {'L': 2.0, 'M': 1.0, 'S': 0.8}, 'topping': {'beef': 4.5, 'chicken': 2, 'jalapenos': 6, 'mushrooms': 2, 'olives': 5, 'pepperoni': 2.5, 'tomatoes': 1}, 'type': {'Neapolitan': 9, 'New': 47.0, 'margherita': 6, 'pepperonis': 12, 'vegetarian': 14.5}}}


    data = {"item": "something doesn't exist", "price": 5}
    response = app.test_client().patch('/change-price-for-item', json = data)
    assert response.data == b"The Item doesn't exist."

    data = {}
    response = app.test_client().patch('/change-price-for-item', json = data)
    assert response.data == b"Invalid input"
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. 25
0
    def test_07_update_order(self):
        with app.test_client() as client:
            # test 1, send valid data as POST form to endpoint
            sent = [1, ["small", "margherita", {"olive": 2, "beef": 1}], ["large", "margherita", {"olive": 2}]]
            result = client.post(
                '/update-order',
                json=sent
            )
            # check result from server with expected data
            self.assertEqual(
                json.loads(result.data),
                [1, 20.5])

            # test 2, send invalid data (absense of order number)
            sent = [["small", "margherita", {"olive": 2, "beef": 1}], ["large", "margherita", {"olive": 2}]]
            result = client.post(
                '/update-order',
                json=sent
            )
            # check result from server with invalid data
            self.assertEqual(result.status_code, 400)

            # test 3, send invalid data (invalid form of order number)
            sent = ["hello", ["small", "margherita", {"olive": 2, "beef": 1}], ["large", "margherita", {"olive": 2}]]
            result = client.post(
                '/update-order',
                json=sent
            )
            # check result from server with invalid data
            self.assertEqual(result.status_code, 400)

            # test 4, send invalid data (invalid order)
            sent = [1, ["verysmall", "margheritaa", {"olive": 2, "beef": 1}], ["large", "margherita", {"olive": 2}]]
            result = client.post(
                '/update-order',
                json=sent
            )
            # check result from server with invalid data
            self.assertEqual(result.status_code, 400)

            # test 5, send invalid data (order number does not exist)
            sent = [-99, ["small", "margherita", {"olive": 2, "beef": 1}], ["large", "margherita", {"olive": 2}]]
            result = client.post(
                '/update-order',
                json=sent
            )
            # check result from server with invalid data
            self.assertEqual(result.status_code, 404)
Esempio n. 26
0
def test_new_order():

    response_body = {
        "Pizzas": {
            "Margherita": {
                "size": "large",
                "toppings": ["onions", "tomatoes"]
            }
        },
        "Drinks": ["Coke"]
    }

    response = app.test_client().post('/new_order', json=response_body)

    assert response.status_code == 200
    assert response.data == b'Order was filled in successfully. Your orderID is: 0'
Esempio n. 27
0
def test_invalid_type_update_order():
    order = _create_mock_order()
    o = pizza_parlour.create_pizza("small", "pepperoni")
    o.add_topping("tomatoes")
    test_itemID = o.itemID
    order['pizzas'].append(o)
    order['price'] = o.get_price(pizza_parlour)
    PizzaParlour.orders.append(order)

    mock_data = {
        "pizzas": [{"itemID": test_itemID,
                    "size": "medium",
                    "type": "meat lover"}]
        }
    response = app.test_client().patch('/update_order/' + str(order["id"]), json=mock_data)
    assert response.status_code == 400
def test_order_cancel():
    default_order = {"1": {"pizza": [{"pizzaSize": "xl", "pizzaType": "pepperoni", "toppings": ["chicken", "beef"]}],
                           "drinks": {"water": 1}}}

    response = app.test_client().post("/delete_order", content_type="application/json", data=json.dumps(default_order))

    assert response.data == "Order Deleted\n"
    assert response.status_code == 200

    with open('./order.json', 'r') as items:
        order = json.load(items)

    try:
        order["1"]
    except KeyError:
        assert True == True
Esempio n. 29
0
def test_modify_pizza_json_type2():
    # Type Edit
    what_to_edit2 = '2'
    order_to_edit2 = '2'
    num_pizza_to_update2 = '2'
    new_size2 = ''
    new_type2 = 'Vegetarian'
    new_toppings2 = ''

    json_string2 = modify_pizza_json(what_to_edit2, order_to_edit2,
                                     num_pizza_to_update2, new_size2,
                                     new_type2, new_toppings2)
    check2 = app.test_client().post('/modify_order/modify_pizza',
                                    json=json_string2)

    assert (check2.status_code == 200)
    assert (check2.data == b"Changes succcefully made")
Esempio n. 30
0
def test_modify_pizza_json_type3():
    # Toppings Edit
    what_to_edit3 = '3'
    order_to_edit3 = '2'
    num_pizza_to_update3 = '2'
    new_size3 = ''
    new_type3 = ''
    new_toppings3 = 'Tomatoes,Mushroom,Basil,Pepperoni'

    json_string3 = modify_pizza_json(what_to_edit3, order_to_edit3,
                                     num_pizza_to_update3, new_size3,
                                     new_type3, new_toppings3)
    check3 = app.test_client().post('/modify_order/modify_pizza',
                                    json=json_string3)

    assert (check3.status_code == 200)
    assert (check3.data == b"Changes succcefully made")