def test_update_a_product_rating(self):
     """ Update a Product Rating"""
     product = Product(1, "Couch", "White couch", "Furniture", 200, "Boxed",
                       50, " ", 8)
     product.save()
     self.assertEqual(product.id, 1)
     # Change it and save it
     product.rating = 10
     product.update()
     self.assertEqual(product.id, 1)
     # Fetch it back and make sure the id hasn't changed
     # but the data did change
     products = Product.all()
     self.assertEqual(len(products), 1)
     self.assertEqual(products[0].rating, 10)
 def test_sort_by_date(self):
     """ Sort Products by Date """
     Product(1, "Couch", "White couch", "Furniture", 200, "Boxed", 50, " ",
             8).save()
     table = Product(2, "Table", "Oak table", "Home", 150, "Boxed", 100,
                     " ", 7)
     table.save()
     table.price = 200
     table.update()
     product = list(Product.sort_by_date())[0]
     self.assertIsNot(product, None)
     self.assertEqual(product.id, table.id)
     self.assertEqual(product.name, "Table")
     self.assertEqual(product.category, "Home")
     self.assertEqual(product.description, "Oak table")
     self.assertEqual(product.price, 200)
     self.assertEqual(product.condition, "Boxed")
     self.assertEqual(product.inventory, 100)
     self.assertEqual(product.rating, 7)