Exemple #1
0
 def test_find_a_recommendation(self):
     saved_recommendation = Recommendation(1, "productId", "recommended",
                                           "categoryId")
     saved_recommendation.save()
     recommendation = Recommendation.find(saved_recommendation.id)
     self.assertEqual(recommendation.productId, "productId")
     self.assertIsNot(recommendation, None)
     self.assertEqual(recommendation.id, saved_recommendation.id)
     self.assertEqual(recommendation.productId, "productId")
Exemple #2
0
 def delete(self, recommendation_id):
     """
     Delete a Recommendation
     This endpoint will delete a Recommendation based the id specified in the path
     """
     #app.logger.info('Request to Delete a recommendation with id [%s]', recommendation_id)
     recommendation = Recommendation.find(recommendation_id)
     if recommendation:
         recommendation.delete()
     return '', status.HTTP_204_NO_CONTENT
Exemple #3
0
 def test_find_recommendation(self):
     """ Find a Recommendation by ID """
     Recommendation(customer_id=2, product_id=3, recommend_product_id=4,\
     recommend_type="upsell").save()
     recc = Recommendation(customer_id=5, product_id=6,\
      recommend_product_id=7, recommend_type="downsell")
     recc.save()
     recommendation = Recommendation.find(recc.id)
     self.assertIsNot(recommendation, None)
     self.assertEqual(recommendation.id, recc.id)
     self.assertEqual(recommendation.product_id, 6)
     self.assertEqual(recommendation.customer_id, 5)
 def get(self, rec_id):
     """
     Retrieve a single Recommendation
     This endpoint will return a Recommendation based on it's id
     """
     app.logger.info("Request to Retrieve a recommendation with id [%s]",
                     rec_id)
     recommendation = Recommendation.find(rec_id)
     if not recommendation:
         api.abort(
             status.HTTP_404_NOT_FOUND,
             "Recommendation with id '{}' was not found.".format(rec_id))
     return recommendation.serialize(), status.HTTP_200_OK
 def put(self, rec_id):
     """
     Update a Recommendation
     This endpoint will update a Recommendation based the body that is posted
     """
     app.logger.info('Request to update recommendation with id: %s', rec_id)
     check_content_type('application/json')
     recommendation = Recommendation.find(rec_id)
     if not recommendation:
         api.abort(
             status.HTTP_404_NOT_FOUND,
             "Recommendation with id '{}' was not found.".format(rec_id))
     recommendation.deserialize(request.get_json())
     recommendation.id = rec_id
     recommendation.save()
     return recommendation.serialize(), status.HTTP_200_OK
 def put(self, rec_id):
     """
     Increment A Recommendation's Success Field
     This endpoint will increment the success counter based on the recommendtion succeed
     """
     app.logger.info(
         'Increment success field for recommendation with id: %s', rec_id)
     check_content_type('application/json')
     recommendation = Recommendation.find(rec_id)
     if not recommendation:
         api.abort(
             status.HTTP_404_NOT_FOUND,
             "Recommendation with id '{}' was not found.".format(rec_id))
     count = recommendation.rec_success
     recommendation.rec_success = count + 1
     recommendation.id = rec_id
     recommendation.save()
     return recommendation.serialize(), status.HTTP_200_OK
    def put(self, categoryId):
        """
        Update a recommendation category
        This end point will update a recommendation category for all RELEVANT RECOMMENDATIONS
        based on the data in the body
        """
        results = Recommendation.find_by_categoryId(categoryId)
        if (len(results) == 0):
            # message = {'error' : 'Recommendation with categoryId: %s was not found' % str(categoryId)}
            return_code = status.HTTP_404_NOT_FOUND
            return '', return_code

        data = request.get_json()
        i = 0
        sizeOfResults = len(results)
        while i < sizeOfResults:
            recommendation = Recommendation.find(results[i].id)
            recommendation.categoryId = data['categoryId']
            recommendation.update()
            i += 1
        # message = {'success' : 'RECOMMENDATIONS category updated'}
        return '', status.HTTP_200_OK
Exemple #8
0
    def put(self, recommendation_id):
        """
        Update a Recommendation
        This endpoint will update a Recommendation based the body that is posted
        """
        #app.logger.info('Request to Update a recommendation with id [%s]', recommendation_id)
        #check_content_type('application/json')
        recommendation = Recommendation.find(recommendation_id)
        if not recommendation:
            abort(
                status.HTTP_404_NOT_FOUND,
                "Recommendation with id '{}' was not found.".format(
                    recommendation_id))

        payload = request.get_json()
        try:
            recommendation.deserialize(payload)
        except DataValidationError as error:
            raise BadRequest(str(error))

        recommendation.id = recommendation_id
        recommendation.update()
        return recommendation.serialize(), status.HTTP_200_OK