Exemplo n.º 1
0
 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)
Exemplo n.º 2
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)
Exemplo n.º 3
0
def create_items(cart_id):
    app.logger.info('Create Item requested')
    cart = ShoppingCart.find(cart_id)
    if not cart:
        raise NotFound('No Cart with id: {} exist'.format(cart_id))
    item = ShoppingCartItems()
    item.deserialize(request.get_json())
    item.cartId = cart_id
    item.add()
    app.logger.info('Created Item with id: {}'.format(item.id))
    return make_response(
        jsonify(item.serialize()), status.HTTP_201_CREATED, {
            'Location':
            url_for(
                'get_item', cart_id=cart_id, item_id=item.id, _external=True)
        })
Exemplo n.º 4
0
 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)