Пример #1
0
 def test_find_by_availability(self):
     """ Find a Promotion by Availability """
     Promotion("A002", "dog", False).save()
     Promotion("kitty", "cat", True).save()
     promotions = Promotion.find_by_availability(True)
     self.assertEqual(len(promotions), 1)
     self.assertEqual(promotions[0].productid, "kitty")
Пример #2
0
    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