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


Python controller_helpers.TestingInvoiceController类代码示例

本文整理汇总了Python中controller_helpers.TestingInvoiceController的典型用法代码示例。如果您正苦于以下问题:Python TestingInvoiceController类的具体用法?Python TestingInvoiceController怎么用?Python TestingInvoiceController使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_cannot_apply_a_refunded_credit_note

    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)
开发者ID:McJones,项目名称:registrasion,代码行数:31,代码来源:test_invoice.py

示例2: test_create_invoice

    def test_create_invoice(self):
        current_cart = TestingCartController.for_user(self.USER_1)

        # Should be able to create an invoice after the product is added
        current_cart.add_to_cart(self.PROD_1, 1)
        invoice_1 = TestingInvoiceController.for_cart(current_cart.cart)
        # That invoice should have a single line item
        line_items = commerce.LineItem.objects.filter(
            invoice=invoice_1.invoice,
        )
        self.assertEqual(1, len(line_items))
        # That invoice should have a value equal to cost of PROD_1
        self.assertEqual(self.PROD_1.price, invoice_1.invoice.value)

        # Adding item to cart should produce a new invoice
        current_cart.add_to_cart(self.PROD_2, 1)
        invoice_2 = TestingInvoiceController.for_cart(current_cart.cart)
        self.assertNotEqual(invoice_1.invoice, invoice_2.invoice)

        # The old invoice should automatically be voided
        invoice_1_new = commerce.Invoice.objects.get(pk=invoice_1.invoice.id)
        invoice_2_new = commerce.Invoice.objects.get(pk=invoice_2.invoice.id)
        self.assertTrue(invoice_1_new.is_void)
        self.assertFalse(invoice_2_new.is_void)

        # Invoice should have two line items
        line_items = commerce.LineItem.objects.filter(
            invoice=invoice_2.invoice,
        )
        self.assertEqual(2, len(line_items))
        # Invoice should have a value equal to cost of PROD_1 and PROD_2
        self.assertEqual(
            self.PROD_1.price + self.PROD_2.price,
            invoice_2.invoice.value)
开发者ID:glasnt,项目名称:registrasion,代码行数:34,代码来源:test_invoice.py

示例3: test_required_category_constraints_prevent_invoicing

    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)
开发者ID:faulteh,项目名称:registrasion,代码行数:33,代码来源:test_invoice.py

示例4: test_apply_credit_note_pays_invoice

    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())
开发者ID:glasnt,项目名称:registrasion,代码行数:30,代码来源:test_invoice.py

示例5: test_cannot_refund_an_applied_credit_note

    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()
开发者ID:glasnt,项目名称:registrasion,代码行数:30,代码来源:test_invoice.py

示例6: test_invoice_controller_for_id_works

    def test_invoice_controller_for_id_works(self):
        invoice = self._invoice_containing_prod_1(1)

        id_ = invoice.invoice.id

        invoice1 = TestingInvoiceController.for_id(id_)
        invoice2 = TestingInvoiceController.for_id(str(id_))

        self.assertEqual(invoice.invoice, invoice1.invoice)
        self.assertEqual(invoice.invoice, invoice2.invoice)
开发者ID:faulteh,项目名称:registrasion,代码行数:10,代码来源:test_invoice.py

示例7: test_voiding_invoice_creates_new_invoice

    def test_voiding_invoice_creates_new_invoice(self):
        current_cart = TestingCartController.for_user(self.USER_1)

        # Should be able to create an invoice after the product is added
        current_cart.add_to_cart(self.PROD_1, 1)
        invoice_1 = TestingInvoiceController.for_cart(current_cart.cart)

        self.assertFalse(invoice_1.invoice.is_void)
        invoice_1.void()

        invoice_2 = TestingInvoiceController.for_cart(current_cart.cart)
        self.assertNotEqual(invoice_1.invoice, invoice_2.invoice)
开发者ID:glasnt,项目名称:registrasion,代码行数:12,代码来源:test_invoice.py

示例8: test_zero_value_invoice_is_automatically_paid

    def test_zero_value_invoice_is_automatically_paid(self):
        voucher = inventory.Voucher.objects.create(
            recipient="Voucher recipient",
            code="VOUCHER",
            limit=1
        )
        discount = conditions.VoucherDiscount.objects.create(
            description="VOUCHER RECIPIENT",
            voucher=voucher,
        )
        conditions.DiscountForProduct.objects.create(
            discount=discount,
            product=self.PROD_1,
            percentage=Decimal(100),
            quantity=1
        )

        current_cart = TestingCartController.for_user(self.USER_1)
        current_cart.apply_voucher(voucher.code)

        # Should be able to create an invoice after the product is added
        current_cart.add_to_cart(self.PROD_1, 1)
        invoice_1 = TestingInvoiceController.for_cart(current_cart.cart)

        self.assertTrue(invoice_1.invoice.is_paid)
开发者ID:glasnt,项目名称:registrasion,代码行数:25,代码来源:test_invoice.py

