Exemplo n.º 1
0
 def test_orders_inserts(self):
     self.test_users_inserts()
     i1 = Item(title='Acabaxi',
               description='A great abacaxi. Very big.',
               price=5,
               restaurant_id=1)
     i2 = Item(title='Banana',
               description='A great bannanana. Very big.',
               price=3,
               restaurant_id=1)
     db.session.add(i1)
     db.session.add(i2)
     o1 = Order()
     db.session.add(o1)
     db.session.flush()
     db.session.refresh(o1)
     db.session.refresh(i1)
     db.session.refresh(i2)
     o1.orderitems.append(
         OrderItem(order_id=o1.id, item_id=i1.id, quantity=2))
     o1.orderitems.append(
         OrderItem(order_id=o1.id, item_id=i2.id, quantity=1))
     db.session.commit()
     retrieved = Order.find_by_id(o1.id)
     self.assertEquals(retrieved.total_price(), 2 * i1.price + i2.price)
Exemplo n.º 2
0
 def patch(self):
     """ pays an order """
     try:
         self.reqparse.add_argument('order_id', type=int, location='json')
         data = self.reqparse.parse_args()
         order = Order.find_by_id(data['id'])
         if order.state != ORDER_PENDING:
             return "Order is not pending", 203
         order.state = ORDER_PAID
         db.session.add(order)
         db.session.commit()
         return order.serializable(), 200
     except IntegrityError as e:
         db.session.rollback()
         return "Integrity error: " + str(e), 400