def test_create_cart(self, api):
     root = api.cart_create({
         '0201896834' : 1, # The Art of Computer Programming Vol. 1
         '0201896842' : 1, # The Art of Computer Programming Vol. 2
    })
     cart = Cart.from_xml(root.Cart)
     assert len(cart.items) == 2
     assert cart['0201896834'].quantity == 1
     assert cart['0201896842'].quantity == 1
    def test_modifying_does_not_work_with_asin(self, api, cart):
        root = api.cart_modify(cart.cart_id, cart.hmac, {
            # The Art of Computer Programming Vol. 3
            '0201896842': 0, 
        })
        from lxml import etree
        print etree.tostring(root.Cart, pretty_print=True)

        cart = Cart.from_xml(root.Cart)
        assert len(cart) == 3
        assert len(cart.items) == 2
    def test_adding_item(self, api, cart):
        root = api.cart_add(cart.cart_id, cart.hmac, {
            '0201896850' : 3, # The Art of Computer Programming Vol. 3
        })
        from lxml import etree
        print etree.tostring(root.Cart, pretty_print=True)

        cart = Cart.from_xml(root.Cart)
        assert len(cart) == 6
        assert len(cart.items) == 3

        item = cart['0201896850']
        assert item.quantity == 3
        assert item.asin == '0201896850'
    def test_modifying_item(self, api, cart):
        root = api.cart_modify(cart.cart_id, cart.hmac, {
            # The Art of Computer Programming Vol. 2
            cart.get_itemid_for_asin('0201896842'): 0, 
        })
        from lxml import etree
        print etree.tostring(root.Cart, pretty_print=True)

        cart = Cart.from_xml(root.Cart)
        assert len(cart) == 1
        assert len(cart.items) == 1

        # 0201896842 is gone!
        pytest.raises(IndexError, lambda x: cart[x], '0201896842')

        # 0201896834 is still here!
        item = cart['0201896834']
        assert item.quantity == 1
        assert item.asin == '0201896834'
 def test_clearing_cart(self, api, cart):
     root = api.cart_clear(cart.cart_id, cart.hmac)
     cart = Cart.from_xml(root.Cart)
     assert len(cart.items) == 0
 def test_getting_cart(self, api, cart):
     root = api.cart_get(cart.cart_id, cart.hmac)
     cart = Cart.from_xml(root.Cart)
     assert len(cart) == 3
     assert len(cart.items) == 2
 def create_cart():
     root = api.cart_create(items)
     cart = Cart.from_xml(root.Cart)
     print 'Cart created:', cart
     return cart