Changeset - 9a4574ef2c3b
[Not reviewed]
0 1 0
Christopher Neugebauer - 8 years ago 2016-04-24 22:25:19
chrisjrn@gmail.com
DRYs up test_invoice a bit
1 file changed with 25 insertions and 73 deletions:
0 comments (0 inline, 0 general)
registrasion/tests/test_invoice.py
Show inline comments
...
 
@@ -19,4 +19,10 @@ UTC = pytz.timezone('UTC')
 
class InvoiceTestCase(RegistrationCartTestCase):
 

	
 
    def _invoice_containing_prod_1(self, qty=1):
 
        cart = TestingCartController.for_user(self.USER_1)
 
        cart.add_to_cart(self.PROD_1, qty)
 

	
 
        return TestingInvoiceController.for_cart(self.reget(cart.cart))
 

	
 
    def test_create_invoice(self):
 
        current_cart = TestingCartController.for_user(self.USER_1)
...
 
@@ -55,8 +61,5 @@ class InvoiceTestCase(RegistrationCartTestCase):
 

	
 
    def test_invoice_controller_for_id_works(self):
 
        current_cart = TestingCartController.for_user(self.USER_1)
 
        current_cart.add_to_cart(self.PROD_1, 1)
 

	
 
        invoice = TestingInvoiceController.for_cart(current_cart.cart)
 
        invoice = self._invoice_containing_prod_1(1)
 

	
 
        id_ = invoice.invoice.id
...
 
@@ -83,8 +86,6 @@ class InvoiceTestCase(RegistrationCartTestCase):
 

	
 
    def test_paying_invoice_makes_new_cart(self):
 
        current_cart = TestingCartController.for_user(self.USER_1)
 
        current_cart.add_to_cart(self.PROD_1, 1)
 
        invoice = self._invoice_containing_prod_1(1)
 

	
 
        invoice = TestingInvoiceController.for_cart(current_cart.cart)
 
        invoice.pay("A payment!", invoice.invoice.value)
 

	
...
 
@@ -97,5 +98,5 @@ class InvoiceTestCase(RegistrationCartTestCase):
 
        # Asking for a cart should generate a new one
 
        new_cart = TestingCartController.for_user(self.USER_1)
 
        self.assertNotEqual(current_cart.cart, new_cart.cart)
 
        self.assertNotEqual(invoice.invoice.cart, new_cart.cart)
 

	
 
    def test_invoice_includes_discounts(self):
...
 
@@ -182,22 +183,14 @@ class InvoiceTestCase(RegistrationCartTestCase):
 

	
 
    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)
 
        invoice_1 = self._invoice_containing_prod_1(1)
 

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

	
 
        invoice_2 = TestingInvoiceController.for_cart(current_cart.cart)
 
        invoice_2 = TestingInvoiceController.for_cart(invoice_1.invoice.cart)
 
        self.assertNotEqual(invoice_1.invoice, invoice_2.invoice)
 

	
 
    def test_cannot_pay_void_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)
 
        invoice_1 = self._invoice_containing_prod_1(1)
 

	
 
        invoice_1.void()
...
 
@@ -207,9 +200,5 @@ class InvoiceTestCase(RegistrationCartTestCase):
 

	
 
    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 = self._invoice_containing_prod_1(1)
 

	
 
        invoice.pay("Reference", invoice.invoice.value)
...
 
@@ -219,9 +208,5 @@ class InvoiceTestCase(RegistrationCartTestCase):
 

	
 
    def test_cannot_void_partially_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 = self._invoice_containing_prod_1(1)
 

	
 
        invoice.pay("Reference", invoice.invoice.value - 1)
...
 
@@ -248,8 +233,5 @@ class InvoiceTestCase(RegistrationCartTestCase):
 

	
 
    def test_overpaid_invoice_results_in_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))
 
        invoice = self._invoice_containing_prod_1(1)
 

	
 
        # Invoice is overpaid by 1 unit
...
 
@@ -269,8 +251,5 @@ class InvoiceTestCase(RegistrationCartTestCase):
 

	
 
    def test_full_paid_invoice_does_not_generate_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))
 
        invoice = self._invoice_containing_prod_1(1)
 

	
 
        # Invoice is paid evenly
...
 
@@ -288,8 +267,5 @@ class InvoiceTestCase(RegistrationCartTestCase):
 

	
 
    def test_refund_partially_paid_invoice_generates_correct_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))
 
        invoice = self._invoice_containing_prod_1(1)
 

	
 
        # Invoice is underpaid by 1 unit
...
 
@@ -310,8 +286,5 @@ class InvoiceTestCase(RegistrationCartTestCase):
 

	
 
    def test_refund_fully_paid_invoice_generates_correct_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))
 
        invoice = self._invoice_containing_prod_1(1)
 

	
 
        to_pay = invoice.invoice.value
...
 
@@ -333,8 +306,5 @@ class InvoiceTestCase(RegistrationCartTestCase):
 

	
 
    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))
 
        invoice = self._invoice_containing_prod_1(1)
 

	
 
        to_pay = invoice.invoice.value
...
 
@@ -364,8 +334,5 @@ class InvoiceTestCase(RegistrationCartTestCase):
 

	
 
    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))
 
        invoice = self._invoice_containing_prod_1(2)
 

	
 
        to_pay = invoice.invoice.value
...
 
@@ -406,8 +373,5 @@ class InvoiceTestCase(RegistrationCartTestCase):
 

	
 
    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))
 
        invoice = self._invoice_containing_prod_1(1)
 

	
 
        to_pay = invoice.invoice.value
...
 
@@ -422,8 +386,5 @@ class InvoiceTestCase(RegistrationCartTestCase):
 

	
 
        # 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 = self._invoice_containing_prod_1(1)
 
        invoice_2.pay("LOL", invoice_2.invoice.value)
 

	
...
 
@@ -438,8 +399,5 @@ class InvoiceTestCase(RegistrationCartTestCase):
 

	
 
        # 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 = self._invoice_containing_prod_1(1)
 
        invoice_2.void()
 
        # Cannot pay void invoice
...
 
@@ -448,8 +406,5 @@ class InvoiceTestCase(RegistrationCartTestCase):
 

	
 
    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))
 
        invoice = self._invoice_containing_prod_1(1)
 

	
 
        to_pay = invoice.invoice.value
...
 
@@ -480,8 +435,5 @@ class InvoiceTestCase(RegistrationCartTestCase):
 

	
 
    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))
 
        invoice = self._invoice_containing_prod_1(1)
 

	
 
        to_pay = invoice.invoice.value
0 comments (0 inline, 0 general)