本文整理汇总了Python中shop.models.cartmodel.Cart.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Cart.delete方法的具体用法?Python Cart.delete怎么用?Python Cart.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shop.models.cartmodel.Cart
的用法示例。
在下文中一共展示了Cart.delete方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CartTestCase
# 需要导入模块: from shop.models.cartmodel import Cart [as 别名]
# 或者: from shop.models.cartmodel.Cart import delete [as 别名]
class CartTestCase(TestCase):
PRODUCT_PRICE = Decimal('100')
TEN_PERCENT = Decimal(10) / Decimal(100)
def setUp(self):
cart_modifiers_pool.USE_CACHE=False
self.user = User.objects.create(username="test", email="[email protected]")
self.product = Product()
self.product.name = "TestPrduct"
self.product.slug = "TestPrduct"
self.product.short_description = "TestPrduct"
self.product.long_description = "TestPrduct"
self.product.active = True
self.product.unit_price = self.PRODUCT_PRICE
self.product.save()
self.cart = Cart()
self.cart.user = self.user
self.cart.save()
def tearDown(self):
self.user.delete()
self.product.delete()
self.cart.delete()
def test_01_empty_cart_costs_0(self):
with SettingsOverride(SHOP_CART_MODIFIERS=[]):
self.cart.update()
self.assertEqual(self.cart.subtotal_price, Decimal('0.0'))
self.assertEqual(self.cart.total_price, Decimal('0.0'))
def test_02_one_object_no_modifiers(self):
with SettingsOverride(SHOP_CART_MODIFIERS=[]):
self.cart.add_product(self.product)
self.cart.save()
self.cart.update()
self.cart.save()
self.assertEqual(self.cart.subtotal_price, self.PRODUCT_PRICE)
self.assertEqual(self.cart.total_price, self.PRODUCT_PRICE)
def test_03_two_objects_no_modifier(self):
with SettingsOverride(SHOP_CART_MODIFIERS=[]):
# We add two objects now :)
self.cart.add_product(self.product,2)
self.cart.update()
self.cart.save()
self.assertEqual(self.cart.subtotal_price, self.PRODUCT_PRICE*2)
self.assertEqual(self.cart.total_price, self.PRODUCT_PRICE*2)
def test_04_one_object_simple_modifier(self):
MODIFIERS = ['shop.cart.modifiers.tax_modifiers.TenPercentTaxModifier']
with SettingsOverride(SHOP_CART_MODIFIERS=MODIFIERS):
self.cart.add_product(self.product)
self.cart.update()
self.cart.save()
self.assertEqual(self.cart.subtotal_price, self.PRODUCT_PRICE)
self.assertEqual(self.cart.total_price, (self.TEN_PERCENT*self.PRODUCT_PRICE)+self.PRODUCT_PRICE)
def test_05_one_object_two_modifiers_no_rebate(self):
MODIFIERS = ['shop.cart.modifiers.tax_modifiers.TenPercentTaxModifier',
'shop.cart.modifiers.rebate_modifiers.BulkRebateModifier']
with SettingsOverride(SHOP_CART_MODIFIERS=MODIFIERS):
self.cart.add_product(self.product)
self.cart.update()
self.cart.save()
self.assertEqual(self.cart.subtotal_price, self.PRODUCT_PRICE)
self.assertEqual(self.cart.total_price, (self.TEN_PERCENT*self.PRODUCT_PRICE)+self.PRODUCT_PRICE)
def test_06_one_object_two_modifiers_with_rebate(self):
MODIFIERS = ['shop.cart.modifiers.tax_modifiers.TenPercentTaxModifier',
'shop.cart.modifiers.rebate_modifiers.BulkRebateModifier']
with SettingsOverride(SHOP_CART_MODIFIERS=MODIFIERS):
# We add 6 objects now :)
self.cart.add_product(self.product,6)
self.cart.update()
self.cart.save()
#subtotal is 600 - 10% = 540
sub_should_be = (6*self.PRODUCT_PRICE) - (self.TEN_PERCENT*(6*self.PRODUCT_PRICE))
total_should_be = sub_should_be + (self.TEN_PERCENT*sub_should_be)
self.assertEqual(self.cart.subtotal_price, sub_should_be)
self.assertEqual(self.cart.total_price, total_should_be)
def test_07_add_same_object_twice(self):
with SettingsOverride(SHOP_CART_MODIFIERS=[]):
self.cart.add_product(self.product)
self.cart.save()
self.cart.update()
self.cart.save()
#.........这里部分代码省略.........