Changeset - ac10ea4ee895
[Not reviewed]
1 6 1
Christopher Neugebauer - 8 years ago 2016-04-07 07:16:04
chrisjrn@gmail.com
s/cart_controller_helper/controller_helpers/
7 files changed with 14 insertions and 7 deletions:
0 comments (0 inline, 0 general)
registrasion/tests/controller_helpers.py
Show inline comments
 
file renamed from registrasion/tests/cart_controller_helper.py to registrasion/tests/controller_helpers.py
registrasion/tests/test_cart.py
Show inline comments
 
import datetime
 
import pytz
 

	
 
from decimal import Decimal
 
from django.contrib.auth.models import User
 
from django.core.exceptions import ObjectDoesNotExist
 
from django.core.exceptions import ValidationError
 
from django.test import TestCase
 

	
 
from registrasion import models as rego
 
from registrasion.controllers.product import ProductController
 

	
 
from cart_controller_helper import TestingCartController
 
from controller_helpers import TestingCartController
 
from patch_datetime import SetTimeMixin
 

	
 
UTC = pytz.timezone('UTC')
 

	
 

	
 
class RegistrationCartTestCase(SetTimeMixin, TestCase):
 

	
 
    def setUp(self):
 
        super(RegistrationCartTestCase, self).setUp()
 

	
 
    @classmethod
 
    def setUpTestData(cls):
 
        cls.USER_1 = User.objects.create_user(
 
            username='testuser',
 
            email='test@example.com',
 
            password='top_secret')
 

	
 
        cls.USER_2 = User.objects.create_user(
 
            username='testuser2',
 
            email='test2@example.com',
 
            password='top_secret')
 

	
 
        cls.RESERVATION = datetime.timedelta(hours=1)
 

	
registrasion/tests/test_ceilings.py
Show inline comments
 
import datetime
 
import pytz
 

	
 
from django.core.exceptions import ValidationError
 

	
 
from cart_controller_helper import TestingCartController
 
from controller_helpers import TestingCartController
 
from test_cart import RegistrationCartTestCase
 

	
 
from registrasion import models as rego
 

	
 
UTC = pytz.timezone('UTC')
 

	
 

	
 
class CeilingsTestCases(RegistrationCartTestCase):
 

	
 
    def test_add_to_cart_ceiling_limit(self):
 
        self.make_ceiling("Limit ceiling", limit=9)
 
        self.__add_to_cart_test()
 

	
 
    def test_add_to_cart_ceiling_category_limit(self):
 
        self.make_category_ceiling("Limit ceiling", limit=9)
 
        self.__add_to_cart_test()
 

	
 
    def __add_to_cart_test(self):
 

	
 
        current_cart = TestingCartController.for_user(self.USER_1)
 

	
 
        # User should not be able to add 10 of PROD_1 to the current cart
 
        # because it is affected by limit_ceiling
 
        with self.assertRaises(ValidationError):
registrasion/tests/test_enabling_condition.py
Show inline comments
 
import pytz
 

	
 
from django.core.exceptions import ValidationError
 

	
 
from registrasion import models as rego
 
from registrasion.controllers.category import CategoryController
 
from cart_controller_helper import TestingCartController
 
from controller_helpers import TestingCartController
 
from registrasion.controllers.product import ProductController
 

	
 
from test_cart import RegistrationCartTestCase
 

	
 
UTC = pytz.timezone('UTC')
 

	
 

	
 
class EnablingConditionTestCases(RegistrationCartTestCase):
 

	
 
    @classmethod
 
    def add_product_enabling_condition(cls, mandatory=False):
 
        ''' Adds a product enabling condition: adding PROD_1 to a cart is
 
        predicated on adding PROD_2 beforehand. '''
 
        enabling_condition = rego.ProductEnablingCondition.objects.create(
 
            description="Product condition",
 
            mandatory=mandatory,
 
        )
 
        enabling_condition.save()
 
        enabling_condition.products.add(cls.PROD_1)
 
        enabling_condition.enabling_products.add(cls.PROD_2)
 
        enabling_condition.save()
 

	
 
    @classmethod
 
    def add_product_enabling_condition_on_category(cls, mandatory=False):
registrasion/tests/test_invoice.py
Show inline comments
 
import datetime
 
import pytz
 

	
 
from decimal import Decimal
 
from django.core.exceptions import ValidationError
 

	
 
from registrasion import models as rego
 
