def get(self): """ Returns all of the Promotions """ app.logger.info('Request to list Promotions...') promotions = [] category = request.args.get('category') productid = request.args.get('productid') available = request.args.get('available') discount = request.args.get('discount') if category: app.logger.info('Filtering by category: %s', category) promotions = Promotion.find_by_category(category) elif productid: app.logger.info('Filtering by productid:%s', productid) promotions = Promotion.find_by_productid(productid) elif available: app.logger.info('Filtering by available: %s', available) is_available = available.lower() in ['yes', 'y', 'true', 't', '1'] promotions = Promotion.find_by_availability(is_available) elif discount: app.logger.info('Filtering by discount:%s', discount) promotions = Promotion.find_by_discount(discount) else: promotions = Promotion.all() app.logger.info('[%s] Promotions returned', len(promotions)) results = [promotion.serialize() for promotion in promotions] return results, status.HTTP_200_OK
def test_find_by_category(self): """ Find a Promotion by Category """ Promotion("A002", "dog").save() Promotion("kitty", "cat").save() promotions = Promotion.find_by_category("cat") self.assertNotEqual(len(promotions), 0) self.assertEqual(promotions[0].category, "cat") self.assertEqual(promotions[0].productid, "kitty")