本文整理汇总了Python中shop.models.cartmodel.Cart.get_updated_cart_items方法的典型用法代码示例。如果您正苦于以下问题:Python Cart.get_updated_cart_items方法的具体用法?Python Cart.get_updated_cart_items怎么用?Python Cart.get_updated_cart_items使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shop.models.cartmodel.Cart
的用法示例。
在下文中一共展示了Cart.get_updated_cart_items方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CartTestCase
# 需要导入模块: from shop.models.cartmodel import Cart [as 别名]
# 或者: from shop.models.cartmodel.Cart import get_updated_cart_items [as 别名]
#.........这里部分代码省略.........
# 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_add_same_object_twice(self):
with SettingsOverride(SHOP_CART_MODIFIERS=[]):
self.assertEqual(self.cart.total_quantity, 0)
self.cart.add_product(self.product)
self.cart.add_product(self.product)
self.cart.update()
self.cart.save()
self.assertEqual(len(self.cart.items.all()), 1)
self.assertEqual(self.cart.items.all()[0].quantity, 2)
self.assertEqual(self.cart.total_quantity, 2)
def test_add_same_object_twice_no_merge(self):
with SettingsOverride(SHOP_CART_MODIFIERS=[]):
self.assertEqual(self.cart.total_quantity, 0)
self.cart.add_product(self.product, merge=False)
self.cart.add_product(self.product, merge=False)
self.cart.update()
self.cart.save()
self.assertEqual(len(self.cart.items.all()), 2)
self.assertEqual(self.cart.items.all()[0].quantity, 1)
self.assertEqual(self.cart.items.all()[1].quantity, 1)
def test_add_product_updates_last_updated(self):
with SettingsOverride(SHOP_CART_MODIFIERS=[]):
initial = self.cart.last_updated
self.cart.add_product(self.product)
self.assertNotEqual(initial, self.cart.last_updated)
def test_cart_item_should_use_specific_type_to_get_price(self):
if SKIP_BASEPRODUCT_TEST:
return
base_product = BaseProduct.objects.create(
unit_price=self.PRODUCT_PRICE)
variation = base_product.productvariation_set.create(
name="Variation 1")
with SettingsOverride(SHOP_CART_MODIFIERS=[]):
self.cart.add_product(variation)
self.cart.update()
self.cart.save()
self.assertEqual(self.cart.subtotal_price, self.PRODUCT_PRICE)
def test_update_quantity_deletes(self):
with SettingsOverride(SHOP_CART_MODIFIERS=[]):
self.assertEqual(self.cart.total_quantity, 0)
self.cart.add_product(self.product)
self.cart.add_product(self.product)
self.cart.update()
self.cart.save()
self.assertEqual(len(self.cart.items.all()), 1)
self.cart.update_quantity(self.cart.items.all()[0].pk, 0)
self.assertEqual(len(self.cart.items.all()), 0)
def test_custom_queryset_is_used_when_passed_to_method(self):
with SettingsOverride(SHOP_CART_MODIFIERS=[]):
# first we add any product
self.cart.add_product(self.product)
# now we try to select a CartItem that does not exist yet. This
# could be an item with a yet unused combination of variations.
qs = CartItem.objects.filter(cart=self.cart, product=self.product,
quantity=42)
# although we add the same product and have merge=True, there
# should be a new CartItem being created now.
self.cart.add_product(self.product, queryset=qs)
self.assertEqual(len(self.cart.items.all()), 2)
def test_get_updated_cart_items(self):
self.cart.add_product(self.product)
self.cart.update()
cached_cart_items = self.cart.get_updated_cart_items()
cart_items = CartItem.objects.filter(cart=self.cart)
for item in cart_items:
item.update({})
self.assertEqual(len(cached_cart_items), len(cart_items))
self.assertEqual(cached_cart_items[0].line_total,
cart_items[0].line_total)
def test_get_updated_cart_items_without_updating_cart(self):
with self.assertRaises(AssertionError):
self.cart.get_updated_cart_items()