Tests now use TestingInvoiceController

This commit is contained in:
Christopher Neugebauer 2016-04-07 10:23:38 +10:00
parent ac10ea4ee8
commit 5633554854
5 changed files with 27 additions and 21 deletions

View file

@ -1,4 +1,5 @@
from registrasion.controllers.cart import CartController from registrasion.controllers.cart import CartController
from registrasion.controllers.invoice import InvoiceController
from registrasion import models as rego from registrasion import models as rego
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
@ -28,3 +29,7 @@ class TestingCartController(CartController):
def next_cart(self): def next_cart(self):
self.cart.active = False self.cart.active = False
self.cart.save() self.cart.save()
class TestingInvoiceController(InvoiceController):
pass

View file

@ -4,7 +4,8 @@ from decimal import Decimal
from registrasion import models as rego from registrasion import models as rego
from registrasion.controllers import discount from registrasion.controllers import discount
from cart_controller_helper import TestingCartController from controller_helpers import TestingCartController
from controller_helpers import TestingInvoiceController
from test_cart import RegistrationCartTestCase from test_cart import RegistrationCartTestCase

View file

@ -6,7 +6,7 @@ from django.core.exceptions import ValidationError
from registrasion import models as rego from registrasion import models as rego
from controller_helpers import TestingCartController from controller_helpers import TestingCartController
from registrasion.controllers.invoice import InvoiceController from controller_helpers import TestingInvoiceController
from test_cart import RegistrationCartTestCase from test_cart import RegistrationCartTestCase
@ -20,7 +20,7 @@ class InvoiceTestCase(RegistrationCartTestCase):
# Should be able to create an invoice after the product is added # Should be able to create an invoice after the product is added
current_cart.add_to_cart(self.PROD_1, 1) current_cart.add_to_cart(self.PROD_1, 1)
invoice_1 = InvoiceController.for_cart(current_cart.cart) invoice_1 = TestingInvoiceController.for_cart(current_cart.cart)
# That invoice should have a single line item # That invoice should have a single line item
line_items = rego.LineItem.objects.filter(invoice=invoice_1.invoice) line_items = rego.LineItem.objects.filter(invoice=invoice_1.invoice)
self.assertEqual(1, len(line_items)) self.assertEqual(1, len(line_items))
@ -29,7 +29,7 @@ class InvoiceTestCase(RegistrationCartTestCase):
# Adding item to cart should produce a new invoice # Adding item to cart should produce a new invoice
current_cart.add_to_cart(self.PROD_2, 1) current_cart.add_to_cart(self.PROD_2, 1)
invoice_2 = InvoiceController.for_cart(current_cart.cart) invoice_2 = TestingInvoiceController.for_cart(current_cart.cart)
self.assertNotEqual(invoice_1.invoice, invoice_2.invoice) self.assertNotEqual(invoice_1.invoice, invoice_2.invoice)
# The old invoice should automatically be voided # The old invoice should automatically be voided
@ -58,13 +58,13 @@ class InvoiceTestCase(RegistrationCartTestCase):
# Now try to invoice the first user # Now try to invoice the first user
with self.assertRaises(ValidationError): with self.assertRaises(ValidationError):
InvoiceController.for_cart(current_cart.cart) TestingInvoiceController.for_cart(current_cart.cart)
def test_paying_invoice_makes_new_cart(self): def test_paying_invoice_makes_new_cart(self):
current_cart = TestingCartController.for_user(self.USER_1) current_cart = TestingCartController.for_user(self.USER_1)
current_cart.add_to_cart(self.PROD_1, 1) current_cart.add_to_cart(self.PROD_1, 1)
invoice = InvoiceController.for_cart(current_cart.cart) invoice = TestingInvoiceController.for_cart(current_cart.cart)
invoice.pay("A payment!", invoice.invoice.value) invoice.pay("A payment!", invoice.invoice.value)
# This payment is for the correct amount invoice should be paid. # This payment is for the correct amount invoice should be paid.
@ -99,7 +99,7 @@ class InvoiceTestCase(RegistrationCartTestCase):
# Should be able to create an invoice after the product is added # Should be able to create an invoice after the product is added
current_cart.add_to_cart(self.PROD_1, 1) current_cart.add_to_cart(self.PROD_1, 1)
invoice_1 = InvoiceController.for_cart(current_cart.cart) invoice_1 = TestingInvoiceController.for_cart(current_cart.cart)
# That invoice should have two line items # That invoice should have two line items
line_items = rego.LineItem.objects.filter(invoice=invoice_1.invoice) line_items = rego.LineItem.objects.filter(invoice=invoice_1.invoice)
@ -131,7 +131,7 @@ class InvoiceTestCase(RegistrationCartTestCase):
# Should be able to create an invoice after the product is added # Should be able to create an invoice after the product is added
current_cart.add_to_cart(self.PROD_1, 1) current_cart.add_to_cart(self.PROD_1, 1)
invoice_1 = InvoiceController.for_cart(current_cart.cart) invoice_1 = TestingInvoiceController.for_cart(current_cart.cart)
self.assertTrue(invoice_1.invoice.paid) self.assertTrue(invoice_1.invoice.paid)
@ -140,21 +140,21 @@ class InvoiceTestCase(RegistrationCartTestCase):
# Should be able to create an invoice after the product is added # Should be able to create an invoice after the product is added
current_cart.add_to_cart(self.PROD_1, 1) current_cart.add_to_cart(self.PROD_1, 1)
invoice_1 = InvoiceController.for_cart(current_cart.cart) invoice_1 = TestingInvoiceController.for_cart(current_cart.cart)
self.assertFalse(invoice_1.invoice.void) self.assertFalse(invoice_1.invoice.void)
# Adding item to cart should produce a new invoice # Adding item to cart should produce a new invoice
current_cart.add_to_cart(self.PROD_2, 1) current_cart.add_to_cart(self.PROD_2, 1)
invoice_2 = InvoiceController.for_cart(current_cart.cart) invoice_2 = TestingInvoiceController.for_cart(current_cart.cart)
self.assertNotEqual(invoice_1.invoice, invoice_2.invoice) self.assertNotEqual(invoice_1.invoice, invoice_2.invoice)
# Viewing invoice_1's invoice should show it as void # Viewing invoice_1's invoice should show it as void
invoice_1_new = InvoiceController(invoice_1.invoice) invoice_1_new = TestingInvoiceController(invoice_1.invoice)
self.assertTrue(invoice_1_new.invoice.void) self.assertTrue(invoice_1_new.invoice.void)
# Viewing invoice_2's invoice should *not* show it as void # Viewing invoice_2's invoice should *not* show it as void
invoice_2_new = InvoiceController(invoice_2.invoice) invoice_2_new = TestingInvoiceController(invoice_2.invoice)
self.assertFalse(invoice_2_new.invoice.void) self.assertFalse(invoice_2_new.invoice.void)
def test_voiding_invoice_creates_new_invoice(self): def test_voiding_invoice_creates_new_invoice(self):
@ -162,12 +162,12 @@ class InvoiceTestCase(RegistrationCartTestCase):
# Should be able to create an invoice after the product is added # Should be able to create an invoice after the product is added
current_cart.add_to_cart(self.PROD_1, 1) current_cart.add_to_cart(self.PROD_1, 1)
invoice_1 = InvoiceController.for_cart(current_cart.cart) invoice_1 = TestingInvoiceController.for_cart(current_cart.cart)
self.assertFalse(invoice_1.invoice.void) self.assertFalse(invoice_1.invoice.void)
invoice_1.void() invoice_1.void()
invoice_2 = InvoiceController.for_cart(current_cart.cart) invoice_2 = TestingInvoiceController.for_cart(current_cart.cart)
self.assertNotEqual(invoice_1.invoice, invoice_2.invoice) self.assertNotEqual(invoice_1.invoice, invoice_2.invoice)
def test_cannot_pay_void_invoice(self): def test_cannot_pay_void_invoice(self):
@ -175,7 +175,7 @@ class InvoiceTestCase(RegistrationCartTestCase):
# Should be able to create an invoice after the product is added # Should be able to create an invoice after the product is added
current_cart.add_to_cart(self.PROD_1, 1) current_cart.add_to_cart(self.PROD_1, 1)
invoice_1 = InvoiceController.for_cart(current_cart.cart) invoice_1 = TestingInvoiceController.for_cart(current_cart.cart)
invoice_1.void() invoice_1.void()
@ -187,7 +187,7 @@ class InvoiceTestCase(RegistrationCartTestCase):
# Should be able to create an invoice after the product is added # Should be able to create an invoice after the product is added
current_cart.add_to_cart(self.PROD_1, 1) current_cart.add_to_cart(self.PROD_1, 1)
invoice_1 = InvoiceController.for_cart(current_cart.cart) invoice_1 = TestingInvoiceController.for_cart(current_cart.cart)
invoice_1.pay("Reference", invoice_1.invoice.value) invoice_1.pay("Reference", invoice_1.invoice.value)
@ -197,7 +197,7 @@ class InvoiceTestCase(RegistrationCartTestCase):
def test_cannot_generate_blank_invoice(self): def test_cannot_generate_blank_invoice(self):
current_cart = TestingCartController.for_user(self.USER_1) current_cart = TestingCartController.for_user(self.USER_1)
with self.assertRaises(ValidationError): with self.assertRaises(ValidationError):
invoice_1 = InvoiceController.for_cart(current_cart.cart) invoice_1 = TestingInvoiceController.for_cart(current_cart.cart)
# TODO: test partially paid invoice cannot be void until payments # TODO: test partially paid invoice cannot be void until payments
# are refunded # are refunded

