def process_order():
    """Process an order submitted from the '/order_melons' route."""

    # gather form data
    melon_id = request.form.get('melon_id')
    quantity = int(request.form.get('qty'))

    # get info for this melon
    melon_info = melons[melon_id]

    # get the shipping cost
    state = request.form.get('state')
    shipping = calculate_shipping(state)

    # calculate the total
    price = melon_info['price']
    total = quantity * price + shipping

    # flash a message
    confirm = "You have ordered {} {}. ".format(quantity, melon_info['name'])
    confirm += "Your order total comes to ${0:.2f}".format(total)
    flash(confirm)

    # send them back to the home page
    return redirect('/melons')
Exemple #2
0
    def test_cali(self):
        """Test shipping for California."""

        cali_shipping = shipping.calculate_shipping('CA')
        self.assertEqual(cali_shipping, 0)
Exemple #3
0
    def test_indiana(self):
        """Test shipping for Indiana."""

        in_shipping = shipping.calculate_shipping('IN')
        self.assertEqual(in_shipping, 5)
Exemple #4
0
    def test_alaska(self):
        """Test shipping for Alaska."""

        ak_shipping = shipping.calculate_shipping('AK')
        self.assertEqual(ak_shipping, 20)