def test_add_shopcart(self): """ Create a ShopCart -- Add it to the database """ shopcarts = ShopCart.all() self.assertEqual(shopcarts, []) shopcart = self._create_shopcart() shopcart.create() # Assert that it was assigned an id and shows up in the database self.assertEqual(shopcart.id, 1) shopcarts = ShopCart.all() self.assertEqual(len(shopcarts), 1)
def delete_all_shopcarts(): """ Returns IDs of the ShopCarts """ app.logger.info("Request for ShopCart list") shopcarts = [] id = request.args.get("id") if id: shopcarts = ShopCart.find(id) else: shopcarts = ShopCart.all() results = [shopcart.delete() for shopcart in shopcarts] return make_response("", status.HTTP_204_NO_CONTENT)
def list_shopcarts(): """ Returns IDs of the ShopCarts """ app.logger.info("Request for ShopCart list") shopcarts = [] id = request.args.get("id") if id: shopcarts = ShopCart.find(id) else: shopcarts = ShopCart.all() results = [shopcart.serialize() for shopcart in shopcarts] return make_response(jsonify(results), status.HTTP_200_OK)
def test_delete_shopcart_item(self): """ Delete a ShopCart item """ shopcarts = ShopCart.all() self.assertEqual(shopcarts, []) item = self._create_item() shopcart = self._create_shopcart(items=[item]) shopcart.create() # Assert that it was assigned an id and shows up in the database self.assertEqual(shopcart.id, 1) shopcarts = ShopCart.all() self.assertEqual(len(shopcarts), 1) # Fetch it back shopcart = ShopCart.find(shopcart.id) item = shopcart.items[0] item.delete() shopcart.save() # Fetch it back again shopcart = ShopCart.find(shopcart.id) self.assertEqual(len(shopcart.items), 0)