Changeset - 8ad265a65a08
[Not reviewed]
0 4 0
Christopher Neugebauer - 8 years ago 2016-04-06 07:19:09
chrisjrn@gmail.com
Fixes tests now that $0 invoices pay themselves
4 files changed with 46 insertions and 16 deletions:
0 comments (0 inline, 0 general)
registrasion/controllers/invoice.py
Show inline comments
...
 
@@ -59,2 +59,3 @@ class InvoiceController(object):
 
    @classmethod
 
    @transaction.atomic
 
    def _generate(cls, cart):
...
 
@@ -67,3 +68,2 @@ class InvoiceController(object):
 
        )
 
        invoice.save()
 

	
...
 
@@ -87,3 +87,2 @@ class InvoiceController(object):
 
            )
 
            line_item.save()
 
            invoice_value += line_item.quantity * line_item.price
...
 
@@ -97,7 +96,9 @@ class InvoiceController(object):
 
            )
 
            line_item.save()
 
            invoice_value += line_item.quantity * line_item.price
 

	
 
        # TODO: calculate line items from discounts
 
        invoice.value = invoice_value
 

	
 
        if invoice.value == 0:
 
            invoice.paid = True
 

	
 
        invoice.save()
registrasion/tests/test_discount.py
Show inline comments
...
 
@@ -348,5 +348,4 @@ class DiscountTestCase(RegistrationCartTestCase):
 
        self.assertEqual(2, discounts[0].quantity)
 
        inv = InvoiceController.for_cart(cart.cart)
 
        inv.pay("Dummy reference", inv.invoice.value)
 
        self.assertTrue(inv.invoice.paid)
 
        cart.cart.active = False
 
        cart.cart.save()
 

	
...
 
@@ -360,5 +359,4 @@ class DiscountTestCase(RegistrationCartTestCase):
 
        self.assertEqual(1, discounts[0].quantity)
 
        inv = InvoiceController.for_cart(cart.cart)
 
        inv.pay("Dummy reference", inv.invoice.value)
 
        self.assertTrue(inv.invoice.paid)
 
        cart.cart.active = False
 
        cart.cart.save()
 

	
registrasion/tests/test_invoice.py
Show inline comments
...
 
@@ -85,3 +85,2 @@ class InvoiceTestCase(RegistrationCartTestCase):
 
        )
 
        voucher.save()
 
        discount = rego.VoucherDiscount.objects.create(
...
 
@@ -90,3 +89,2 @@ class InvoiceTestCase(RegistrationCartTestCase):
 
        )
 
        discount.save()
 
        rego.DiscountForProduct.objects.create(
...
 
@@ -96,3 +94,3 @@ class InvoiceTestCase(RegistrationCartTestCase):
 
            quantity=1
 
        ).save()
 
        )
 

	
...
 
@@ -113,2 +111,28 @@ class InvoiceTestCase(RegistrationCartTestCase):
 

	
 
    def test_zero_value_invoice_is_automatically_paid(self):
 
        voucher = rego.Voucher.objects.create(
 
            recipient="Voucher recipient",
 
            code="VOUCHER",
 
            limit=1
 
        )
 
        discount = rego.VoucherDiscount.objects.create(
 
            description="VOUCHER RECIPIENT",
 
            voucher=voucher,
 
        )
 
        rego.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 = InvoiceController.for_cart(current_cart.cart)
 

	
 
        self.assertTrue(invoice_1.invoice.paid)
 

	
 
    def test_invoice_voids_self_if_cart_is_invalid(self):
...
 
@@ -171 +195,6 @@ class InvoiceTestCase(RegistrationCartTestCase):
 
            invoice_1.void()
 

	
 
    def test_cannot_generate_blank_invoice(self):
 
        current_cart = TestingCartController.for_user(self.USER_1)
 
        with self.assertRaises(ValidationError):
 
            invoice_1 = InvoiceController.for_cart(current_cart.cart)
registrasion/tests/test_voucher.py
Show inline comments
...
 
@@ -127,4 +127,4 @@ class VoucherTestCases(RegistrationCartTestCase):
 

	
 
        inv = InvoiceController.for_cart(current_cart.cart)
 
        inv.pay("Hello!", inv.invoice.value)
 
        current_cart.cart.active = False
 
        current_cart.cart.save()
 

	
...
 
@@ -141,5 +141,7 @@ class VoucherTestCases(RegistrationCartTestCase):
 
        current_cart.apply_voucher(voucher.code)
 
        current_cart.add_to_cart(self.PROD_1, 1)
 

	
 
        inv = InvoiceController.for_cart(current_cart.cart)
 
        inv.pay("Hello!", inv.invoice.value)
 
        if not inv.invoice.paid:
 
            inv.pay("Hello!", inv.invoice.value)
 

	
0 comments (0 inline, 0 general)