Example #1
0
def list_promotions():
    """ Returns all of the Promotions """
    app.logger.info("Request for promotions list")
    promotions = []
    name = request.args.get("name")
    if name:
        promotions = Promotion.find_by_name(name)
    else:
        promotions = Promotion.all()

    results = [promotion.serialize() for promotion in promotions]
    return make_response(jsonify(results), status.HTTP_200_OK)
Example #2
0
 def test_find_by_name(self):
     """ Find a Promotion by Name """
     Promotion(name="discount").create()
     Promotion(name="buy one get one").create()
     promotions = Promotion.find_by_name("buy one get one")
     self.assertEqual(promotions[0].name, "buy one get one")