def test_find_by_category(self): """ Find a Promotion by Category """ Promotion("A1234", "BOGO", True, "20").save() Promotion("B4321", "dollar", False, "5").save() promotions = Promotion.find_by_category("dollar") self.assertNotEqual(len(promotions), 0) self.assertEqual(promotions[0].category, "dollar") self.assertEqual(promotions[0].productid, "B4321")
def test_find_by_category(self): """ Find Promotion goods by Category """ Promotion(promo_name="random", goods_name="random_good", category="random_category", price=20, discount=20, available=True).save() Promotion(promo_name="random2", goods_name="random2_good", category="random2_category", price=2, discount=2, available=False).save() promotions = Promotion.find_by_category("random2_category") self.assertEqual(promotions[0].category, "random2_category") self.assertEqual(promotions[0].promo_name, "random2") self.assertEqual(promotions[0].goods_name, "random2_good") self.assertEqual(promotions[0].price, 2) self.assertEqual(promotions[0].discount, 2) self.assertEqual(promotions[0].available, False)
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)