def get(self): """ Returns all of the Products """ app.logger.info('Request to list Products...') results = [] category = request.args.get('category') #print (category) name = request.args.get('name') if category: # print("Category is " + category) results = Product.find_by_category(str(category).lower()) elif name: results = Product.find_by_name(str(name).lower()) else: results = Product.all() # for pro in results: # print(pro.id) # app.logger.info('[%s] Products returned', len(results)) # return make_response(jsonify([p.serialize() for p in results]), # HTTP_200_OK) resultsUpd = [prod.serialize() for prod in results] # for prod in resultsUpd: # print(prod['id']) return resultsUpd, status.HTTP_200_OK
def test_find_by_category(self): """ Find Products by Category """ Product(0, 'Asus2500', 'Laptop', '234', 'laptop', 'blue', 4).save() Product(0, 'GE4509', 'Microwave', '34324', 'microwave', 'black', 4).save() products = Product.find_by_category("Laptop") self.assertNotEqual(len(products), 0) self.assertEqual(products[0].category, "Laptop") self.assertEqual(products[0].name, "Asus2500")
def list_product(): """ Retrieves a list of products from the database """ results = [] category = request.args.get('category') name = request.args.get('name') if category: results = Product.find_by_category(category) elif name: results = Product.find_by_name(name) else: results = Product.all() return jsonify([p.serialize() for p in results]), HTTP_200_OK
def get(self): app.logger.info('Request to list Products...') category = request.args.get('category') name = request.args.get('name') if category: results = Product.find_by_category(str(category).lower()) elif name: results = Product.find_by_name(str(name).lower()) else: results = Product.all() resultsUpd = [prod.serialize() for prod in results] return resultsUpd, status.HTTP_200_OK