Beispiel #1
0
 def test_find_by_discount(self):
     """ Find a Promotion by Discount """
     Promotion("A1234", "BOGO", True, "20").save()
     Promotion("B4321", "dollar", False, "5").save()
     promotions = Promotion.find_by_discount("20")
     self.assertEqual(len(promotions), 1)
     self.assertEqual(promotions[0].productid, "A1234")
Beispiel #2
0
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)