def get(self): """List all the product by their updated date""" app.logger.info("List products by updated date") sorted_products = Product.sort_by_date() results = [product.serialize() for product in sorted_products] # return make_response(jsonify(results), status.HTTP_200_OK) return results, status.HTTP_200_OK
def test_get_product_list_by_date(self): """ Get a list of Products by date order""" products = Product.sort_by_date() results = [ product.serialize() for product in products] resp = self.app.get('/products/latest') self.assertEqual(resp.status_code, status.HTTP_200_OK) data = json.loads(resp.data) # print(data) # print(products) # print(results) self.assertEqual(data, results)
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)