本文整理汇总了Python中controller_helpers.TestingCartController.for_user方法的典型用法代码示例。如果您正苦于以下问题:Python TestingCartController.for_user方法的具体用法?Python TestingCartController.for_user怎么用?Python TestingCartController.for_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类controller_helpers.TestingCartController
的用法示例。
在下文中一共展示了TestingCartController.for_user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_discount_ceiling_only_counts_items_covered_by_ceiling
# 需要导入模块: from controller_helpers import TestingCartController [as 别名]
# 或者: from controller_helpers.TestingCartController import for_user [as 别名]
def test_discount_ceiling_only_counts_items_covered_by_ceiling(self):
self.make_discount_ceiling("Limit ceiling", limit=1, percentage=50)
voucher = self.new_voucher(code="VOUCHER")
discount = rego.VoucherDiscount.objects.create(
description="VOUCHER RECIPIENT",
voucher=voucher,
)
discount.save()
rego.DiscountForProduct.objects.create(
discount=discount,
product=self.PROD_1,
percentage=100,
quantity=1
).save()
# Buy two of PROD_1, in separate carts:
cart = TestingCartController.for_user(self.USER_1)
# the 100% discount from the voucher should apply to the first item
# and not the ceiling discount.
cart.apply_voucher("VOUCHER")
cart.add_to_cart(self.PROD_1, 1)
self.assertEqual(1, len(cart.cart.discountitem_set.all()))
cart.next_cart()
# The second cart has no voucher attached, so should apply the
# ceiling discount
cart = TestingCartController.for_user(self.USER_1)
cart.add_to_cart(self.PROD_1, 1)
self.assertEqual(1, len(cart.cart.discountitem_set.all()))
示例2: test_discount_applies_across_carts
# 需要导入模块: from controller_helpers import TestingCartController [as 别名]
# 或者: from controller_helpers.TestingCartController import for_user [as 别名]
def test_discount_applies_across_carts(self):
self.add_discount_prod_1_includes_prod_2()
# Enable the discount during the first cart.
cart = TestingCartController.for_user(self.USER_1)
cart.add_to_cart(self.PROD_1, 1)
cart.next_cart()
# Use the discount in the second cart
cart = TestingCartController.for_user(self.USER_1)
cart.add_to_cart(self.PROD_2, 1)
# The discount should be applied.
self.assertEqual(1, len(cart.cart.discountitem_set.all()))
cart.next_cart()
# The discount should respect the total quantity across all
# of the user's carts.
cart = TestingCartController.for_user(self.USER_1)
cart.add_to_cart(self.PROD_2, 2)
# Having one item in the second cart leaves one more item where
# the discount is applicable. The discount should apply, but only for
# quantity=1
discount_items = list(cart.cart.discountitem_set.all())
self.assertEqual(1, discount_items[0].quantity)
示例3: test_per_user_category_and_product_limits
# 需要导入模块: from controller_helpers import TestingCartController [as 别名]
# 或者: from controller_helpers.TestingCartController import for_user [as 别名]
def test_per_user_category_and_product_limits(self):
self.set_limits()
current_cart = TestingCartController.for_user(self.USER_1)
# Hit both the product and category edges:
current_cart.set_quantity(self.PROD_3, 4)
current_cart.set_quantity(self.PROD_4, 6)
with self.assertRaises(ValidationError):
# There's unlimited PROD_3, but limited in the category
current_cart.add_to_cart(self.PROD_3, 1)
current_cart.set_quantity(self.PROD_3, 0)
with self.assertRaises(ValidationError):
# There's only 6 allowed of PROD_4
current_cart.add_to_cart(self.PROD_4, 1)
# The limits should extend across carts...
current_cart.next_cart()
current_cart = TestingCartController.for_user(self.USER_1)
current_cart.set_quantity(self.PROD_3, 4)
with self.assertRaises(ValidationError):
current_cart.set_quantity(self.PROD_3, 5)
with self.assertRaises(ValidationError):
current_cart.set_quantity(self.PROD_4, 1)
示例4: test_cannot_refund_an_applied_credit_note
# 需要导入模块: from controller_helpers import TestingCartController [as 别名]
# 或者: from controller_helpers.TestingCartController import for_user [as 别名]
def test_cannot_refund_an_applied_credit_note(self):
cart = TestingCartController.for_user(self.USER_1)
cart.add_to_cart(self.PROD_1, 1)
invoice = TestingInvoiceController.for_cart(self.reget(cart.cart))
to_pay = invoice.invoice.value
invoice.pay("Reference", to_pay)
self.assertTrue(invoice.invoice.is_paid)
invoice.refund()
self.assertEquals(1, commerce.CreditNote.unclaimed().count())
credit_note = commerce.CreditNote.objects.get(invoice=invoice.invoice)
cn = TestingCreditNoteController(credit_note)
# Create a new cart with invoice
cart = TestingCartController.for_user(self.USER_1)
cart.add_to_cart(self.PROD_1, 1)
invoice_2 = TestingInvoiceController.for_cart(self.reget(cart.cart))
cn.apply_to_invoice(invoice_2.invoice)
self.assertEquals(0, commerce.CreditNote.unclaimed().count())
# Cannot refund this credit note as it is already applied.
with self.assertRaises(ValidationError):
cn.refund()
示例5: test_add_to_cart_product_per_user_limit
# 需要导入模块: from controller_helpers import TestingCartController [as 别名]
# 或者: from controller_helpers.TestingCartController import for_user [as 别名]
def test_add_to_cart_product_per_user_limit(self):
current_cart = TestingCartController.for_user(self.USER_1)
# User should be able to add 1 of PROD_1 to the current cart.
current_cart.add_to_cart(self.PROD_1, 1)
# User should be able to add 1 of PROD_1 to the current cart.
current_cart.add_to_cart(self.PROD_1, 1)
# User should not be able to add 10 of PROD_1 to the current cart now,
# because they have a limit of 10.
with self.assertRaises(ValidationError):
current_cart.add_to_cart(self.PROD_1, 10)
current_cart.next_cart()
current_cart = TestingCartController.for_user(self.USER_1)
# User should not be able to add 10 of PROD_1 to the current cart now,
# even though it's a new cart.
with self.assertRaises(ValidationError):
current_cart.add_to_cart(self.PROD_1, 10)
# Second user should not be affected by first user's limits
second_user_cart = TestingCartController.for_user(self.USER_2)
second_user_cart.add_to_cart(self.PROD_1, 10)
示例6: test_discounts_are_released_by_refunds
# 需要导入模块: from controller_helpers import TestingCartController [as 别名]
# 或者: from controller_helpers.TestingCartController import for_user [as 别名]
def test_discounts_are_released_by_refunds(self):
self.add_discount_prod_1_includes_prod_2(quantity=2)
cart = TestingCartController.for_user(self.USER_1)
cart.add_to_cart(self.PROD_1, 1) # Enable the discount
discounts = discount.available_discounts(
self.USER_1,
[],
[self.PROD_2],
)
self.assertEqual(1, len(discounts))
cart.cart.active = False # Keep discount enabled
cart.next_cart()
cart = TestingCartController.for_user(self.USER_1)
cart.add_to_cart(self.PROD_2, 2) # The discount will be exhausted
cart.next_cart()
discounts = discount.available_discounts(
self.USER_1,
[],
[self.PROD_2],
)
self.assertEqual(0, len(discounts))
cart.cart.released = True
cart.next_cart()
discounts = discount.available_discounts(
self.USER_1,
[],
[self.PROD_2],
)
self.assertEqual(1, len(discounts))
示例7: test_cart_discounts_only_calculated_at_end_of_batches
# 需要导入模块: from controller_helpers import TestingCartController [as 别名]
# 或者: from controller_helpers.TestingCartController import for_user [as 别名]
def test_cart_discounts_only_calculated_at_end_of_batches(self):
def count_discounts(cart):
return cart.cart.discountitem_set.count()
cart = TestingCartController.for_user(self.USER_1)
self.make_discount_ceiling("FLOOZLE")
count_0 = count_discounts(cart)
with BatchController.batch(self.USER_1):
# Memoise the cart
same_cart = TestingCartController.for_user(self.USER_1)
with BatchController.batch(self.USER_1):
# Memoise the cart
same_cart_2 = TestingCartController.for_user(self.USER_1)
same_cart_2.add_to_cart(self.PROD_1, 1)
count_1 = count_discounts(same_cart_2)
count_2 = count_discounts(same_cart)
count_3 = count_discounts(cart)
self.assertEqual(0, count_0)
self.assertEqual(0, count_1)
self.assertEqual(0, count_2)
self.assertEqual(1, count_3)
示例8: test_apply_credit_note_pays_invoice
# 需要导入模块: from controller_helpers import TestingCartController [as 别名]
# 或者: from controller_helpers.TestingCartController import for_user [as 别名]
def test_apply_credit_note_pays_invoice(self):
cart = TestingCartController.for_user(self.USER_1)
cart.add_to_cart(self.PROD_1, 1)
invoice = TestingInvoiceController.for_cart(self.reget(cart.cart))
to_pay = invoice.invoice.value
invoice.pay("Reference", to_pay)
self.assertTrue(invoice.invoice.is_paid)
invoice.refund()
# There should be one credit note generated out of the invoice.
credit_note = commerce.CreditNote.objects.get(invoice=invoice.invoice)
cn = TestingCreditNoteController(credit_note)
# That credit note should be in the unclaimed pile
self.assertEquals(1, commerce.CreditNote.unclaimed().count())
# Create a new (identical) cart with invoice
cart = TestingCartController.for_user(self.USER_1)
cart.add_to_cart(self.PROD_1, 1)
invoice2 = TestingInvoiceController.for_cart(self.reget(cart.cart))
cn.apply_to_invoice(invoice2.invoice)
self.assertTrue(invoice2.invoice.is_paid)
# That invoice should not show up as unclaimed any more
self.assertEquals(0, commerce.CreditNote.unclaimed().count())
示例9: test_cannot_apply_a_refunded_credit_note
# 需要导入模块: from controller_helpers import TestingCartController [as 别名]
# 或者: from controller_helpers.TestingCartController import for_user [as 别名]
def test_cannot_apply_a_refunded_credit_note(self):
cart = TestingCartController.for_user(self.USER_1)
cart.add_to_cart(self.PROD_1, 1)
invoice = TestingInvoiceController.for_cart(self.reget(cart.cart))
to_pay = invoice.invoice.value
invoice.pay("Reference", to_pay)
self.assertTrue(invoice.invoice.is_paid)
invoice.refund()
self.assertEquals(1, rego.CreditNote.unclaimed().count())
credit_note = rego.CreditNote.objects.get(invoice=invoice.invoice)
cn = TestingCreditNoteController(credit_note)
cn.refund()
# Refunding a credit note should mark it as claimed
self.assertEquals(0, rego.CreditNote.unclaimed().count())
# Create a new cart with invoice
cart = TestingCartController.for_user(self.USER_1)
cart.add_to_cart(self.PROD_1, 1)
invoice_2 = TestingInvoiceController.for_cart(self.reget(cart.cart))
# Cannot pay with this credit note.
with self.assertRaises(ValidationError):
cn.apply_to_invoice(invoice_2.invoice)
示例10: test_required_category_constraints_prevent_invoicing
# 需要导入模块: from controller_helpers import TestingCartController [as 别名]
# 或者: from controller_helpers.TestingCartController import for_user [as 别名]
def test_required_category_constraints_prevent_invoicing(self):
self.CAT_1.required = True
self.CAT_1.save()
cart = TestingCartController.for_user(self.USER_1)
cart.add_to_cart(self.PROD_3, 1)
# CAT_1 is required, we don't have CAT_1 yet
with self.assertRaises(ValidationError):
invoice = TestingInvoiceController.for_cart(cart.cart)
# Now that we have CAT_1, we can check out the cart
cart.add_to_cart(self.PROD_1, 1)
invoice = TestingInvoiceController.for_cart(cart.cart)
# Paying for the invoice should work fine
invoice.pay("Boop", invoice.invoice.value)
# We have an item in the first cart, so should be able to invoice
# for the second cart, even without CAT_1 in it.
cart = TestingCartController.for_user(self.USER_1)
cart.add_to_cart(self.PROD_3, 1)
invoice2 = TestingInvoiceController.for_cart(cart.cart)
# Void invoice2, and release the first cart
# now we don't have any CAT_1
invoice2.void()
invoice.refund()
# Now that we don't have CAT_1, we can't checkout this cart
with self.assertRaises(ValidationError):
invoice = TestingInvoiceController.for_cart(cart.cart)
示例11: test_product_enabled_by_category_in_previous_cart
# 需要导入模块: from controller_helpers import TestingCartController [as 别名]
# 或者: from controller_helpers.TestingCartController import for_user [as 别名]
def test_product_enabled_by_category_in_previous_cart(self):
self.add_category_flag()
current_cart = TestingCartController.for_user(self.USER_1)
current_cart.add_to_cart(self.PROD_3, 1)
current_cart.next_cart()
# Create new cart and try to add PROD_1
current_cart = TestingCartController.for_user(self.USER_1)
current_cart.add_to_cart(self.PROD_1, 1)
示例12: test_cart_revision_does_not_increment_if_not_modified
# 需要导入模块: from controller_helpers import TestingCartController [as 别名]
# 或者: from controller_helpers.TestingCartController import for_user [as 别名]
def test_cart_revision_does_not_increment_if_not_modified(self):
cart = TestingCartController.for_user(self.USER_1)
rev_0 = cart.cart.revision
with BatchController.batch(self.USER_1):
# Memoise the cart
same_cart = TestingCartController.for_user(self.USER_1)
# Do nothing on exit
rev_1 = self.reget(cart.cart).revision
self.assertEqual(rev_0, rev_1)
示例13: test_get_cart
# 需要导入模块: from controller_helpers import TestingCartController [as 别名]
# 或者: from controller_helpers.TestingCartController import for_user [as 别名]
def test_get_cart(self):
current_cart = TestingCartController.for_user(self.USER_1)
current_cart.next_cart()
old_cart = current_cart
current_cart = TestingCartController.for_user(self.USER_1)
self.assertNotEqual(old_cart.cart, current_cart.cart)
current_cart2 = TestingCartController.for_user(self.USER_1)
self.assertEqual(current_cart.cart, current_cart2.cart)
示例14: test_voucher_can_only_be_applied_once_across_multiple_carts
# 需要导入模块: from controller_helpers import TestingCartController [as 别名]
# 或者: from controller_helpers.TestingCartController import for_user [as 别名]
def test_voucher_can_only_be_applied_once_across_multiple_carts(self):
voucher = self.new_voucher(limit=2)
current_cart = TestingCartController.for_user(self.USER_1)
current_cart.apply_voucher(voucher.code)
current_cart.next_cart()
current_cart = TestingCartController.for_user(self.USER_1)
with self.assertRaises(ValidationError):
current_cart.apply_voucher(voucher.code)
return current_cart
示例15: test_cart_revision_only_increments_at_end_of_batches
# 需要导入模块: from controller_helpers import TestingCartController [as 别名]
# 或者: from controller_helpers.TestingCartController import for_user [as 别名]
def test_cart_revision_only_increments_at_end_of_batches(self):
cart = TestingCartController.for_user(self.USER_1)
rev_0 = cart.cart.revision
with BatchController.batch(self.USER_1):
# Memoise the cart
same_cart = TestingCartController.for_user(self.USER_1)
same_cart.add_to_cart(self.PROD_1, 1)
rev_1 = self.reget(same_cart.cart).revision
rev_2 = self.reget(cart.cart).revision
self.assertEqual(rev_0, rev_1)
self.assertNotEqual(rev_0, rev_2)