def test_delete_a_shopcartitem(self): """ Delete a Cart Item """ item = ShoppingCartItems(productID=1234, price=12.99, quantity=1, cartId=5) item.add() self.assertEqual(len(ShoppingCartItems.all()), 1) # delete the cart item and make sure it isn't in the database item.delete() self.assertEqual(len(ShoppingCartItems.all()), 0)
def test_add_a_shopcartitem(self): """ Create an item and add it to the database """ items = ShoppingCartItems.all() self.assertEqual(items, []) item = ShoppingCartItems(productID=1234, price=12.99, quantity=1, cartId=5) self.assertTrue(item != None) self.assertEqual(item.id, None) item.add() # Asert that it was assigned an id and shows up in the database self.assertEqual(item.id, 1) items = ShoppingCartItems.all() self.assertEqual(len(items), 1)
def test_update_a_shopcartitem(self): """ Update a ShopCart Item""" item = ShoppingCartItems(productID=1234, price=12.99, quantity=1, cartId=5) item.add() self.assertEqual(item.id, 1) # Change it and save it item.productID = 4321 item.add() self.assertEqual(item.id, 1) # Fetch it back and make sure the id hasn't changed # but the data did change items = ShoppingCartItems.all() self.assertEqual(len(items), 1) self.assertEqual(items[0].productID, 4321)
def list_items(): """ Returns all of the Cart items """ results = [] app.logger.info('Getting all items of all cart') results = ShoppingCartItems.all() return jsonify([item.serialize() for item in results]), status.HTTP_200_OK