Beispiel #1
0
    def test_find_by_recommend_product_id(self):
        """ Test find by recommend_product_id """
        Recommendation(product_id=PS3,
                       recommended_product_id=CONTROLLER,
                       recommendation_type="accessory").save()
        Recommendation(product_id=PS4,
                       recommended_product_id=CONTROLLER,
                       recommendation_type="accessory").save()
        Recommendation(product_id=PS4,
                       recommended_product_id=MONSTER_HUNTER,
                       recommendation_type="cross-sell").save()

        recommendations = Recommendation.find_by_recommend_product_id(
            CONTROLLER)
        self.assertEqual(len(recommendations), 2)
        self.assertEqual(recommendations[0].recommended_product_id, CONTROLLER)
        self.assertEqual(recommendations[1].recommended_product_id, CONTROLLER)
Beispiel #2
0
def query_recommendations_by_recommended_product_id(recommended_product_id):
    """ Query a recommendation from the database that have the same recommended product id """
    recommendations = Recommendation.find_by_recommend_product_id(
        int(recommended_product_id))
    if len(recommendations) > 0:
        message = [
            recommendation.serialize() for recommendation in recommendations
        ]
        return_code = HTTP_200_OK
    else:
        message = {
            'error':
            'Recommendation with product_id: \
                    %s was not found' % str(recommended_product_id)
        }
        return_code = HTTP_404_NOT_FOUND

    return message, return_code