def test_find_by_productid(self): """ Find a Promotion by Productid """ Promotion("A1234", "BOGO", True, "20").save() Promotion("B4321", "dollar", False, "5").save() promotions = Promotion.find_by_productid("A1234") self.assertNotEqual(len(promotions), 0) self.assertEqual(promotions[0].category, "BOGO") self.assertEqual(promotions[0].productid, "A1234")
def list_promotions(): """ Returns all of the Promotions """ promotions = [] category = request.args.get('category') productid = request.args.get('productid') discount = request.args.get('discount') if category: app.logger.info('Find by category') promotions = Promotion.find_by_category(category) elif productid: app.logger.info('Find by productid') promotions = Promotion.find_by_productid(productid) elif discount: app.logger.info('Find by discount') promotions = Promotion.find_by_discount(discount) else: app.logger.info('Find all') promotions = Promotion.all() app.logger.info('[%s] Promotions returned', len(promotions)) results = [promotion.serialize() for promotion in promotions] return make_response(jsonify(results), status.HTTP_200_OK)