from cart_controller_helper import TestingCartController
 
from controller_helpers import TestingCartController
 
from registrasion.controllers.invoice import InvoiceController
 

	
 
from test_cart import RegistrationCartTestCase
 

	
 
UTC = pytz.timezone('UTC')
 

	
 

	
 
class InvoiceTestCase(RegistrationCartTestCase):
 

	
 
    def test_create_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 = InvoiceController.for_cart(current_cart.cart)
 
        # That invoice should have a single line item
 
        line_items = rego.LineItem.objects.filter(invoice=invoice_1.invoice)
 
        self.assertEqual(1, len(line_items))
 
        # That invoice should have a value equal to cost of PROD_1
 
        self.assertEqual(self.PROD_1.price, invoice_1.invoice.value)
 

	
 
        # Adding item to cart should produce a new invoice
 
        current_cart.add_to_cart(self.PROD_2, 1)
 
        invoice_2 = InvoiceController.for_cart(current_cart.cart)
...
 
@@ -176,25 +176,32 @@ class InvoiceTestCase(RegistrationCartTestCase):
 
        # 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)
 

	
 
        invoice_1.void()
 

	
 
        with self.assertRaises(ValidationError):
 
            invoice_1.pay("Reference", invoice_1.invoice.value)
 

	
 
    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_1 = InvoiceController.for_cart(current_cart.cart)
 

	
 
        invoice_1.pay("Reference", invoice_1.invoice.value)
 

	
 
        with self.assertRaises(ValidationError):
 
            invoice_1.void()
 

	
 
    def test_cannot_generate_blank_invoice(self):
 
        current_cart = TestingCartController.for_user(self.USER_1)
 
        with self.assertRaises(ValidationError):
 
            InvoiceController.for_cart(current_cart.cart)
 
            invoice_1 = InvoiceController.for_cart(current_cart.cart)
 

	
 
    # TODO: test partially paid invoice cannot be void until payments
 
    # are refunded
 

	
 
    # TODO: test overpaid invoice results in credit note
 

	
 
    # TODO: test credit note generation more generally 
registrasion/tests/test_refund.py
Show inline comments
 
import pytz
 

	
 
from cart_controller_helper import TestingCartController
 
from controller_helpers import TestingCartController
 
from registrasion.controllers.invoice import InvoiceController
 

	
 
from test_cart import RegistrationCartTestCase
 

	
 
UTC = pytz.timezone('UTC')
 

	
 

	
 
class RefundTestCase(RegistrationCartTestCase):
 

	
 
    def test_refund_marks_void_and_unpaid_and_cart_released(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 = InvoiceController.for_cart(current_cart.cart)
 

	
 
        invoice.pay("A Payment!", invoice.invoice.value)
 
        self.assertFalse(invoice.invoice.void)
 
        self.assertTrue(invoice.invoice.paid)
 
        self.assertFalse(invoice.invoice.cart.released)
 

	
 
        invoice.refund("A Refund!", invoice.invoice.value)
 
        self.assertTrue(invoice.invoice.void)
 
        self.assertFalse(invoice.invoice.paid)
registrasion/tests/test_voucher.py
Show inline comments
 
import datetime
 
import pytz
 

	
 
from decimal import Decimal
 
from django.core.exceptions import ValidationError
 
from django.db import IntegrityError
 

	
 
from registrasion import models as rego
 
from cart_controller_helper import TestingCartController
 
from controller_helpers import TestingCartController
 
from registrasion.controllers.invoice import InvoiceController
 

	
 
from test_cart import RegistrationCartTestCase
 

	
 
UTC = pytz.timezone('UTC')
 

	
 

	
 
class VoucherTestCases(RegistrationCartTestCase):
 

	
 
    def test_apply_voucher(self):
 
        voucher = self.new_voucher()
 

	
 
        self.set_time(datetime.datetime(2015, 01, 01, tzinfo=UTC))
 

	
 
        cart_1 = TestingCartController.for_user(self.USER_1)
 
        cart_1.apply_voucher(voucher.code)
 
        self.assertIn(voucher, cart_1.cart.vouchers.all())
 

	
 
        # Second user should not be able to apply this voucher (it's exhausted)
 
        cart_2 = TestingCartController.for_user(self.USER_2)
 
        with self.assertRaises(ValidationError):
 
            cart_2.apply_voucher(voucher.code)
 

	
 
        # After the reservation duration
0 comments (0 inline, 0 general)