Beispiel #1
0
    def test_find_by_recommend_type(self):
        """ Test find by recommend_type """
        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_type("accessory")
        self.assertEqual(len(recommendations), 2)
        self.assertEqual(recommendations[0].recommendation_type, "accessory")
        self.assertEqual(recommendations[1].recommendation_type, "accessory")
Beispiel #2
0
def query_recommendations_by_recommendation_type(recommendation_type):
    """ Query a recommendation from the database that have the same recommendation type """
    recommendations = Recommendation.find_by_recommend_type(
        str(recommendation_type))
    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(recommendation_type)
        }
        return_code = HTTP_404_NOT_FOUND

    return message, return_code