def get(self):
        """ Returns all of the Recommendations """
        #app.logger.info('Listing recommendations')
        recommendations = []
        categoryId = request.args.get('categoryId')
        productId = request.args.get('productId')
        suggestionId = request.args.get('suggestionId')
        if categoryId:
            recommendations = Recommendation.find_by_categoryId(categoryId)
        elif productId:
            recommendations = Recommendation.find_by_productId(productId)
        elif suggestionId:
            recommendations = Recommendation.find_by_suggestionId(suggestionId)
        else:
            recommendations = Recommendation.all()

        #app.logger.info('[%s] Recommendations returned', len(recommendations))
        results = [
            recommendation.serialize() for recommendation in recommendations
        ]
        return results, status.HTTP_200_OK
Esempio n. 2
0
 def test_find_by_productId(self):
     Recommendation(1, "productId1", "suggestionId1", "categoryId1").save()
     Recommendation(2, "productId2", "suggestionId2", "categoryId2").save()
     recommendations = Recommendation.find_by_productId("productId1")
     self.assertEqual(len(recommendations), 1)
     self.assertEqual(recommendations[0].productId, "productId1")