def test_find_by_category(self): """ Find Products by Category """ Product(name="Wagyu Tenderloin Steak", category="food", stock=11, price=20.56, description="The most decadent, succulent cut of beef, ever." ).save() Product(name="shampos", category="Health Care", stock=48, price=12.34).save() products = Product.find_by_category("food") self.assertEqual(products[0].category, "food") self.assertEqual(products[0].name, "Wagyu Tenderloin Steak") self.assertEqual(products[0].stock, 11)
def get(self): """Returns all of the Products""" app.logger.info('Request for product list') products = [] category = request.args.get('category') name = request.args.get('name') price = request.args.get('price') if category: products = Product.find_by_category(category) elif name: products = Product.find_by_name(name) elif price and int(price) > 0 and int( price) < 4: # query price by range if int(price) == 1: products = Product.find_by_price(0, 25) elif int(price) == 2: products = Product.find_by_price(25, 50) else: products = Product.find_by_price(50, 75) else: products = Product.all() results = [product.serialize() for product in products] return results, status.HTTP_200_OK