예제 #1
0
    def test_finding_recommendations_by_product_id(self):
        """ List all recommendations for a particular product id """

        data_one = {
            "product_id": 23,
            "rec_type_id": 1,
            "rec_product_id": 45,
            "weight": .5
        }
        rec = Recommendation()
        rec.deserialize(data_one)
        rec.save()

        data_two = {
            "product_id": 87,
            "rec_type_id": 2,
            "rec_product_id": 51,
            "weight": .5
        }
        rec = Recommendation()
        rec.deserialize(data_two)
        rec.save()

        # Assuming the client will provide a product id and category as a String
        rec = Recommendation.find_by_product_id(87)[0]

        self.assertIsNot(rec, None)
        self.assertEqual(rec.product_id, 87)
        self.assertEqual(rec.rec_type_id, 2)
        self.assertEqual(rec.rec_product_id, 51)
        self.assertEqual(rec.weight, .5)
예제 #2
0
    def test_find_recommendation(self):
        """ Find a Recommendation by product_id """
        Recommendation(product_id=PS3,
                       recommended_product_id=CONTROLLER,
                       recommendation_type="accessory").save()
        ps4 = Recommendation(product_id=PS4,
                             recommended_product_id=CONTROLLER,
                             recommendation_type="accessory")
        ps4.save()

        recommendation = Recommendation.find_by_product_id(ps4.product_id)
        self.assertIsNot(len(recommendation), 0)
        self.assertEqual(recommendation[0].id, ps4.id)
        self.assertEqual(recommendation[0].product_id, PS4)
        self.assertEqual(recommendation[0].recommended_product_id,
                         ps4.recommended_product_id)
        self.assertEqual(recommendation[0].recommendation_type,
                         ps4.recommendation_type)
        self.assertEqual(recommendation[0].likes, ps4.likes)
예제 #3
0
def query_recommendations_by_product_id(product_id):
    """
    Query a recommendation from the database that have the same product_id
    """
    recommendations = Recommendation.find_by_product_id(int(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(product_id)
        }
        return_code = HTTP_404_NOT_FOUND

    return message, return_code