def test_find_recommendation(self): """ Find a Recommendation by ID """ data_one = { "product_id": 54, "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": 1, "rec_product_id": 51, "weight": .5 } rec = Recommendation() rec.deserialize(data_two) rec.save() rec = Recommendation.find_by_id(2) self.assertIsNot(rec, None) self.assertEqual(rec.product_id, 87) self.assertEqual(rec.rec_type_id, 1) self.assertEqual(rec.rec_product_id, 51) self.assertEqual(rec.weight, .5)
def test_recommendation_not_found_with_data(self): """ Test for a Recommendation that doesn't exist """ data_one = { "product_id": 23, "rec_type_id": 1, "rec_product_id": 45, "weight": .5 } rec = Recommendation() rec.deserialize(data_one) rec = Recommendation.find_by_id(2) self.assertIs(rec, None)
def test_update_a_recommendation(self): """ Update a Recommendation """ data = { "product_id": 23, "rec_type_id": 1, "rec_product_id": 45, "weight": .5 } rec = Recommendation() rec.deserialize(data) rec.save() # self.assertEqual(rec.id, 1) # Change and save it rec.product_id = 54 rec.save() self.assertEqual(rec.product_id, 54) # Fetch it back and make sure the id hasn't changed # but the data did change rec = Recommendation.find_by_id(1) self.assertEqual(rec.product_id, 54)
def test_find_with_no_recommendation_data(self): """ Find a Recommendation with no Recommendations """ rec = Recommendation.find_by_id(1) self.assertIs(rec, None)