示例9: test_invoice_includes_discounts

    def test_invoice_includes_discounts(self):
        voucher = inventory.Voucher.objects.create(
            recipient="Voucher recipient",
            code="VOUCHER",
            limit=1
        )
        discount = conditions.VoucherDiscount.objects.create(
            description="VOUCHER RECIPIENT",
            voucher=voucher,
        )
        conditions.DiscountForProduct.objects.create(
            discount=discount,
            product=self.PROD_1,
            percentage=Decimal(50),
            quantity=1
        )

        current_cart = TestingCartController.for_user(self.USER_1)
        current_cart.apply_voucher(voucher.code)

        # Should be able to create an invoice after the product is added
        current_cart.add_to_cart(self.PROD_1, 1)
        invoice_1 = TestingInvoiceController.for_cart(current_cart.cart)

        # That invoice should have two line items
        line_items = commerce.LineItem.objects.filter(
            invoice=invoice_1.invoice,
        )
        self.assertEqual(2, len(line_items))
        # That invoice should have a value equal to 50% of the cost of PROD_1
        self.assertEqual(
            self.PROD_1.price * Decimal("0.5"),
            invoice_1.invoice.value)
开发者ID:glasnt,项目名称:registrasion,代码行数:33,代码来源:test_invoice.py

示例10: test_voiding_invoice_creates_new_invoice

    def test_voiding_invoice_creates_new_invoice(self):
        invoice_1 = self._invoice_containing_prod_1(1)

        self.assertFalse(invoice_1.invoice.is_void)
        invoice_1.void()

        invoice_2 = TestingInvoiceController.for_cart(invoice_1.invoice.cart)
        self.assertNotEqual(invoice_1.invoice, invoice_2.invoice)
开发者ID:faulteh,项目名称:registrasion,代码行数:8,代码来源:test_invoice.py

示例11: test_cannot_pay_implicitly_void_invoice

    def test_cannot_pay_implicitly_void_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))

        # Implicitly void the invoice
        cart.add_to_cart(self.PROD_1, 1)

        with self.assertRaises(ValidationError):
            invoice.validate_allowed_to_pay()
开发者ID:glasnt,项目名称:registrasion,代码行数:10,代码来源:test_invoice.py

示例12: test_cannot_void_paid_invoice

    def test_cannot_void_paid_invoice(self):
        current_cart = TestingCartController.for_user(self.USER_1)

        # Should be able to create an invoice after the product is added
        current_cart.add_to_cart(self.PROD_1, 1)
        invoice = TestingInvoiceController.for_cart(current_cart.cart)

        invoice.pay("Reference", invoice.invoice.value)

        with self.assertRaises(ValidationError):
            invoice.void()
开发者ID:glasnt,项目名称:registrasion,代码行数:11,代码来源:test_invoice.py

示例13: test_apply_credit_note_generates_new_credit_note_if_overpaying

    def test_apply_credit_note_generates_new_credit_note_if_overpaying(self):
        cart = TestingCartController.for_user(self.USER_1)
        cart.add_to_cart(self.PROD_1, 2)

        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)

        self.assertEquals(1, commerce.CreditNote.unclaimed().count())

        # Create a new cart (of half value of inv 1) and get 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)

        # We generated a new credit note, and spent the old one,
        # unclaimed should still be 1.
        self.assertEquals(1, commerce.CreditNote.unclaimed().count())

        credit_note2 = commerce.CreditNote.objects.get(
            invoice=invoice2.invoice,
        )

        # The new credit note should be the residual of the cost of cart 1
        # minus the cost of cart 2.
        self.assertEquals(
            invoice.invoice.value - invoice2.invoice.value,
            credit_note2.value,
        )
开发者ID:glasnt,项目名称:registrasion,代码行数:41,代码来源:test_invoice.py

示例14: test_cannot_apply_credit_note_on_invalid_invoices

    def test_cannot_apply_credit_note_on_invalid_invoices(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)

        # Create a new cart with invoice, pay it
        cart = TestingCartController.for_user(self.USER_1)
        cart.add_to_cart(self.PROD_1, 1)

        invoice_2 = TestingInvoiceController.for_cart(self.reget(cart.cart))
        invoice_2.pay("LOL", invoice_2.invoice.value)

        # Cannot pay paid invoice
        with self.assertRaises(ValidationError):
            cn.apply_to_invoice(invoice_2.invoice)

        invoice_2.refund()
        # Cannot pay refunded invoice
        with self.assertRaises(ValidationError):
            cn.apply_to_invoice(invoice_2.invoice)

        # 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))
        invoice_2.void()
        # Cannot pay void invoice
        with self.assertRaises(ValidationError):
            cn.apply_to_invoice(invoice_2.invoice)
开发者ID:glasnt,项目名称:registrasion,代码行数:41,代码来源:test_invoice.py

示例15: test_invoice_voids_self_if_cart_is_invalid

    def test_invoice_voids_self_if_cart_is_invalid(self):
        current_cart = TestingCartController.for_user(self.USER_1)

        # Should be able to create an invoice after the product is added
        current_cart.add_to_cart(self.PROD_1, 1)
        invoice_1 = TestingInvoiceController.for_cart(current_cart.cart)

        self.assertFalse(invoice_1.invoice.is_void)

        # Adding item to cart should produce a new invoice
        current_cart.add_to_cart(self.PROD_2, 1)
        invoice_2 = TestingInvoiceController.for_cart(current_cart.cart)
        self.assertNotEqual(invoice_1.invoice, invoice_2.invoice)

        # Viewing invoice_1's invoice should show it as void
        invoice_1_new = TestingInvoiceController(invoice_1.invoice)
        self.assertTrue(invoice_1_new.invoice.is_void)

        # Viewing invoice_2's invoice should *not* show it as void
        invoice_2_new = TestingInvoiceController(invoice_2.invoice)
        self.assertFalse(invoice_2_new.invoice.is_void)
开发者ID:glasnt,项目名称:registrasion,代码行数:21,代码来源:test_invoice.py


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