def test_find_by_name(self): """ Find a Product by Name """ 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_name("shampos") self.assertEqual(products[0].category, "Health Care") self.assertEqual(products[0].name, "shampos") print(products[0].price) print(getcontext()) self.assertAlmostEqual(products[0].price, Decimal(12.34))
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