View file

@ -1,7 +1,7 @@
import pytz import pytz
from controller_helpers import TestingCartController from controller_helpers import TestingCartController
from registrasion.controllers.invoice import InvoiceController from controller_helpers import TestingInvoiceController
from test_cart import RegistrationCartTestCase from test_cart import RegistrationCartTestCase
@ -15,7 +15,7 @@ class RefundTestCase(RegistrationCartTestCase):
# Should be able to create an invoice after the product is added # Should be able to create an invoice after the product is added
current_cart.add_to_cart(self.PROD_1, 1) current_cart.add_to_cart(self.PROD_1, 1)
invoice = InvoiceController.for_cart(current_cart.cart) invoice = TestingInvoiceController.for_cart(current_cart.cart)
invoice.pay("A Payment!", invoice.invoice.value) invoice.pay("A Payment!", invoice.invoice.value)
self.assertFalse(invoice.invoice.void) self.assertFalse(invoice.invoice.void)

View file

@ -7,7 +7,7 @@ from django.db import IntegrityError
from registrasion import models as rego from registrasion import models as rego
from controller_helpers import TestingCartController from controller_helpers import TestingCartController
from registrasion.controllers.invoice import InvoiceController from controller_helpers import TestingInvoiceController
from test_cart import RegistrationCartTestCase from test_cart import RegistrationCartTestCase
@ -140,7 +140,7 @@ class VoucherTestCases(RegistrationCartTestCase):
current_cart.apply_voucher(voucher.code) current_cart.apply_voucher(voucher.code)
current_cart.add_to_cart(self.PROD_1, 1) current_cart.add_to_cart(self.PROD_1, 1)
inv = InvoiceController.for_cart(current_cart.cart) inv = TestingInvoiceController.for_cart(current_cart.cart)
if not inv.invoice.paid: if not inv.invoice.paid:
inv.pay("Hello!", inv.invoice.value) inv.pay("Hello!", inv.invoice.value)