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
def test_find_by_amount(self): """ Find Shopcart Items by amount """ shopcart = Shopcart().deserialize({"user_id": 12345}) shopcart.create() ShopcartItem(sid=shopcart.id, sku=101, name="printer", price=101.29, amount=1).create() ShopcartItem(sid=shopcart.id, sku=201, name="printer", price=101.29, amount=10).create() shopcart_items = ShopcartItem.find_by_amount(10) self.assertEqual(len(shopcart_items), 1) self.assertEqual(shopcart_items[0].amount, 10)