本文整理汇总了Python中cart.Cart.edit_item方法的典型用法代码示例。如果您正苦于以下问题:Python Cart.edit_item方法的具体用法?Python Cart.edit_item怎么用?Python Cart.edit_item使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cart.Cart
的用法示例。
在下文中一共展示了Cart.edit_item方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CartTest
# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import edit_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)