当前位置: 首页>>代码示例>>Python>>正文


Python Cart.remove_item方法代码示例

本文整理汇总了Python中cart.Cart.remove_item方法的典型用法代码示例。如果您正苦于以下问题:Python Cart.remove_item方法的具体用法?Python Cart.remove_item怎么用?Python Cart.remove_item使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cart.Cart的用法示例。


在下文中一共展示了Cart.remove_item方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestRemoveFromCart

# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import remove_item [as 别名]
class TestRemoveFromCart(unittest.TestCase):
    
    def setUp(self):
        self.products = []
        self.cart = Cart()
        for i in range(1,10):
            product = Product(product_id=i, key_name="test_product_"+str(i),price=round(random.uniform(1,10),2),tax_percent=18.00)
            product.put()
            product.add_stock("test_product_"+str(i),10)
            self.products.append("test_product_"+str(i))
            p = Product.get_by_key_name("test_product_"+str(i))
            self.cart.add_item(CartItem(p), random.randint(1,10))
        
        random.shuffle(self.products)
        
    
    def test_totals_with_delivery(self):
        print '----------------- TEST RfB TOTALS --------------------'
        
        self.cart.delivery = {'price':2.5,'tax':15.0,'name':'testDelivery'}
        self.cart.recalc()
        delivery_gross = self.cart.delivery['price'] + self.cart.delivery['price'] * self.cart.delivery['tax']/100
        delivery_tax = self.cart.delivery['price'] * self.cart.delivery['tax'] / 100
        delivery_net = self.cart.delivery['price']
        print 'DELIVERY ','price:', self.cart.delivery['price'], 'plus tax:', delivery_gross, 'tax percent:', self.cart.delivery['tax'],'price tax:', delivery_tax
        
        sub_total_tax_items = self.cart.sub_total_tax_items #TAX Items
        sub_total_price = self.cart.sub_total_price #GROSS Items
        total = self.cart.total #GROSS Items + GROSS Delivery
        total_without_tax = self.cart.total_without_tax  #NET Items + NET Delivery
        total_tax =  self.cart.total_tax #TAX items + TAX Delivery
        
        for i in range(3):
            qty = random.randint(1,10)
            qty=1
            p = Product.get_by_key_name(self.products[i])
            print self.products[i],'price:', p.price, 'plus tax:', p.price + p.price * p.tax_percent / 100,'tax percent: ',p.tax_percent, 'price tax:',p.price * p.tax_percent / 100, 'qty:',qty
            sub_total_tax_items -= (p.price * p.tax_percent / 100)*qty
            sub_total_price -=  (p.price + p.price * p.tax_percent / 100)*qty
            total -= (p.price + p.price * p.tax_percent / 100)*qty
            total_without_tax -=  (p.price)*qty
            total_tax -= (p.price * p.tax_percent / 100)*qty
            
            self.cart.remove_item(CartItem(p),qty)
        
        print 'sub_total_tax_items: ', sub_total_tax_items, ' CART sub_total_tax_items: ',self.cart.sub_total_tax_items
        self.assertAlmostEqual(sub_total_tax_items, self.cart.sub_total_tax_items,7, 'Error calculating sub_total_tax_items')
        
        print 'sub_total_price: ', sub_total_price, ' CART sub_total_price: ',self.cart.sub_total_price
        self.assertEqual(round(sub_total_price,2), round(self.cart.sub_total_price,2), 'Error calculating sub_total_price')
        
        print 'total: ', total, ' CART total: ',self.cart.total
        self.assertEqual(round(total,2), round(self.cart.total,2), 'Error calculating total')
        
        print 'total_without_tax: ', total_without_tax, ' CART total_without_tax: ',self.cart.total_without_tax
        self.assertEqual(round(total_without_tax,2), round(self.cart.total_without_tax,2), 'Error calculating total_without_tax')
        
        print 'total_tax: ', total_tax, ' CART total_tax: ',self.cart.total_tax
        self.assertEqual(round(total_tax,2), round(self.cart.total_tax,2), 'Error calculating total_tax')
        print '----------------- END TEST -----------------------' 
开发者ID:itaogit,项目名称:shopapp,代码行数:62,代码来源:tests-cart.py

示例2: CartTest

# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import remove_item [as 别名]
class CartTest(unittest.TestCase):
    
    def setUp(self):
        self.cart = Cart()
        self.inv = Inventory()

    def tearDown(self):
        self.inv.close()

    def test_add_items_to_basket(self):
        # Test adding item, make sure it's in cart and inventory updates to reflect that
        old_qty= self.inv.view_qty('item050')
        self.cart.add_item('item050', 10)
        self.assertEqual(self.cart.basket('item050'), 10)
        self.assertEqual(self.inv.view_qty('item050'), old_qty-10)
        self.inv.update_qty('item050', 500)
        # Test adding more to cart than inventory contains
        self.cart._basket['item050'] = 0 # Temporary kluge 
        self.cart.add_item('item050', 600)
        self.assertEqual(self.cart.basket('item050'), 500)
        self.assertEqual(self.inv.view_qty('item050'), 0)
        self.inv.update_qty('item050', 500)

    def test_remove_items_from_basket(self):
        self.cart.add_item('item050', 10)
        self.cart.remove_item('item050',5)
        self.assertEqual(self.cart.basket('item050'), 5)
        self.assertEqual(self.inv.view_qty('item050'), 495)

    def test_edit_items(self):
        # Change to a quantity greater than you already have
        self.cart.edit_item('item050', 50)
        self.cart.edit_item('item050', 70)
        self.assertEqual(self.cart.basket('item050'), 70)
        self.assertEqual(self.inv.view_qty('item050'), 430)
        self.cart.remove_item('item050', 70)
        # Add more than are in inventory
        self.cart.edit_item('item050', 1000)
        self.assertEqual(self.inv.view_qty('item050'), 0)
        self.assertEqual(self.cart.basket('item050'), 500)
        self.cart.remove_item('item050', 500)
        # Change to a quantity less than what you already have
        self.cart.add_item('item050', 100)
        self.cart.edit_item('item050', 50)
        self.assertEqual(self.inv.view_qty('item050'), 450)
        self.assertEqual(self.cart.basket('item050'), 50)
        self.cart.remove_item('item050', 50)
        
    def test_items_total(self):
        self.cart.add_item('item100', 100)
        cost = 100 * self.inv.view_price('item100')
        self.assertEqual(self.cart.items_total(), cost)
        self.cart.remove_item('item100', 100)

    def test_list_items(self):
        self.cart.add_item('item100', 100)
        # Test listing sorted by item name
        for _tuple in self.cart.list_items('item'):
            self.assertEqual(_tuple, ('item100', 100, self.inv.view_price('item100')))
        # Test listing sorted by qty
        for _tuple in self.cart.list_items('price'):
            self.assertEqual(_tuple, ('item100', 100, self.inv.view_price('item100')))
        # Test listing sorted by price
            self.assertEqual(_tuple, ('item100', 100, self.inv.view_price('item100')))
        self.cart.remove_item('item100', 100)
开发者ID:timahutchinson,项目名称:curly-quack,代码行数:67,代码来源:unit_test.py


注:本文中的cart.Cart.remove_item方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。