diff --git a/registrasion/tests/controller_helpers.py b/registrasion/tests/controller_helpers.py index 32af58c858d79f97625f729bd38ff4d5b4e299bd..60cf2346210b9d400ff9e9539704c4bee45649a1 100644 --- a/registrasion/tests/controller_helpers.py +++ b/registrasion/tests/controller_helpers.py @@ -3,6 +3,7 @@ from registrasion.controllers.invoice import InvoiceController from registrasion import models as rego from django.core.exceptions import ObjectDoesNotExist +from django.core.exceptions import ValidationError class TestingCartController(CartController): @@ -32,4 +33,27 @@ class TestingCartController(CartController): class TestingInvoiceController(InvoiceController): - pass + + def pay(self, reference, amount): + ''' Testing method for simulating an invoice paymenht by the given + amount. ''' + if self.invoice.cart: + cart = CartController(self.invoice.cart) + cart.validate_cart() # Raises ValidationError if invalid + + status = self.invoice.status + if status == rego.Invoice.STATUS_VOID: + raise ValidationError("Void invoices cannot be paid") + elif status == rego.Invoice.STATUS_PAID: + raise ValidationError("Paid invoices cannot be paid again") + elif status == rego.Invoice.STATUS_REFUNDED: + raise ValidationError("Refunded invoices cannot be paid") + + ''' Adds a payment ''' + payment = rego.ManualPayment.objects.create( + invoice=self.invoice, + reference=reference, + amount=amount, + ) + + self.update_status()