Simplifies credit note tests
This commit is contained in:
parent
04b7a7998c
commit
5fce13d386
2 changed files with 21 additions and 25 deletions
|
@ -16,6 +16,8 @@ from test_cart import RegistrationCartTestCase
|
||||||
|
|
||||||
UTC = pytz.timezone('UTC')
|
UTC = pytz.timezone('UTC')
|
||||||
|
|
||||||
|
HOURS = datetime.timedelta(hours=1)
|
||||||
|
|
||||||
|
|
||||||
class CreditNoteTestCase(TestHelperMixin, RegistrationCartTestCase):
|
class CreditNoteTestCase(TestHelperMixin, RegistrationCartTestCase):
|
||||||
|
|
||||||
|
@ -337,17 +339,13 @@ class CreditNoteTestCase(TestHelperMixin, RegistrationCartTestCase):
|
||||||
self.assertTrue(invoice2.invoice.is_paid)
|
self.assertTrue(invoice2.invoice.is_paid)
|
||||||
|
|
||||||
def _generate_multiple_credit_notes(self):
|
def _generate_multiple_credit_notes(self):
|
||||||
items = [("Item 1", 5), ("Item 2", 6)]
|
invoice1 = self._manual_invoice(11)
|
||||||
due = datetime.timedelta(hours=1)
|
invoice2 = self._manual_invoice(11)
|
||||||
inv1 = TestingInvoiceController.manual_invoice(self.USER_1, due, items)
|
invoice1.pay("Pay", invoice1.invoice.value)
|
||||||
inv2 = TestingInvoiceController.manual_invoice(self.USER_1, due, items)
|
|
||||||
invoice1 = TestingInvoiceController(inv1)
|
|
||||||
invoice1.pay("Pay", inv1.value)
|
|
||||||
invoice1.refund()
|
invoice1.refund()
|
||||||
invoice2 = TestingInvoiceController(inv2)
|
invoice2.pay("Pay", invoice2.invoice.value)
|
||||||
invoice2.pay("Pay", inv2.value)
|
|
||||||
invoice2.refund()
|
invoice2.refund()
|
||||||
return inv1.value + inv2.value
|
return invoice1.invoice.value + invoice2.invoice.value
|
||||||
|
|
||||||
def test_mutiple_credit_notes_are_applied_when_generating_invoice_1(self):
|
def test_mutiple_credit_notes_are_applied_when_generating_invoice_1(self):
|
||||||
''' Tests (1) that multiple credit notes are applied to new invoice.
|
''' Tests (1) that multiple credit notes are applied to new invoice.
|
||||||
|
@ -356,10 +354,7 @@ class CreditNoteTestCase(TestHelperMixin, RegistrationCartTestCase):
|
||||||
'''
|
'''
|
||||||
|
|
||||||
notes_value = self._generate_multiple_credit_notes()
|
notes_value = self._generate_multiple_credit_notes()
|
||||||
item = [("Item", notes_value + 1)]
|
invoice = self._manual_invoice(notes_value + 1)
|
||||||
due = datetime.timedelta(hours=1)
|
|
||||||
inv = TestingInvoiceController.manual_invoice(self.USER_1, due, item)
|
|
||||||
invoice = TestingInvoiceController(inv)
|
|
||||||
|
|
||||||
self.assertEqual(notes_value, invoice.total_payments())
|
self.assertEqual(notes_value, invoice.total_payments())
|
||||||
self.assertTrue(invoice.invoice.is_unpaid)
|
self.assertTrue(invoice.invoice.is_unpaid)
|
||||||
|
@ -375,10 +370,8 @@ class CreditNoteTestCase(TestHelperMixin, RegistrationCartTestCase):
|
||||||
'''
|
'''
|
||||||
|
|
||||||
notes_value = self._generate_multiple_credit_notes()
|
notes_value = self._generate_multiple_credit_notes()
|
||||||
item = [("Item", notes_value - 1)]
|
invoice = self._manual_invoice(notes_value - 1)
|
||||||
due = datetime.timedelta(hours=1)
|
|
||||||
inv = TestingInvoiceController.manual_invoice(self.USER_1, due, item)
|
|
||||||
invoice = TestingInvoiceController(inv)
|
|
||||||
|
|
||||||
self.assertEqual(notes_value - 1, invoice.total_payments())
|
self.assertEqual(notes_value - 1, invoice.total_payments())
|
||||||
self.assertTrue(invoice.invoice.is_paid)
|
self.assertTrue(invoice.invoice.is_paid)
|
||||||
|
@ -402,10 +395,7 @@ class CreditNoteTestCase(TestHelperMixin, RegistrationCartTestCase):
|
||||||
|
|
||||||
# Create a manual invoice whose value is smaller than any of the
|
# Create a manual invoice whose value is smaller than any of the
|
||||||
# credit notes we created
|
# credit notes we created
|
||||||
item = [("Item", 1)]
|
invoice = self._manual_invoice(1)
|
||||||
due = datetime.timedelta(hours=1)
|
|
||||||
inv = TestingInvoiceController.manual_invoice(self.USER_1, due, item)
|
|
||||||
|
|
||||||
notes_new = commerce.CreditNote.unclaimed().filter(
|
notes_new = commerce.CreditNote.unclaimed().filter(
|
||||||
invoice__user=self.USER_1
|
invoice__user=self.USER_1
|
||||||
)
|
)
|
||||||
|
@ -421,10 +411,7 @@ class CreditNoteTestCase(TestHelperMixin, RegistrationCartTestCase):
|
||||||
# Create some credit notes.
|
# Create some credit notes.
|
||||||
self._generate_multiple_credit_notes()
|
self._generate_multiple_credit_notes()
|
||||||
|
|
||||||
item = [("Item", notes_value)]
|
invoice = self._manual_invoice(2)
|
||||||
due = datetime.timedelta(hours=1)
|
|
||||||
inv = TestingInvoiceController.manual_invoice(self.USER_1, due, item)
|
|
||||||
invoice = TestingInvoiceController(inv)
|
|
||||||
|
|
||||||
# Because there's already an invoice open for this user
|
# Because there's already an invoice open for this user
|
||||||
# The credit notes are not automatically applied.
|
# The credit notes are not automatically applied.
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import datetime
|
||||||
|
|
||||||
from registrasion.models import commerce
|
from registrasion.models import commerce
|
||||||
|
|
||||||
from controller_helpers import TestingCartController
|
from controller_helpers import TestingCartController
|
||||||
|
@ -12,6 +14,13 @@ class TestHelperMixin(object):
|
||||||
|
|
||||||
return TestingInvoiceController.for_cart(self.reget(cart.cart))
|
return TestingInvoiceController.for_cart(self.reget(cart.cart))
|
||||||
|
|
||||||
|
def _manual_invoice(self, value=1):
|
||||||
|
items = [("Item", value)]
|
||||||
|
due = datetime.timedelta(hours=1)
|
||||||
|
inv = TestingInvoiceController.manual_invoice(self.USER_1, due, items)
|
||||||
|
|
||||||
|
return TestingInvoiceController(inv)
|
||||||
|
|
||||||
def _credit_note_for_invoice(self, invoice):
|
def _credit_note_for_invoice(self, invoice):
|
||||||
note = commerce.CreditNote.objects.get(invoice=invoice)
|
note = commerce.CreditNote.objects.get(invoice=invoice)
|
||||||
return TestingCreditNoteController(note)
|
return TestingCreditNoteController(note)
|
||||||
|
|
Loading…
Reference in a new issue