Esempio n. 1
0
    def get(self):
        """ Returns all of the ShopcartItems """
        logger.info('Request to list ShopcartItems...')

        args = shopcart_item_args.parse_args()

        if args['sku']:
            logger.info('Find by sku')
            shopcart_items = ShopcartItem.find_by_sku(args['sku'])
        elif args['name']:
            logger.info('Find by name')
            shopcart_items = ShopcartItem.find_by_name(args['name'])
        elif args['price']:
            logger.info('Find by price')
            shopcart_items = ShopcartItem.find_by_price(args['price'])
        elif args['amount']:
            logger.info('Find by amount')
            shopcart_items = ShopcartItem.find_by_amount(args['amount'])
        else:
            logger.info('Find all')
            shopcart_items = ShopcartItem.all()

        results = [shopcart_item.serialize() for shopcart_item in shopcart_items]
        logger.info('[%s] Shopcart Items returned', len(results))
        return results, status.HTTP_200_OK
Esempio n. 2
0
 def test_find_by_sku(self):
     """ Find Shopcart Items by sku """
     shopcart_1 = Shopcart().deserialize({"user_id": 12345})
     shopcart_1.create()
     shopcart_2 = Shopcart().deserialize({"user_id": 12345})
     shopcart_2.create()
     ShopcartItem(sid=shopcart_1.id, sku=101, name="printer", price=101.29, amount=1).create()
     ShopcartItem(sid=shopcart_2.id, sku=101, name="printer", price=101.29, amount=10).create()
     ShopcartItem(sid=shopcart_1.id, sku=201, name="printer", price=101.29, amount=1).create()
     shopcart_items = ShopcartItem.find_by_sku(101)
     self.assertEqual(len(shopcart_items), 2)
     self.assertEqual(shopcart_items[0].sku, 101)