def test_delete_a_recommendation(self): recommendation = Recommendation(1, "productId", "recommended", "categoryId") recommendation.save() self.assertEqual(len(Recommendation.all()), 1) recommendation.delete() self.assertEqual(len(Recommendation.all()), 0)
def test_reset(self): """ Reset """ recommendation = Recommendation(customer_id=2, product_id=3, recommend_product_id=4, recommend_type="upsell") recommendation.save() self.assertEqual(len(Recommendation.all()), 1) # delete the recommendation and make sure it isn't in the database recommendation.remove_all() self.assertEqual(len(Recommendation.all()), 0)
def test_add_a_recommendation(self): """ Create a recommendation and add it to the database """ recommendations = Recommendation.all() self.assertEqual(recommendations, []) recommendation = Recommendation(customer_id=2, product_id=3, recommend_product_id=4, recommend_type="upsell") self.assertTrue(recommendation is not None) self.assertEqual(recommendation.id, None) recommendation.save() # Asert that it was assigned an id and shows up in the database self.assertEqual(recommendation.id, 1) recommendations = Recommendation.all() self.assertEqual(len(recommendations), 1)
def test_update_a_recommendation(self): recommendation = Recommendation(1, "productId", "recommended", "categoryId") recommendation.save() recommendation.categoryId = "newcategoryId" recommendation.save() recommendations = Recommendation.all() self.assertEqual(recommendations[0].categoryId, "newcategoryId")
def test_update_a_recommendation(self): """ Update a Recommendation """ recommendation = Recommendation(customer_id=2, product_id=3, recommend_product_id=4, recommend_type="upsell") recommendation.save() self.assertEqual(recommendation.id, 1) # Change it an save it recommendation.recommend_product_id = 5 recommendation.save() self.assertEqual(recommendation.id, 1) # Fetch it back and make sure the id hasn't changed # but the data did change recommendations = Recommendation.all() self.assertEqual(len(recommendations), 1) self.assertEqual(recommendations[0].recommend_product_id, 5)
def get(self): """ Returns all of the Recommendations """ #app.logger.info('Listing recommendations') recommendations = [] categoryId = request.args.get('categoryId') productId = request.args.get('productId') suggestionId = request.args.get('suggestionId') if categoryId: recommendations = Recommendation.find_by_categoryId(categoryId) elif productId: recommendations = Recommendation.find_by_productId(productId) elif suggestionId: recommendations = Recommendation.find_by_suggestionId(suggestionId) else: recommendations = Recommendation.all() #app.logger.info('[%s] Recommendations returned', len(recommendations)) results = [ recommendation.serialize() for recommendation in recommendations ] return results, status.HTTP_200_OK