Removes set_quantity and add_to_cart from CartController, and factors it into a test controller for testing
This commit is contained in:
parent
312fffd137
commit
eab1deff77
9 changed files with 125 additions and 119 deletions
|
@ -21,8 +21,8 @@ class CartController(object):
|
||||||
def __init__(self, cart):
|
def __init__(self, cart):
|
||||||
self.cart = cart
|
self.cart = cart
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def for_user(user):
|
def for_user(cls, user):
|
||||||
''' Returns the user's current cart, or creates a new cart
|
''' Returns the user's current cart, or creates a new cart
|
||||||
if there isn't one ready yet. '''
|
if there isn't one ready yet. '''
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ class CartController(object):
|
||||||
reservation_duration=datetime.timedelta(),
|
reservation_duration=datetime.timedelta(),
|
||||||
)
|
)
|
||||||
existing.save()
|
existing.save()
|
||||||
return CartController(existing)
|
return cls(existing)
|
||||||
|
|
||||||
def extend_reservation(self):
|
def extend_reservation(self):
|
||||||
''' Updates the cart's time last updated value, which is used to
|
''' Updates the cart's time last updated value, which is used to
|
||||||
|
@ -163,25 +163,6 @@ class CartController(object):
|
||||||
# TODO: batch errors
|
# TODO: batch errors
|
||||||
raise ValidationError("An enabling condition failed")
|
raise ValidationError("An enabling condition failed")
|
||||||
|
|
||||||
def set_quantity(self, product, quantity, batched=False):
|
|
||||||
''' Sets the _quantity_ of the given _product_ in the cart to the given
|
|
||||||
_quantity_. '''
|
|
||||||
|
|
||||||
self.set_quantities(((product, quantity),))
|
|
||||||
|
|
||||||
def add_to_cart(self, product, quantity):
|
|
||||||
''' Adds _quantity_ of the given _product_ to the cart. Raises
|
|
||||||
ValidationError if constraints are violated.'''
|
|
||||||
|
|
||||||
try:
|
|
||||||
product_item = rego.ProductItem.objects.get(
|
|
||||||
cart=self.cart,
|
|
||||||
product=product)
|
|
||||||
old_quantity = product_item.quantity
|
|
||||||
except ObjectDoesNotExist:
|
|
||||||
old_quantity = 0
|
|
||||||
self.set_quantity(product, old_quantity + quantity)
|
|
||||||
|
|
||||||
def apply_voucher(self, voucher_code):
|
def apply_voucher(self, voucher_code):
|
||||||
''' Applies the voucher with the given code to this cart. '''
|
''' Applies the voucher with the given code to this cart. '''
|
||||||
|
|
||||||
|
|
25
registrasion/tests/cart_controller_helper.py
Normal file
25
registrasion/tests/cart_controller_helper.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
from registrasion.controllers.cart import CartController
|
||||||
|
from registrasion import models as rego
|
||||||
|
|
||||||
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
|
|
||||||
|
class TestingCartController(CartController):
|
||||||
|
|
||||||
|
def set_quantity(self, product, quantity, batched=False):
|
||||||
|
''' Sets the _quantity_ of the given _product_ in the cart to the given
|
||||||
|
_quantity_. '''
|
||||||
|
|
||||||
|
self.set_quantities(((product, quantity),))
|
||||||
|
|
||||||
|
def add_to_cart(self, product, quantity):
|
||||||
|
''' Adds _quantity_ of the given _product_ to the cart. Raises
|
||||||
|
ValidationError if constraints are violated.'''
|
||||||
|
|
||||||
|
try:
|
||||||
|
product_item = rego.ProductItem.objects.get(
|
||||||
|
cart=self.cart,
|
||||||
|
product=product)
|
||||||
|
old_quantity = product_item.quantity
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
old_quantity = 0
|
||||||
|
self.set_quantity(product, old_quantity + quantity)
|
|
@ -8,9 +8,9 @@ from django.core.exceptions import ValidationError
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from registrasion import models as rego
|
from registrasion import models as rego
|
||||||
from registrasion.controllers.cart import CartController
|
|
||||||
from registrasion.controllers.product import ProductController
|
from registrasion.controllers.product import ProductController
|
||||||
|
|
||||||
|
from cart_controller_helper import TestingCartController
|
||||||
from patch_datetime import SetTimeMixin
|
from patch_datetime import SetTimeMixin
|
||||||
|
|
||||||
UTC = pytz.timezone('UTC')
|
UTC = pytz.timezone('UTC')
|
||||||
|
@ -73,11 +73,11 @@ class RegistrationCartTestCase(SetTimeMixin, TestCase):
|
||||||
cls.PROD_4.save()
|
cls.PROD_4.save()
|
||||||
|
|
||||||
# Burn through some carts -- this made some past EC tests fail
|
# Burn through some carts -- this made some past EC tests fail
|
||||||
current_cart = CartController.for_user(cls.USER_1)
|
current_cart = TestingCartController.for_user(cls.USER_1)
|
||||||
current_cart.cart.active = False
|
current_cart.cart.active = False
|
||||||
current_cart.cart.save()
|
current_cart.cart.save()
|
||||||
|
|
||||||
current_cart = CartController.for_user(cls.USER_2)
|
current_cart = TestingCartController.for_user(cls.USER_2)
|
||||||
current_cart.cart.active = False
|
current_cart.cart.active = False
|
||||||
current_cart.cart.save()
|
current_cart.cart.save()
|
||||||
|
|
||||||
|
@ -129,21 +129,21 @@ class RegistrationCartTestCase(SetTimeMixin, TestCase):
|
||||||
class BasicCartTests(RegistrationCartTestCase):
|
class BasicCartTests(RegistrationCartTestCase):
|
||||||
|
|
||||||
def test_get_cart(self):
|
def test_get_cart(self):
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
|
|
||||||
current_cart.cart.active = False
|
current_cart.cart.active = False
|
||||||
current_cart.cart.save()
|
current_cart.cart.save()
|
||||||
|
|
||||||
old_cart = current_cart
|
old_cart = current_cart
|
||||||
|
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
self.assertNotEqual(old_cart.cart, current_cart.cart)
|
self.assertNotEqual(old_cart.cart, current_cart.cart)
|
||||||
|
|
||||||
current_cart2 = CartController.for_user(self.USER_1)
|
current_cart2 = TestingCartController.for_user(self.USER_1)
|
||||||
self.assertEqual(current_cart.cart, current_cart2.cart)
|
self.assertEqual(current_cart.cart, current_cart2.cart)
|
||||||
|
|
||||||
def test_add_to_cart_collapses_product_items(self):
|
def test_add_to_cart_collapses_product_items(self):
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
|
|
||||||
# Add a product twice
|
# Add a product twice
|
||||||
current_cart.add_to_cart(self.PROD_1, 1)
|
current_cart.add_to_cart(self.PROD_1, 1)
|
||||||
|
@ -158,7 +158,7 @@ class BasicCartTests(RegistrationCartTestCase):
|
||||||
self.assertEquals(2, item.quantity)
|
self.assertEquals(2, item.quantity)
|
||||||
|
|
||||||
def test_set_quantity(self):
|
def test_set_quantity(self):
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
|
|
||||||
def get_item():
|
def get_item():
|
||||||
return rego.ProductItem.objects.get(
|
return rego.ProductItem.objects.get(
|
||||||
|
@ -190,7 +190,7 @@ class BasicCartTests(RegistrationCartTestCase):
|
||||||
self.assertEqual(2, get_item().quantity)
|
self.assertEqual(2, get_item().quantity)
|
||||||
|
|
||||||
def test_add_to_cart_product_per_user_limit(self):
|
def test_add_to_cart_product_per_user_limit(self):
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
|
|
||||||
# User should be able to add 1 of PROD_1 to the current cart.
|
# User should be able to add 1 of PROD_1 to the current cart.
|
||||||
current_cart.add_to_cart(self.PROD_1, 1)
|
current_cart.add_to_cart(self.PROD_1, 1)
|
||||||
|
@ -206,14 +206,14 @@ class BasicCartTests(RegistrationCartTestCase):
|
||||||
current_cart.cart.active = False
|
current_cart.cart.active = False
|
||||||
current_cart.cart.save()
|
current_cart.cart.save()
|
||||||
|
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
# User should not be able to add 10 of PROD_1 to the current cart now,
|
# User should not be able to add 10 of PROD_1 to the current cart now,
|
||||||
# even though it's a new cart.
|
# even though it's a new cart.
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
current_cart.add_to_cart(self.PROD_1, 10)
|
current_cart.add_to_cart(self.PROD_1, 10)
|
||||||
|
|
||||||
# Second user should not be affected by first user's limits
|
# Second user should not be affected by first user's limits
|
||||||
second_user_cart = CartController.for_user(self.USER_2)
|
second_user_cart = TestingCartController.for_user(self.USER_2)
|
||||||
second_user_cart.add_to_cart(self.PROD_1, 10)
|
second_user_cart.add_to_cart(self.PROD_1, 10)
|
||||||
|
|
||||||
def set_limits(self):
|
def set_limits(self):
|
||||||
|
@ -230,7 +230,7 @@ class BasicCartTests(RegistrationCartTestCase):
|
||||||
def test_per_user_product_limit_ignored_if_blank(self):
|
def test_per_user_product_limit_ignored_if_blank(self):
|
||||||
self.set_limits()
|
self.set_limits()
|
||||||
|
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
# There is no product limit on PROD_2, and there is no cat limit
|
# There is no product limit on PROD_2, and there is no cat limit
|
||||||
current_cart.add_to_cart(self.PROD_2, 1)
|
current_cart.add_to_cart(self.PROD_2, 1)
|
||||||
# There is no product limit on PROD_3, but there is a cat limit
|
# There is no product limit on PROD_3, but there is a cat limit
|
||||||
|
@ -238,7 +238,7 @@ class BasicCartTests(RegistrationCartTestCase):
|
||||||
|
|
||||||
def test_per_user_category_limit_ignored_if_blank(self):
|
def test_per_user_category_limit_ignored_if_blank(self):
|
||||||
self.set_limits()
|
self.set_limits()
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
# There is no product limit on PROD_2, and there is no cat limit
|
# There is no product limit on PROD_2, and there is no cat limit
|
||||||
current_cart.add_to_cart(self.PROD_2, 1)
|
current_cart.add_to_cart(self.PROD_2, 1)
|
||||||
# There is no cat limit on PROD_1, but there is a prod limit
|
# There is no cat limit on PROD_1, but there is a prod limit
|
||||||
|
@ -247,7 +247,7 @@ class BasicCartTests(RegistrationCartTestCase):
|
||||||
def test_per_user_category_limit_only(self):
|
def test_per_user_category_limit_only(self):
|
||||||
self.set_limits()
|
self.set_limits()
|
||||||
|
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
|
|
||||||
# Cannot add to cart if category limit is filled by one product.
|
# Cannot add to cart if category limit is filled by one product.
|
||||||
current_cart.set_quantity(self.PROD_3, 10)
|
current_cart.set_quantity(self.PROD_3, 10)
|
||||||
|
@ -264,7 +264,7 @@ class BasicCartTests(RegistrationCartTestCase):
|
||||||
current_cart.cart.active = False
|
current_cart.cart.active = False
|
||||||
current_cart.cart.save()
|
current_cart.cart.save()
|
||||||
|
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
# The category limit should extend across carts
|
# The category limit should extend across carts
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
current_cart.add_to_cart(self.PROD_3, 10)
|
current_cart.add_to_cart(self.PROD_3, 10)
|
||||||
|
@ -272,7 +272,7 @@ class BasicCartTests(RegistrationCartTestCase):
|
||||||
def test_per_user_category_and_product_limits(self):
|
def test_per_user_category_and_product_limits(self):
|
||||||
self.set_limits()
|
self.set_limits()
|
||||||
|
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
|
|
||||||
# Hit both the product and category edges:
|
# Hit both the product and category edges:
|
||||||
current_cart.set_quantity(self.PROD_3, 4)
|
current_cart.set_quantity(self.PROD_3, 4)
|
||||||
|
@ -290,7 +290,7 @@ class BasicCartTests(RegistrationCartTestCase):
|
||||||
current_cart.cart.active = False
|
current_cart.cart.active = False
|
||||||
current_cart.cart.save()
|
current_cart.cart.save()
|
||||||
|
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
current_cart.set_quantity(self.PROD_3, 4)
|
current_cart.set_quantity(self.PROD_3, 4)
|
||||||
|
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
|
@ -308,7 +308,7 @@ class BasicCartTests(RegistrationCartTestCase):
|
||||||
products=[self.PROD_2, self.PROD_3, self.PROD_4],
|
products=[self.PROD_2, self.PROD_3, self.PROD_4],
|
||||||
)
|
)
|
||||||
|
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
prods = get_prods()
|
prods = get_prods()
|
||||||
self.assertTrue(item in prods)
|
self.assertTrue(item in prods)
|
||||||
current_cart.add_to_cart(item, quantity)
|
current_cart.add_to_cart(item, quantity)
|
||||||
|
@ -317,7 +317,7 @@ class BasicCartTests(RegistrationCartTestCase):
|
||||||
current_cart.cart.active = False
|
current_cart.cart.active = False
|
||||||
current_cart.cart.save()
|
current_cart.cart.save()
|
||||||
|
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
|
|
||||||
prods = get_prods()
|
prods = get_prods()
|
||||||
self.assertTrue(item not in prods)
|
self.assertTrue(item not in prods)
|
||||||
|
|
|
@ -3,7 +3,7 @@ import pytz
|
||||||
|
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
|
||||||
from registrasion.controllers.cart import CartController
|
from cart_controller_helper import TestingCartController
|
||||||
|
|
||||||
from test_cart import RegistrationCartTestCase
|
from test_cart import RegistrationCartTestCase
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ class CeilingsTestCases(RegistrationCartTestCase):
|
||||||
|
|
||||||
def __add_to_cart_test(self):
|
def __add_to_cart_test(self):
|
||||||
|
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
|
|
||||||
# User should not be able to add 10 of PROD_1 to the current cart
|
# User should not be able to add 10 of PROD_1 to the current cart
|
||||||
# because it is affected by limit_ceiling
|
# because it is affected by limit_ceiling
|
||||||
|
@ -46,7 +46,7 @@ class CeilingsTestCases(RegistrationCartTestCase):
|
||||||
start_time=datetime.datetime(2015, 01, 01, tzinfo=UTC),
|
start_time=datetime.datetime(2015, 01, 01, tzinfo=UTC),
|
||||||
end_time=datetime.datetime(2015, 02, 01, tzinfo=UTC))
|
end_time=datetime.datetime(2015, 02, 01, tzinfo=UTC))
|
||||||
|
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
|
|
||||||
# User should not be able to add whilst we're before start_time
|
# User should not be able to add whilst we're before start_time
|
||||||
self.set_time(datetime.datetime(2014, 01, 01, tzinfo=UTC))
|
self.set_time(datetime.datetime(2014, 01, 01, tzinfo=UTC))
|
||||||
|
@ -74,8 +74,8 @@ class CeilingsTestCases(RegistrationCartTestCase):
|
||||||
|
|
||||||
self.set_time(datetime.datetime(2015, 01, 01, tzinfo=UTC))
|
self.set_time(datetime.datetime(2015, 01, 01, tzinfo=UTC))
|
||||||
|
|
||||||
first_cart = CartController.for_user(self.USER_1)
|
first_cart = TestingCartController.for_user(self.USER_1)
|
||||||
second_cart = CartController.for_user(self.USER_2)
|
second_cart = TestingCartController.for_user(self.USER_2)
|
||||||
|
|
||||||
first_cart.add_to_cart(self.PROD_1, 1)
|
first_cart.add_to_cart(self.PROD_1, 1)
|
||||||
|
|
||||||
|
@ -111,8 +111,8 @@ class CeilingsTestCases(RegistrationCartTestCase):
|
||||||
def __validation_test(self):
|
def __validation_test(self):
|
||||||
self.set_time(datetime.datetime(2015, 01, 01, tzinfo=UTC))
|
self.set_time(datetime.datetime(2015, 01, 01, tzinfo=UTC))
|
||||||
|
|
||||||
first_cart = CartController.for_user(self.USER_1)
|
first_cart = TestingCartController.for_user(self.USER_1)
|
||||||
second_cart = CartController.for_user(self.USER_2)
|
second_cart = TestingCartController.for_user(self.USER_2)
|
||||||
|
|
||||||
# Adding a valid product should validate.
|
# Adding a valid product should validate.
|
||||||
first_cart.add_to_cart(self.PROD_1, 1)
|
first_cart.add_to_cart(self.PROD_1, 1)
|
||||||
|
@ -136,13 +136,13 @@ class CeilingsTestCases(RegistrationCartTestCase):
|
||||||
def test_items_released_from_ceiling_by_refund(self):
|
def test_items_released_from_ceiling_by_refund(self):
|
||||||
self.make_ceiling("Limit ceiling", limit=1)
|
self.make_ceiling("Limit ceiling", limit=1)
|
||||||
|
|
||||||
first_cart = CartController.for_user(self.USER_1)
|
first_cart = TestingCartController.for_user(self.USER_1)
|
||||||
first_cart.add_to_cart(self.PROD_1, 1)
|
first_cart.add_to_cart(self.PROD_1, 1)
|
||||||
|
|
||||||
first_cart.cart.active = False
|
first_cart.cart.active = False
|
||||||
first_cart.cart.save()
|
first_cart.cart.save()
|
||||||
|
|
||||||
second_cart = CartController.for_user(self.USER_2)
|
second_cart = TestingCartController.for_user(self.USER_2)
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
second_cart.add_to_cart(self.PROD_1, 1)
|
second_cart.add_to_cart(self.PROD_1, 1)
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ 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 registrasion.controllers.cart import CartController
|
from cart_controller_helper import TestingCartController
|
||||||
from registrasion.controllers.invoice import InvoiceController
|
from registrasion.controllers.invoice import InvoiceController
|
||||||
|
|
||||||
from test_cart import RegistrationCartTestCase
|
from test_cart import RegistrationCartTestCase
|
||||||
|
@ -84,7 +84,7 @@ class DiscountTestCase(RegistrationCartTestCase):
|
||||||
def test_discount_is_applied(self):
|
def test_discount_is_applied(self):
|
||||||
self.add_discount_prod_1_includes_prod_2()
|
self.add_discount_prod_1_includes_prod_2()
|
||||||
|
|
||||||
cart = CartController.for_user(self.USER_1)
|
cart = TestingCartController.for_user(self.USER_1)
|
||||||
cart.add_to_cart(self.PROD_1, 1)
|
cart.add_to_cart(self.PROD_1, 1)
|
||||||
cart.add_to_cart(self.PROD_2, 1)
|
cart.add_to_cart(self.PROD_2, 1)
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ class DiscountTestCase(RegistrationCartTestCase):
|
||||||
def test_discount_is_applied_for_category(self):
|
def test_discount_is_applied_for_category(self):
|
||||||
self.add_discount_prod_1_includes_cat_2()
|
self.add_discount_prod_1_includes_cat_2()
|
||||||
|
|
||||||
cart = CartController.for_user(self.USER_1)
|
cart = TestingCartController.for_user(self.USER_1)
|
||||||
cart.add_to_cart(self.PROD_1, 1)
|
cart.add_to_cart(self.PROD_1, 1)
|
||||||
cart.add_to_cart(self.PROD_3, 1)
|
cart.add_to_cart(self.PROD_3, 1)
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ class DiscountTestCase(RegistrationCartTestCase):
|
||||||
def test_discount_does_not_apply_if_not_met(self):
|
def test_discount_does_not_apply_if_not_met(self):
|
||||||
self.add_discount_prod_1_includes_prod_2()
|
self.add_discount_prod_1_includes_prod_2()
|
||||||
|
|
||||||
cart = CartController.for_user(self.USER_1)
|
cart = TestingCartController.for_user(self.USER_1)
|
||||||
cart.add_to_cart(self.PROD_2, 1)
|
cart.add_to_cart(self.PROD_2, 1)
|
||||||
|
|
||||||
# No discount should be applied as the condition is not met
|
# No discount should be applied as the condition is not met
|
||||||
|
@ -113,7 +113,7 @@ class DiscountTestCase(RegistrationCartTestCase):
|
||||||
def test_discount_applied_out_of_order(self):
|
def test_discount_applied_out_of_order(self):
|
||||||
self.add_discount_prod_1_includes_prod_2()
|
self.add_discount_prod_1_includes_prod_2()
|
||||||
|
|
||||||
cart = CartController.for_user(self.USER_1)
|
cart = TestingCartController.for_user(self.USER_1)
|
||||||
cart.add_to_cart(self.PROD_2, 1)
|
cart.add_to_cart(self.PROD_2, 1)
|
||||||
cart.add_to_cart(self.PROD_1, 1)
|
cart.add_to_cart(self.PROD_1, 1)
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ class DiscountTestCase(RegistrationCartTestCase):
|
||||||
def test_discounts_collapse(self):
|
def test_discounts_collapse(self):
|
||||||
self.add_discount_prod_1_includes_prod_2()
|
self.add_discount_prod_1_includes_prod_2()
|
||||||
|
|
||||||
cart = CartController.for_user(self.USER_1)
|
cart = TestingCartController.for_user(self.USER_1)
|
||||||
cart.add_to_cart(self.PROD_1, 1)
|
cart.add_to_cart(self.PROD_1, 1)
|
||||||
cart.add_to_cart(self.PROD_2, 1)
|
cart.add_to_cart(self.PROD_2, 1)
|
||||||
cart.add_to_cart(self.PROD_2, 1)
|
cart.add_to_cart(self.PROD_2, 1)
|
||||||
|
@ -134,7 +134,7 @@ class DiscountTestCase(RegistrationCartTestCase):
|
||||||
def test_discounts_respect_quantity(self):
|
def test_discounts_respect_quantity(self):
|
||||||
self.add_discount_prod_1_includes_prod_2()
|
self.add_discount_prod_1_includes_prod_2()
|
||||||
|
|
||||||
cart = CartController.for_user(self.USER_1)
|
cart = TestingCartController.for_user(self.USER_1)
|
||||||
cart.add_to_cart(self.PROD_1, 1)
|
cart.add_to_cart(self.PROD_1, 1)
|
||||||
cart.add_to_cart(self.PROD_2, 3)
|
cart.add_to_cart(self.PROD_2, 3)
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ class DiscountTestCase(RegistrationCartTestCase):
|
||||||
discount_full = self.add_discount_prod_1_includes_prod_2()
|
discount_full = self.add_discount_prod_1_includes_prod_2()
|
||||||
discount_half = self.add_discount_prod_1_includes_prod_2(Decimal(50))
|
discount_half = self.add_discount_prod_1_includes_prod_2(Decimal(50))
|
||||||
|
|
||||||
cart = CartController.for_user(self.USER_1)
|
cart = TestingCartController.for_user(self.USER_1)
|
||||||
cart.add_to_cart(self.PROD_1, 1)
|
cart.add_to_cart(self.PROD_1, 1)
|
||||||
cart.add_to_cart(self.PROD_2, 3)
|
cart.add_to_cart(self.PROD_2, 3)
|
||||||
|
|
||||||
|
@ -166,13 +166,13 @@ class DiscountTestCase(RegistrationCartTestCase):
|
||||||
self.add_discount_prod_1_includes_prod_2()
|
self.add_discount_prod_1_includes_prod_2()
|
||||||
|
|
||||||
# Enable the discount during the first cart.
|
# Enable the discount during the first cart.
|
||||||
cart = CartController.for_user(self.USER_1)
|
cart = TestingCartController.for_user(self.USER_1)
|
||||||
cart.add_to_cart(self.PROD_1, 1)
|
cart.add_to_cart(self.PROD_1, 1)
|
||||||
cart.cart.active = False
|
cart.cart.active = False
|
||||||
cart.cart.save()
|
cart.cart.save()
|
||||||
|
|
||||||
# Use the discount in the second cart
|
# Use the discount in the second cart
|
||||||
cart = CartController.for_user(self.USER_1)
|
cart = TestingCartController.for_user(self.USER_1)
|
||||||
cart.add_to_cart(self.PROD_2, 1)
|
cart.add_to_cart(self.PROD_2, 1)
|
||||||
|
|
||||||
# The discount should be applied.
|
# The discount should be applied.
|
||||||
|
@ -182,7 +182,7 @@ class DiscountTestCase(RegistrationCartTestCase):
|
||||||
|
|
||||||
# The discount should respect the total quantity across all
|
# The discount should respect the total quantity across all
|
||||||
# of the user's carts.
|
# of the user's carts.
|
||||||
cart = CartController.for_user(self.USER_1)
|
cart = TestingCartController.for_user(self.USER_1)
|
||||||
cart.add_to_cart(self.PROD_2, 2)
|
cart.add_to_cart(self.PROD_2, 2)
|
||||||
|
|
||||||
# Having one item in the second cart leaves one more item where
|
# Having one item in the second cart leaves one more item where
|
||||||
|
@ -193,7 +193,7 @@ class DiscountTestCase(RegistrationCartTestCase):
|
||||||
|
|
||||||
def test_discount_applies_only_once_enabled(self):
|
def test_discount_applies_only_once_enabled(self):
|
||||||
# Enable the discount during the first cart.
|
# Enable the discount during the first cart.
|
||||||
cart = CartController.for_user(self.USER_1)
|
cart = TestingCartController.for_user(self.USER_1)
|
||||||
cart.add_to_cart(self.PROD_1, 1)
|
cart.add_to_cart(self.PROD_1, 1)
|
||||||
# This would exhaust discount if present
|
# This would exhaust discount if present
|
||||||
cart.add_to_cart(self.PROD_2, 2)
|
cart.add_to_cart(self.PROD_2, 2)
|
||||||
|
@ -201,7 +201,7 @@ class DiscountTestCase(RegistrationCartTestCase):
|
||||||
cart.cart.save()
|
cart.cart.save()
|
||||||
|
|
||||||
self.add_discount_prod_1_includes_prod_2()
|
self.add_discount_prod_1_includes_prod_2()
|
||||||
cart = CartController.for_user(self.USER_1)
|
cart = TestingCartController.for_user(self.USER_1)
|
||||||
cart.add_to_cart(self.PROD_2, 2)
|
cart.add_to_cart(self.PROD_2, 2)
|
||||||
|
|
||||||
discount_items = list(cart.cart.discountitem_set.all())
|
discount_items = list(cart.cart.discountitem_set.all())
|
||||||
|
@ -209,7 +209,7 @@ class DiscountTestCase(RegistrationCartTestCase):
|
||||||
|
|
||||||
def test_category_discount_applies_once_per_category(self):
|
def test_category_discount_applies_once_per_category(self):
|
||||||
self.add_discount_prod_1_includes_cat_2(quantity=1)
|
self.add_discount_prod_1_includes_cat_2(quantity=1)
|
||||||
cart = CartController.for_user(self.USER_1)
|
cart = TestingCartController.for_user(self.USER_1)
|
||||||
cart.add_to_cart(self.PROD_1, 1)
|
cart.add_to_cart(self.PROD_1, 1)
|
||||||
|
|
||||||
# Add two items from category 2
|
# Add two items from category 2
|
||||||
|
@ -223,7 +223,7 @@ class DiscountTestCase(RegistrationCartTestCase):
|
||||||
|
|
||||||
def test_category_discount_applies_to_highest_value(self):
|
def test_category_discount_applies_to_highest_value(self):
|
||||||
self.add_discount_prod_1_includes_cat_2(quantity=1)
|
self.add_discount_prod_1_includes_cat_2(quantity=1)
|
||||||
cart = CartController.for_user(self.USER_1)
|
cart = TestingCartController.for_user(self.USER_1)
|
||||||
cart.add_to_cart(self.PROD_1, 1)
|
cart.add_to_cart(self.PROD_1, 1)
|
||||||
|
|
||||||
# Add two items from category 2, add the less expensive one first
|
# Add two items from category 2, add the less expensive one first
|
||||||
|
@ -241,7 +241,7 @@ class DiscountTestCase(RegistrationCartTestCase):
|
||||||
# Both users should be able to apply the same discount
|
# Both users should be able to apply the same discount
|
||||||
# in the same way
|
# in the same way
|
||||||
for user in (self.USER_1, self.USER_2):
|
for user in (self.USER_1, self.USER_2):
|
||||||
cart = CartController.for_user(user)
|
cart = TestingCartController.for_user(user)
|
||||||
cart.add_to_cart(self.PROD_1, 1) # Enable the discount
|
cart.add_to_cart(self.PROD_1, 1) # Enable the discount
|
||||||
cart.add_to_cart(self.PROD_3, 1)
|
cart.add_to_cart(self.PROD_3, 1)
|
||||||
|
|
||||||
|
@ -270,7 +270,7 @@ class DiscountTestCase(RegistrationCartTestCase):
|
||||||
def test_category_discount_appears_once_if_met_twice(self):
|
def test_category_discount_appears_once_if_met_twice(self):
|
||||||
self.add_discount_prod_1_includes_cat_2(quantity=1)
|
self.add_discount_prod_1_includes_cat_2(quantity=1)
|
||||||
|
|
||||||
cart = CartController.for_user(self.USER_1)
|
cart = TestingCartController.for_user(self.USER_1)
|
||||||
cart.add_to_cart(self.PROD_1, 1) # Enable the discount
|
cart.add_to_cart(self.PROD_1, 1) # Enable the discount
|
||||||
|
|
||||||
discounts = discount.available_discounts(
|
discounts = discount.available_discounts(
|
||||||
|
@ -283,7 +283,7 @@ class DiscountTestCase(RegistrationCartTestCase):
|
||||||
def test_category_discount_appears_with_category(self):
|
def test_category_discount_appears_with_category(self):
|
||||||
self.add_discount_prod_1_includes_cat_2(quantity=1)
|
self.add_discount_prod_1_includes_cat_2(quantity=1)
|
||||||
|
|
||||||
cart = CartController.for_user(self.USER_1)
|
cart = TestingCartController.for_user(self.USER_1)
|
||||||
cart.add_to_cart(self.PROD_1, 1) # Enable the discount
|
cart.add_to_cart(self.PROD_1, 1) # Enable the discount
|
||||||
|
|
||||||
discounts = discount.available_discounts(self.USER_1, [self.CAT_2], [])
|
discounts = discount.available_discounts(self.USER_1, [self.CAT_2], [])
|
||||||
|
@ -292,7 +292,7 @@ class DiscountTestCase(RegistrationCartTestCase):
|
||||||
def test_category_discount_appears_with_product(self):
|
def test_category_discount_appears_with_product(self):
|
||||||
self.add_discount_prod_1_includes_cat_2(quantity=1)
|
self.add_discount_prod_1_includes_cat_2(quantity=1)
|
||||||
|
|
||||||
cart = CartController.for_user(self.USER_1)
|
cart = TestingCartController.for_user(self.USER_1)
|
||||||
cart.add_to_cart(self.PROD_1, 1) # Enable the discount
|
cart.add_to_cart(self.PROD_1, 1) # Enable the discount
|
||||||
|
|
||||||
discounts = discount.available_discounts(
|
discounts = discount.available_discounts(
|
||||||
|
@ -305,7 +305,7 @@ class DiscountTestCase(RegistrationCartTestCase):
|
||||||
def test_category_discount_appears_once_with_two_valid_product(self):
|
def test_category_discount_appears_once_with_two_valid_product(self):
|
||||||
self.add_discount_prod_1_includes_cat_2(quantity=1)
|
self.add_discount_prod_1_includes_cat_2(quantity=1)
|
||||||
|
|
||||||
cart = CartController.for_user(self.USER_1)
|
cart = TestingCartController.for_user(self.USER_1)
|
||||||
cart.add_to_cart(self.PROD_1, 1) # Enable the discount
|
cart.add_to_cart(self.PROD_1, 1) # Enable the discount
|
||||||
|
|
||||||
discounts = discount.available_discounts(
|
discounts = discount.available_discounts(
|
||||||
|
@ -318,7 +318,7 @@ class DiscountTestCase(RegistrationCartTestCase):
|
||||||
def test_product_discount_appears_with_product(self):
|
def test_product_discount_appears_with_product(self):
|
||||||
self.add_discount_prod_1_includes_prod_2(quantity=1)
|
self.add_discount_prod_1_includes_prod_2(quantity=1)
|
||||||
|
|
||||||
cart = CartController.for_user(self.USER_1)
|
cart = TestingCartController.for_user(self.USER_1)
|
||||||
cart.add_to_cart(self.PROD_1, 1) # Enable the discount
|
cart.add_to_cart(self.PROD_1, 1) # Enable the discount
|
||||||
|
|
||||||
discounts = discount.available_discounts(
|
discounts = discount.available_discounts(
|
||||||
|
@ -331,7 +331,7 @@ class DiscountTestCase(RegistrationCartTestCase):
|
||||||
def test_product_discount_does_not_appear_with_category(self):
|
def test_product_discount_does_not_appear_with_category(self):
|
||||||
self.add_discount_prod_1_includes_prod_2(quantity=1)
|
self.add_discount_prod_1_includes_prod_2(quantity=1)
|
||||||
|
|
||||||
cart = CartController.for_user(self.USER_1)
|
cart = TestingCartController.for_user(self.USER_1)
|
||||||
cart.add_to_cart(self.PROD_1, 1) # Enable the discount
|
cart.add_to_cart(self.PROD_1, 1) # Enable the discount
|
||||||
|
|
||||||
discounts = discount.available_discounts(self.USER_1, [self.CAT_1], [])
|
discounts = discount.available_discounts(self.USER_1, [self.CAT_1], [])
|
||||||
|
@ -340,7 +340,7 @@ class DiscountTestCase(RegistrationCartTestCase):
|
||||||
def test_discount_quantity_is_correct_before_first_purchase(self):
|
def test_discount_quantity_is_correct_before_first_purchase(self):
|
||||||
self.add_discount_prod_1_includes_cat_2(quantity=2)
|
self.add_discount_prod_1_includes_cat_2(quantity=2)
|
||||||
|
|
||||||
cart = CartController.for_user(self.USER_1)
|
cart = TestingCartController.for_user(self.USER_1)
|
||||||
cart.add_to_cart(self.PROD_1, 1) # Enable the discount
|
cart.add_to_cart(self.PROD_1, 1) # Enable the discount
|
||||||
cart.add_to_cart(self.PROD_3, 1) # Exhaust the quantity
|
cart.add_to_cart(self.PROD_3, 1) # Exhaust the quantity
|
||||||
|
|
||||||
|
@ -353,7 +353,7 @@ class DiscountTestCase(RegistrationCartTestCase):
|
||||||
def test_discount_quantity_is_correct_after_first_purchase(self):
|
def test_discount_quantity_is_correct_after_first_purchase(self):
|
||||||
self.test_discount_quantity_is_correct_before_first_purchase()
|
self.test_discount_quantity_is_correct_before_first_purchase()
|
||||||
|
|
||||||
cart = CartController.for_user(self.USER_1)
|
cart = TestingCartController.for_user(self.USER_1)
|
||||||
cart.add_to_cart(self.PROD_3, 1) # Exhaust the quantity
|
cart.add_to_cart(self.PROD_3, 1) # Exhaust the quantity
|
||||||
|
|
||||||
discounts = discount.available_discounts(self.USER_1, [self.CAT_2], [])
|
discounts = discount.available_discounts(self.USER_1, [self.CAT_2], [])
|
||||||
|
@ -369,7 +369,7 @@ class DiscountTestCase(RegistrationCartTestCase):
|
||||||
|
|
||||||
def test_product_discount_enabled_twice_appears_twice(self):
|
def test_product_discount_enabled_twice_appears_twice(self):
|
||||||
self.add_discount_prod_1_includes_prod_3_and_prod_4(quantity=2)
|
self.add_discount_prod_1_includes_prod_3_and_prod_4(quantity=2)
|
||||||
cart = CartController.for_user(self.USER_1)
|
cart = TestingCartController.for_user(self.USER_1)
|
||||||
cart.add_to_cart(self.PROD_1, 1) # Enable the discount
|
cart.add_to_cart(self.PROD_1, 1) # Enable the discount
|
||||||
discounts = discount.available_discounts(
|
discounts = discount.available_discounts(
|
||||||
self.USER_1,
|
self.USER_1,
|
||||||
|
@ -380,7 +380,7 @@ class DiscountTestCase(RegistrationCartTestCase):
|
||||||
|
|
||||||
def test_discounts_are_released_by_refunds(self):
|
def test_discounts_are_released_by_refunds(self):
|
||||||
self.add_discount_prod_1_includes_prod_2(quantity=2)
|
self.add_discount_prod_1_includes_prod_2(quantity=2)
|
||||||
cart = CartController.for_user(self.USER_1)
|
cart = TestingCartController.for_user(self.USER_1)
|
||||||
cart.add_to_cart(self.PROD_1, 1) # Enable the discount
|
cart.add_to_cart(self.PROD_1, 1) # Enable the discount
|
||||||
discounts = discount.available_discounts(
|
discounts = discount.available_discounts(
|
||||||
self.USER_1,
|
self.USER_1,
|
||||||
|
@ -392,7 +392,7 @@ class DiscountTestCase(RegistrationCartTestCase):
|
||||||
cart.cart.active = False # Keep discount enabled
|
cart.cart.active = False # Keep discount enabled
|
||||||
cart.cart.save()
|
cart.cart.save()
|
||||||
|
|
||||||
cart = CartController.for_user(self.USER_1)
|
cart = TestingCartController.for_user(self.USER_1)
|
||||||
cart.add_to_cart(self.PROD_2, 2) # The discount will be exhausted
|
cart.add_to_cart(self.PROD_2, 2) # The discount will be exhausted
|
||||||
cart.cart.active = False
|
cart.cart.active = False
|
||||||
cart.cart.save()
|
cart.cart.save()
|
||||||
|
|
|
@ -4,7 +4,7 @@ from django.core.exceptions import ValidationError
|
||||||
|
|
||||||
from registrasion import models as rego
|
from registrasion import models as rego
|
||||||
from registrasion.controllers.category import CategoryController
|
from registrasion.controllers.category import CategoryController
|
||||||
from registrasion.controllers.cart import CartController
|
from cart_controller_helper import TestingCartController
|
||||||
from registrasion.controllers.product import ProductController
|
from registrasion.controllers.product import ProductController
|
||||||
|
|
||||||
from test_cart import RegistrationCartTestCase
|
from test_cart import RegistrationCartTestCase
|
||||||
|
@ -56,7 +56,7 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
|
||||||
self.add_product_enabling_condition()
|
self.add_product_enabling_condition()
|
||||||
|
|
||||||
# Cannot buy PROD_1 without buying PROD_2
|
# Cannot buy PROD_1 without buying PROD_2
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
current_cart.add_to_cart(self.PROD_1, 1)
|
current_cart.add_to_cart(self.PROD_1, 1)
|
||||||
|
|
||||||
|
@ -66,20 +66,20 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
|
||||||
def test_product_enabled_by_product_in_previous_cart(self):
|
def test_product_enabled_by_product_in_previous_cart(self):
|
||||||
self.add_product_enabling_condition()
|
self.add_product_enabling_condition()
|
||||||
|
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
current_cart.add_to_cart(self.PROD_2, 1)
|
current_cart.add_to_cart(self.PROD_2, 1)
|
||||||
current_cart.cart.active = False
|
current_cart.cart.active = False
|
||||||
current_cart.cart.save()
|
current_cart.cart.save()
|
||||||
|
|
||||||
# Create new cart and try to add PROD_1
|
# Create new cart and try to add PROD_1
|
||||||
current_cart = CartController.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)
|
||||||
|
|
||||||
def test_product_enabling_condition_enables_category(self):
|
def test_product_enabling_condition_enables_category(self):
|
||||||
self.add_product_enabling_condition_on_category()
|
self.add_product_enabling_condition_on_category()
|
||||||
|
|
||||||
# Cannot buy PROD_1 without buying item from CAT_2
|
# Cannot buy PROD_1 without buying item from CAT_2
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
current_cart.add_to_cart(self.PROD_1, 1)
|
current_cart.add_to_cart(self.PROD_1, 1)
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
|
||||||
self.add_category_enabling_condition()
|
self.add_category_enabling_condition()
|
||||||
|
|
||||||
# Cannot buy PROD_1 without buying PROD_2
|
# Cannot buy PROD_1 without buying PROD_2
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
current_cart.add_to_cart(self.PROD_1, 1)
|
current_cart.add_to_cart(self.PROD_1, 1)
|
||||||
|
|
||||||
|
@ -101,13 +101,13 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
|
||||||
def test_product_enabled_by_category_in_previous_cart(self):
|
def test_product_enabled_by_category_in_previous_cart(self):
|
||||||
self.add_category_enabling_condition()
|
self.add_category_enabling_condition()
|
||||||
|
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
current_cart.add_to_cart(self.PROD_3, 1)
|
current_cart.add_to_cart(self.PROD_3, 1)
|
||||||
current_cart.cart.active = False
|
current_cart.cart.active = False
|
||||||
current_cart.cart.save()
|
current_cart.cart.save()
|
||||||
|
|
||||||
# Create new cart and try to add PROD_1
|
# Create new cart and try to add PROD_1
|
||||||
current_cart = CartController.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)
|
||||||
|
|
||||||
def test_multiple_non_mandatory_conditions(self):
|
def test_multiple_non_mandatory_conditions(self):
|
||||||
|
@ -115,7 +115,7 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
|
||||||
self.add_category_enabling_condition()
|
self.add_category_enabling_condition()
|
||||||
|
|
||||||
# User 1 is testing the product enabling condition
|
# User 1 is testing the product enabling condition
|
||||||
cart_1 = CartController.for_user(self.USER_1)
|
cart_1 = TestingCartController.for_user(self.USER_1)
|
||||||
# Cannot add PROD_1 until a condition is met
|
# Cannot add PROD_1 until a condition is met
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
cart_1.add_to_cart(self.PROD_1, 1)
|
cart_1.add_to_cart(self.PROD_1, 1)
|
||||||
|
@ -123,7 +123,7 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
|
||||||
cart_1.add_to_cart(self.PROD_1, 1)
|
cart_1.add_to_cart(self.PROD_1, 1)
|
||||||
|
|
||||||
# User 2 is testing the category enabling condition
|
# User 2 is testing the category enabling condition
|
||||||
cart_2 = CartController.for_user(self.USER_2)
|
cart_2 = TestingCartController.for_user(self.USER_2)
|
||||||
# Cannot add PROD_1 until a condition is met
|
# Cannot add PROD_1 until a condition is met
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
cart_2.add_to_cart(self.PROD_1, 1)
|
cart_2.add_to_cart(self.PROD_1, 1)
|
||||||
|
@ -134,7 +134,7 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
|
||||||
self.add_product_enabling_condition(mandatory=True)
|
self.add_product_enabling_condition(mandatory=True)
|
||||||
self.add_category_enabling_condition(mandatory=True)
|
self.add_category_enabling_condition(mandatory=True)
|
||||||
|
|
||||||
cart_1 = CartController.for_user(self.USER_1)
|
cart_1 = TestingCartController.for_user(self.USER_1)
|
||||||
# Cannot add PROD_1 until both conditions are met
|
# Cannot add PROD_1 until both conditions are met
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
cart_1.add_to_cart(self.PROD_1, 1)
|
cart_1.add_to_cart(self.PROD_1, 1)
|
||||||
|
@ -148,7 +148,7 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
|
||||||
self.add_product_enabling_condition(mandatory=False)
|
self.add_product_enabling_condition(mandatory=False)
|
||||||
self.add_category_enabling_condition(mandatory=True)
|
self.add_category_enabling_condition(mandatory=True)
|
||||||
|
|
||||||
cart_1 = CartController.for_user(self.USER_1)
|
cart_1 = TestingCartController.for_user(self.USER_1)
|
||||||
# Cannot add PROD_1 until both conditions are met
|
# Cannot add PROD_1 until both conditions are met
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
cart_1.add_to_cart(self.PROD_1, 1)
|
cart_1.add_to_cart(self.PROD_1, 1)
|
||||||
|
@ -199,7 +199,7 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
|
||||||
def test_available_products_on_category_works_when_condition_is_met(self):
|
def test_available_products_on_category_works_when_condition_is_met(self):
|
||||||
self.add_product_enabling_condition(mandatory=False)
|
self.add_product_enabling_condition(mandatory=False)
|
||||||
|
|
||||||
cart_1 = CartController.for_user(self.USER_1)
|
cart_1 = TestingCartController.for_user(self.USER_1)
|
||||||
cart_1.add_to_cart(self.PROD_2, 1)
|
cart_1.add_to_cart(self.PROD_2, 1)
|
||||||
|
|
||||||
prods = ProductController.available_products(
|
prods = ProductController.available_products(
|
||||||
|
@ -224,7 +224,7 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
|
||||||
def test_available_products_on_products_works_when_condition_is_met(self):
|
def test_available_products_on_products_works_when_condition_is_met(self):
|
||||||
self.add_product_enabling_condition(mandatory=False)
|
self.add_product_enabling_condition(mandatory=False)
|
||||||
|
|
||||||
cart_1 = CartController.for_user(self.USER_1)
|
cart_1 = TestingCartController.for_user(self.USER_1)
|
||||||
cart_1.add_to_cart(self.PROD_2, 1)
|
cart_1.add_to_cart(self.PROD_2, 1)
|
||||||
|
|
||||||
prods = ProductController.available_products(
|
prods = ProductController.available_products(
|
||||||
|
@ -238,13 +238,13 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
|
||||||
def test_category_enabling_condition_fails_if_cart_refunded(self):
|
def test_category_enabling_condition_fails_if_cart_refunded(self):
|
||||||
self.add_category_enabling_condition(mandatory=False)
|
self.add_category_enabling_condition(mandatory=False)
|
||||||
|
|
||||||
cart = CartController.for_user(self.USER_1)
|
cart = TestingCartController.for_user(self.USER_1)
|
||||||
cart.add_to_cart(self.PROD_3, 1)
|
cart.add_to_cart(self.PROD_3, 1)
|
||||||
|
|
||||||
cart.cart.active = False
|
cart.cart.active = False
|
||||||
cart.cart.save()
|
cart.cart.save()
|
||||||
|
|
||||||
cart_2 = CartController.for_user(self.USER_1)
|
cart_2 = TestingCartController.for_user(self.USER_1)
|
||||||
cart_2.add_to_cart(self.PROD_1, 1)
|
cart_2.add_to_cart(self.PROD_1, 1)
|
||||||
cart_2.set_quantity(self.PROD_1, 0)
|
cart_2.set_quantity(self.PROD_1, 0)
|
||||||
|
|
||||||
|
@ -257,13 +257,13 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
|
||||||
def test_product_enabling_condition_fails_if_cart_refunded(self):
|
def test_product_enabling_condition_fails_if_cart_refunded(self):
|
||||||
self.add_product_enabling_condition(mandatory=False)
|
self.add_product_enabling_condition(mandatory=False)
|
||||||
|
|
||||||
cart = CartController.for_user(self.USER_1)
|
cart = TestingCartController.for_user(self.USER_1)
|
||||||
cart.add_to_cart(self.PROD_2, 1)
|
cart.add_to_cart(self.PROD_2, 1)
|
||||||
|
|
||||||
cart.cart.active = False
|
cart.cart.active = False
|
||||||
cart.cart.save()
|
cart.cart.save()
|
||||||
|
|
||||||
cart_2 = CartController.for_user(self.USER_1)
|
cart_2 = TestingCartController.for_user(self.USER_1)
|
||||||
cart_2.add_to_cart(self.PROD_1, 1)
|
cart_2.add_to_cart(self.PROD_1, 1)
|
||||||
cart_2.set_quantity(self.PROD_1, 0)
|
cart_2.set_quantity(self.PROD_1, 0)
|
||||||
|
|
||||||
|
@ -276,7 +276,7 @@ class EnablingConditionTestCases(RegistrationCartTestCase):
|
||||||
def test_available_categories(self):
|
def test_available_categories(self):
|
||||||
self.add_product_enabling_condition_on_category(mandatory=False)
|
self.add_product_enabling_condition_on_category(mandatory=False)
|
||||||
|
|
||||||
cart_1 = CartController.for_user(self.USER_1)
|
cart_1 = TestingCartController.for_user(self.USER_1)
|
||||||
|
|
||||||
cats = CategoryController.available_categories(
|
cats = CategoryController.available_categories(
|
||||||
self.USER_1,
|
self.USER_1,
|
||||||
|
|
|
@ -5,7 +5,7 @@ from decimal import Decimal
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
|
||||||
from registrasion import models as rego
|
from registrasion import models as rego
|
||||||
from registrasion.controllers.cart import CartController
|
from cart_controller_helper import TestingCartController
|
||||||
from registrasion.controllers.invoice import InvoiceController
|
from registrasion.controllers.invoice import InvoiceController
|
||||||
|
|
||||||
from test_cart import RegistrationCartTestCase
|
from test_cart import RegistrationCartTestCase
|
||||||
|
@ -16,7 +16,7 @@ UTC = pytz.timezone('UTC')
|
||||||
class InvoiceTestCase(RegistrationCartTestCase):
|
class InvoiceTestCase(RegistrationCartTestCase):
|
||||||
|
|
||||||
def test_create_invoice(self):
|
def test_create_invoice(self):
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
|
|
||||||
# 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)
|
||||||
|
@ -49,11 +49,11 @@ class InvoiceTestCase(RegistrationCartTestCase):
|
||||||
def test_create_invoice_fails_if_cart_invalid(self):
|
def test_create_invoice_fails_if_cart_invalid(self):
|
||||||
self.make_ceiling("Limit ceiling", limit=1)
|
self.make_ceiling("Limit ceiling", limit=1)
|
||||||
self.set_time(datetime.datetime(2015, 01, 01, tzinfo=UTC))
|
self.set_time(datetime.datetime(2015, 01, 01, tzinfo=UTC))
|
||||||
current_cart = CartController.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)
|
||||||
|
|
||||||
self.add_timedelta(self.RESERVATION * 2)
|
self.add_timedelta(self.RESERVATION * 2)
|
||||||
cart_2 = CartController.for_user(self.USER_2)
|
cart_2 = TestingCartController.for_user(self.USER_2)
|
||||||
cart_2.add_to_cart(self.PROD_1, 1)
|
cart_2.add_to_cart(self.PROD_1, 1)
|
||||||
|
|
||||||
# Now try to invoice the first user
|
# Now try to invoice the first user
|
||||||
|
@ -61,7 +61,7 @@ class InvoiceTestCase(RegistrationCartTestCase):
|
||||||
InvoiceController.for_cart(current_cart.cart)
|
InvoiceController.for_cart(current_cart.cart)
|
||||||
|
|
||||||
def test_paying_invoice_makes_new_cart(self):
|
def test_paying_invoice_makes_new_cart(self):
|
||||||
current_cart = CartController.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 = InvoiceController.for_cart(current_cart.cart)
|
||||||
|
@ -74,7 +74,7 @@ class InvoiceTestCase(RegistrationCartTestCase):
|
||||||
self.assertFalse(invoice.invoice.cart.active)
|
self.assertFalse(invoice.invoice.cart.active)
|
||||||
|
|
||||||
# Asking for a cart should generate a new one
|
# Asking for a cart should generate a new one
|
||||||
new_cart = CartController.for_user(self.USER_1)
|
new_cart = TestingCartController.for_user(self.USER_1)
|
||||||
self.assertNotEqual(current_cart.cart, new_cart.cart)
|
self.assertNotEqual(current_cart.cart, new_cart.cart)
|
||||||
|
|
||||||
def test_invoice_includes_discounts(self):
|
def test_invoice_includes_discounts(self):
|
||||||
|
@ -96,7 +96,7 @@ class InvoiceTestCase(RegistrationCartTestCase):
|
||||||
quantity=1
|
quantity=1
|
||||||
).save()
|
).save()
|
||||||
|
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
current_cart.apply_voucher(voucher.code)
|
current_cart.apply_voucher(voucher.code)
|
||||||
|
|
||||||
# Should be able to create an invoice after the product is added
|
# Should be able to create an invoice after the product is added
|
||||||
|
@ -112,7 +112,7 @@ class InvoiceTestCase(RegistrationCartTestCase):
|
||||||
invoice_1.invoice.value)
|
invoice_1.invoice.value)
|
||||||
|
|
||||||
def test_invoice_voids_self_if_cart_is_invalid(self):
|
def test_invoice_voids_self_if_cart_is_invalid(self):
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
|
|
||||||
# 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)
|
||||||
|
@ -134,7 +134,7 @@ class InvoiceTestCase(RegistrationCartTestCase):
|
||||||
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):
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
|
|
||||||
# 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)
|
||||||
|
@ -147,7 +147,7 @@ class InvoiceTestCase(RegistrationCartTestCase):
|
||||||
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):
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
|
|
||||||
# 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)
|
||||||
|
@ -159,7 +159,7 @@ class InvoiceTestCase(RegistrationCartTestCase):
|
||||||
invoice_1.pay("Reference", invoice_1.invoice.value)
|
invoice_1.pay("Reference", invoice_1.invoice.value)
|
||||||
|
|
||||||
def test_cannot_void_paid_invoice(self):
|
def test_cannot_void_paid_invoice(self):
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
|
|
||||||
# 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)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
from registrasion.controllers.cart import CartController
|
from cart_controller_helper import TestingCartController
|
||||||
from registrasion.controllers.invoice import InvoiceController
|
from registrasion.controllers.invoice import InvoiceController
|
||||||
|
|
||||||
from test_cart import RegistrationCartTestCase
|
from test_cart import RegistrationCartTestCase
|
||||||
|
@ -11,7 +11,7 @@ UTC = pytz.timezone('UTC')
|
||||||
class RefundTestCase(RegistrationCartTestCase):
|
class RefundTestCase(RegistrationCartTestCase):
|
||||||
|
|
||||||
def test_refund_marks_void_and_unpaid_and_cart_released(self):
|
def test_refund_marks_void_and_unpaid_and_cart_released(self):
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
|
|
||||||
# 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)
|
||||||
|
|
|
@ -6,7 +6,7 @@ from django.core.exceptions import ValidationError
|
||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
|
|
||||||
from registrasion import models as rego
|
from registrasion import models as rego
|
||||||
from registrasion.controllers.cart import CartController
|
from cart_controller_helper import TestingCartController
|
||||||
from registrasion.controllers.invoice import InvoiceController
|
from registrasion.controllers.invoice import InvoiceController
|
||||||
|
|
||||||
from test_cart import RegistrationCartTestCase
|
from test_cart import RegistrationCartTestCase
|
||||||
|
@ -31,12 +31,12 @@ class VoucherTestCases(RegistrationCartTestCase):
|
||||||
|
|
||||||
self.set_time(datetime.datetime(2015, 01, 01, tzinfo=UTC))
|
self.set_time(datetime.datetime(2015, 01, 01, tzinfo=UTC))
|
||||||
|
|
||||||
cart_1 = CartController.for_user(self.USER_1)
|
cart_1 = TestingCartController.for_user(self.USER_1)
|
||||||
cart_1.apply_voucher(voucher.code)
|
cart_1.apply_voucher(voucher.code)
|
||||||
self.assertIn(voucher, cart_1.cart.vouchers.all())
|
self.assertIn(voucher, cart_1.cart.vouchers.all())
|
||||||
|
|
||||||
# Second user should not be able to apply this voucher (it's exhausted)
|
# Second user should not be able to apply this voucher (it's exhausted)
|
||||||
cart_2 = CartController.for_user(self.USER_2)
|
cart_2 = TestingCartController.for_user(self.USER_2)
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
cart_2.apply_voucher(voucher.code)
|
cart_2.apply_voucher(voucher.code)
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ class VoucherTestCases(RegistrationCartTestCase):
|
||||||
enabling_condition.save()
|
enabling_condition.save()
|
||||||
|
|
||||||
# Adding the product without a voucher will not work
|
# Adding the product without a voucher will not work
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
current_cart.add_to_cart(self.PROD_1, 1)
|
current_cart.add_to_cart(self.PROD_1, 1)
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ class VoucherTestCases(RegistrationCartTestCase):
|
||||||
).save()
|
).save()
|
||||||
|
|
||||||
# Having PROD_1 in place should add a discount
|
# Having PROD_1 in place should add a discount
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
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)
|
||||||
self.assertEqual(1, len(current_cart.cart.discountitem_set.all()))
|
self.assertEqual(1, len(current_cart.cart.discountitem_set.all()))
|
||||||
|
@ -106,19 +106,19 @@ class VoucherTestCases(RegistrationCartTestCase):
|
||||||
|
|
||||||
def test_vouchers_case_insensitive(self):
|
def test_vouchers_case_insensitive(self):
|
||||||
voucher = self.new_voucher(code="VOUCHeR")
|
voucher = self.new_voucher(code="VOUCHeR")
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
current_cart.apply_voucher(voucher.code.lower())
|
current_cart.apply_voucher(voucher.code.lower())
|
||||||
|
|
||||||
def test_voucher_can_only_be_applied_once(self):
|
def test_voucher_can_only_be_applied_once(self):
|
||||||
voucher = self.new_voucher(limit=2)
|
voucher = self.new_voucher(limit=2)
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
current_cart.apply_voucher(voucher.code)
|
current_cart.apply_voucher(voucher.code)
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
current_cart.apply_voucher(voucher.code)
|
current_cart.apply_voucher(voucher.code)
|
||||||
|
|
||||||
def test_voucher_can_only_be_applied_once_across_multiple_carts(self):
|
def test_voucher_can_only_be_applied_once_across_multiple_carts(self):
|
||||||
voucher = self.new_voucher(limit=2)
|
voucher = self.new_voucher(limit=2)
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
current_cart.apply_voucher(voucher.code)
|
current_cart.apply_voucher(voucher.code)
|
||||||
|
|
||||||
inv = InvoiceController.for_cart(current_cart.cart)
|
inv = InvoiceController.for_cart(current_cart.cart)
|
||||||
|
@ -131,13 +131,13 @@ class VoucherTestCases(RegistrationCartTestCase):
|
||||||
|
|
||||||
def test_refund_releases_used_vouchers(self):
|
def test_refund_releases_used_vouchers(self):
|
||||||
voucher = self.new_voucher(limit=2)
|
voucher = self.new_voucher(limit=2)
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
current_cart.apply_voucher(voucher.code)
|
current_cart.apply_voucher(voucher.code)
|
||||||
|
|
||||||
inv = InvoiceController.for_cart(current_cart.cart)
|
inv = InvoiceController.for_cart(current_cart.cart)
|
||||||
inv.pay("Hello!", inv.invoice.value)
|
inv.pay("Hello!", inv.invoice.value)
|
||||||
|
|
||||||
current_cart = CartController.for_user(self.USER_1)
|
current_cart = TestingCartController.for_user(self.USER_1)
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
current_cart.apply_voucher(voucher.code)
|
current_cart.apply_voucher(voucher.code)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue