示例#1
0
class OrderTests(APITestCase):
    """
    Create Order object for testing purpose.
    """
    def setUp(self):
        pizza_type = PizzaType.objects.create(flavour="salami",
                                              size="small",
                                              price=13.0)
        self.pizza = Pizza(pizza_type=pizza_type, quantity=3)
        self.pizza.save()
        customer = Customer.objects.create(username='******',
                                           address='Lahore, Pakistan',
                                           phone_number=1352532341)
        self.order = Order.objects.create(order_by=customer)
        self.order.pizza.add(self.pizza)
        self.order.save()

    def test_list_orders(self):
        """
        Ensure the orders list working.
        """

        url = reverse('orders-list')
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

    def test_delete_order(self):
        """
        Delete order bu providing order id.
        """

        url = reverse('orders-detail', kwargs={'pk': self.order.id})
        response = self.client.delete(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
示例#2
0
def order():
    if request.method == 'GET':
        session.clear()
    data = db.session.query(Config).first()
    if data.state != 'ordering':
        return redirect("/")
    form = OrderForm(request.form)
    if request.method == 'POST' and form.validate():
        db.session.rollback()
        db.session.expunge_all()
        if form.item.data == 'half':
            order = Half()
            order.email = form.email.data + EMAIL_DOMAIN
            order.location = form.location.data
            order.topping1 = form.topping1.data
            order.topping2 = form.topping2.data
            order.topping3 = form.topping3.data
        elif form.item.data == 'whole':
            order = Pizza()
            person = Person()
            order.topping1_left = form.topping1.data
            order.topping2_left = form.topping2.data
            order.topping3_left = form.topping3.data
            order.topping1_right = form.topping4.data
            order.topping2_right = form.topping5.data
            order.topping3_right = form.topping6.data
            order.sauce = form.sauce.data
            order.size = 'Large'
            person.email = form.email.data + EMAIL_DOMAIN
            person.location = form.location.data
            order.person1 = person
            db.session.add(person)
        elif form.item.data == 'medium':
            order = Pizza()
            person = Person()
            order.topping1_left = form.topping1.data
            order.topping2_left = form.topping2.data
            order.topping1_right = form.topping4.data
            order.topping2_right = form.topping5.data
            order.sauce = form.sauce.data
            order.size = 'Medium'
            person.email = form.email.data + EMAIL_DOMAIN
            person.location = form.location.data
            order.person1 = person
            db.session.add(person)
        order.time_added = datetime.datetime.now()
        db.session.add(order)
        db.session.flush()
        session['order_id'] = order.id
        session['order_type'] = type(order).__name__
        session['payment_amount'] = set_price(form)
        url = 'https://api.venmo.com/v1/oauth/authorize?client_id={}&scope=make_payments&response_type=code'.format(
            CONSUMER_ID)
        return redirect(url)
    return render_template('order.html',
                           data=data,
                           form=form,
                           domain=EMAIL_DOMAIN,
                           large_price=LARGE_PRICE,
                           medium_price=MEDIUM_PRICE)
示例#3
0
 def setUp(self):
     pizza_type = PizzaType.objects.create(flavour="salami",
                                           size="small",
                                           price=13.0)
     self.pizza = Pizza(pizza_type=pizza_type, quantity=3)
     self.pizza.save()
     customer = Customer.objects.create(username='******',
                                        address='Lahore, Pakistan',
                                        phone_number=1352532341)
     self.order = Order.objects.create(order_by=customer)
     self.order.pizza.add(self.pizza)
     self.order.save()
示例#4
0
 def setUp(self):
     self.user_jerry = User(username='******',
                            password='******',
                            email='*****@*****.**')
     self.new_pizza = Pizza(pizza_contents="My pizza",
                            pizza_category='Order',
                            user=self.user_jerry)
示例#5
0
    def pizzas():
        if request.method == "POST":
            flavour = str(request.data.get('flavour', ''))
            size = str(request.data.get('size', ''))
            price = str(request.data.get('cost', '899'))
            crust = str(request.data.get('crust', ''))
            toppings = str(request.data.get('toppings', ''))
            if flavour:
                pizza = Pizza(flavour=flavour,
                              size=size,
                              price=price,
                              crust=crust,
                              toppings=toppings)
                pizza.save_pizza()
                response = jsonify({
                    'id': pizza.id,
                    'flavour': pizza.flavour,
                    'size': pizza.size,
                    'price': pizza.price,
                    'crust': pizza.crust,
                    'toppings': pizza.toppings
                })
                response.status_code = 201
                return response

        else:
            pizzas = Pizza.get_all()
            results = []

            for pizza in pizzas:
                obj = {
                    'id': pizza.id,
                    'flavour': pizza.flavour,
                    'size': pizza.size,
                    'price': pizza.price,
                    'crust': pizza.crust,
                    'toppings': pizza.toppings
                }
            results.append(obj)
            response = jsonify(results)
            return response
示例#6
0
    def create(self, validated_data):
        types = PizzaType.objects.all()
        pizza = validated_data.get('pizza')
        customer = validated_data.get('order_by')
        member = Customer.objects.filter(
            phone_number=customer.get('phone_number'))
        member = Customer.objects.create(
            **customer) if not member.exists() else member.first()
        data = {
            'order_by': member,
            'payment_type': validated_data.get('payment_type', 'cash'),
            'description': validated_data.get('description')
        }
        order = Order.objects.create(**data)

        for p in pizza:
            pizza_type = types.filter(flavour=p.get('flavour'),
                                      size=p.get('size')).first()
            pizza_obj = Pizza(pizza_type=pizza_type,
                              quantity=p.get('quantity'))
            pizza_obj.save()
            order.pizza.add(pizza_obj)
        return order
示例#7
0
    def pizzas():
        if request.method == "POST":
            name = str(request.data.get('name', ''))
            size = str(request.data.get('size', ''))
            price = str(request.data.get('price', ''))
            crust = str(request.data.get('crust', ''))
            if name:
                piza = Pizza(name=name, size=size, price=price, crust=crust)
                piza.save()
                response = jsonify({
                    'id': piza.id,
                    'name': piza.name,
                    'size': piza.size,
                    'price': piza.price,
                    'crust': piza.crust,
                })
                response.status_code = 201
                return response
        else:
            # GET
            piza = Pizza.get_all()
            results = []
            results_obj = {}

            for items in piza:
                obj = {
                    'id': items.id,
                    'name': items.name,
                    'size': items.size,
                    'price': items.price,
                    'crust': items.crust,
                }
                results_obj["results"] = results
                results_obj.append(obj)
            response = jsonify(results_obj)
            response.status_code = 200
            return response
示例#8
0
def update():
    form = UpdateMenu()
    if form.validate_on_submit():
        pizza = Pizza(pizza=form.pizza.data,
                      pizza_amount=form.pizza_amount.data,
                      p_size=form.p_size.data,
                      crust=form.crust.data,
                      crust_amount=form.crust_amount.data,
                      toppings=form.toppings.data,
                      top_size=form.top_size.data)

        db.session.add(pizza)
        db.session.commit()

        flash('Menu created', 'success')
        return redirect(url_for('admin'))

    title = 'Menu updata page'
    return render_template('updated_menu.html', title=title, form=form)