Ejemplo n.º 1
0
    def get(self, customer_id):
        """ Returns list of all of the shop cart items"""
        if request.args.get('price') == None:
            app.logger.info(
                'Request to list all items in shopcart with customer_id: %s',
                customer_id)
            items = []
            items = Shopcart.find_by_customer_id(customer_id)
            results = [item.serialize() for item in items]
            #if results is None or len(results) == 0:
            #    api.abort(404, "No items for this customer.")
            return results, status.HTTP_200_OK

        else:
            target_price = request.args.get('price')
            print(target_price)
            app.logger.info(
                'Request to query all items in shopcart with customer_id: %s',
                customer_id)
            items = []
            items = Shopcart.query_by_target_price(customer_id, target_price)
            results = [item.serialize() for item in items]
            print(results)
            #if results is None or len(results) == 0:
            #    api.abort(404, "No items for this customer.")
            return results, status.HTTP_200_OK
Ejemplo n.º 2
0
    def test_find_by_customer_id(self):
        """ Find by customer_id """
        shopcart = self._create_shopcart()
        shopcart.create()

        # Fetch it back by name
        same_shopcart = Shopcart.find_by_customer_id(shopcart.customer_id)[0]
        self.assertEqual(same_shopcart.customer_id, shopcart.customer_id)
        self.assertEqual(same_shopcart.id, shopcart.id)
Ejemplo n.º 3
0
 def test_find_by_customer_id_pos(self):
     """ Find a shopcart by customer_id """
     Shopcart(product_id=3, customer_id=10, quantity=2, price=5.0, text="pen", state=1).save()
     Shopcart(product_id=4, customer_id=11, quantity=1, price=150.30, text="book", state=0).save()
     Shopcart(product_id=5, customer_id=11, quantity=2, price=12.91, text="hat", state=1).save()
     shopcart = Shopcart.find_by_customer_id(11)
     self.assertEqual(shopcart.count(), 2)
     self.assertEqual(shopcart[0].product_id, 4)
     self.assertEqual(shopcart[0].customer_id, 11)
     self.assertEqual(shopcart[0].quantity, 1)
     self.assertEqual(float(shopcart[0].price), 150.30)
     self.assertEqual(shopcart[0].text, "book")
     self.assertEqual(shopcart[0].state, 0)
     self.assertEqual(shopcart[1].product_id, 5)
     self.assertEqual(shopcart[1].customer_id, 11)
     self.assertEqual(shopcart[1].quantity, 2)
     self.assertEqual(float(shopcart[1].price), 12.91)
     self.assertEqual(shopcart[1].text, "hat")
     self.assertEqual(shopcart[1].state, 1)
Ejemplo n.º 4
0
 def test_find_by_customer_id_neg(self):
     """ Shouldn't find a shopcart by customer_id """
     Shopcart(product_id=3, customer_id=10, quantity=2, price=5.0, text="pen", state=1).save()
     shopcart = Shopcart.find_by_customer_id(11)
     self.assertEqual(shopcart.count(), 0)