Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor absolute discount benefit tests.

Now using --spec format which is more readable (most of the time).
  • Loading branch information...
commit da2f16f896daa922e5cad076917eb22e5085de30 1 parent c3b1546
@codeinthehole codeinthehole authored
View
6 oscar/test/helpers.py
@@ -27,12 +27,14 @@
def create_product(price=None, title="Dummy title", product_class="Dummy item class",
- partner="Dummy partner", partner_sku=None, upc=None, num_in_stock=10, attributes=None):
+ partner="Dummy partner", partner_sku=None, upc=None, num_in_stock=10,
+ attributes=None, **kwargs):
"""
Helper method for creating products that are used in tests.
"""
ic,_ = ProductClass._default_manager.get_or_create(name=product_class)
- item = Product._default_manager.create(title=title, product_class=ic, upc=upc)
+ item = Product._default_manager.create(title=title, product_class=ic,
+ upc=upc, **kwargs)
if price is not None or partner_sku or num_in_stock is not None:
if not partner_sku:
partner_sku = 'sku_%d_%d' % (item.id, random.randint(0, 10000))
View
3  tests/unit/offer/__init__.py
@@ -6,5 +6,6 @@
class OfferTest(TestCase):
def setUp(self):
- self.range = models.Range.objects.create(name="All products range", includes_all_products=True)
+ self.range = models.Range.objects.create(
+ name="All products range", includes_all_products=True)
self.basket = Basket.objects.create()
View
278 tests/unit/offer/benefit_tests.py
@@ -1,4 +1,4 @@
-from decimal import Decimal
+from decimal import Decimal as D
from django.conf import settings
@@ -12,8 +12,8 @@ class PercentageDiscountBenefitTest(OfferTest):
def setUp(self):
super(PercentageDiscountBenefitTest, self).setUp()
- self.benefit = models.PercentageDiscountBenefit(range=self.range, type="Percentage", value=Decimal('15.00'))
- self.item = create_product(price=Decimal('5.00'))
+ self.benefit = models.PercentageDiscountBenefit(range=self.range, type="Percentage", value=D('15.00'))
+ self.item = create_product(price=D('5.00'))
self.original_offer_rounding_function = getattr(settings, 'OSCAR_OFFER_ROUNDING_FUNCTION', None)
if self.original_offer_rounding_function is not None:
delattr(settings, 'OSCAR_OFFER_ROUNDING_FUNCTION')
@@ -24,32 +24,32 @@ def tearDown(self):
settings.OSCAR_OFFER_ROUNDING_FUNCTION = self.original_offer_rounding_function
def test_no_discount_for_empty_basket(self):
- self.assertEquals(Decimal('0.00'), self.benefit.apply(self.basket))
+ self.assertEquals(D('0.00'), self.benefit.apply(self.basket))
def test_no_discount_for_not_discountable_product(self):
self.item.is_discountable = False
self.item.save()
self.basket.add_product(self.item, 1)
- self.assertEquals(Decimal('0.00'), self.benefit.apply(self.basket))
+ self.assertEquals(D('0.00'), self.benefit.apply(self.basket))
def test_discount_for_single_item_basket(self):
self.basket.add_product(self.item, 1)
- self.assertEquals(Decimal('0.15') * Decimal('5.00'), self.benefit.apply(self.basket))
+ self.assertEquals(D('0.15') * D('5.00'), self.benefit.apply(self.basket))
def test_discount_for_multi_item_basket(self):
self.basket.add_product(self.item, 3)
- self.assertEquals(Decimal('3') * Decimal('0.15') * Decimal('5.00'), self.benefit.apply(self.basket))
+ self.assertEquals(D('3') * D('0.15') * D('5.00'), self.benefit.apply(self.basket))
def test_discount_for_multi_item_basket_with_max_affected_items_set(self):
self.basket.add_product(self.item, 3)
self.benefit.max_affected_items = 1
- self.assertEquals(Decimal('0.15') * Decimal('5.00'), self.benefit.apply(self.basket))
+ self.assertEquals(D('0.15') * D('5.00'), self.benefit.apply(self.basket))
def test_discount_can_only_be_applied_once(self):
self.basket.add_product(self.item, 3)
self.benefit.apply(self.basket)
second_discount = self.benefit.apply(self.basket)
- self.assertEquals(Decimal('0.00'), second_discount)
+ self.assertEquals(D('0.00'), second_discount)
def test_discount_can_be_applied_several_times_when_max_is_set(self):
self.basket.add_product(self.item, 3)
@@ -58,110 +58,138 @@ def test_discount_can_be_applied_several_times_when_max_is_set(self):
self.assertTrue(self.benefit.apply(self.basket) > 0)
-class AbsoluteDiscountBenefitTest(OfferTest):
+class TestAbsoluteDiscount(OfferTest):
def setUp(self):
- super(AbsoluteDiscountBenefitTest, self).setUp()
+ super(TestAbsoluteDiscount, self).setUp()
+
self.benefit = models.AbsoluteDiscountBenefit(
- range=self.range, type="Absolute", value=Decimal('10.00'))
- self.item = create_product(price=Decimal('5.00'))
- self.original_offer_rounding_function = getattr(settings, 'OSCAR_OFFER_ROUNDING_FUNCTION', None)
+ range=self.range, type="Absolute", value=D('10.00'))
+ self.item = create_product(price=D('5.00'))
+
+ self.original_offer_rounding_function = getattr(
+ settings, 'OSCAR_OFFER_ROUNDING_FUNCTION', None)
if self.original_offer_rounding_function is not None:
delattr(settings, 'OSCAR_OFFER_ROUNDING_FUNCTION')
def tearDown(self):
- super(AbsoluteDiscountBenefitTest, self).tearDown()
if self.original_offer_rounding_function is not None:
settings.OSCAR_OFFER_ROUNDING_FUNCTION = self.original_offer_rounding_function
- def test_no_discount_for_empty_basket(self):
- self.assertEquals(Decimal('0.00'), self.benefit.apply(self.basket))
-
- def test_no_discount_for_not_discountable_product(self):
- self.item.is_discountable = False
- self.item.save()
- self.basket.add_product(self.item, 1)
- self.assertEquals(Decimal('0.00'), self.benefit.apply(self.basket))
-
- def test_discount_for_single_item_basket(self):
- self.basket.add_product(self.item, 1)
- self.assertEquals(Decimal('5.00'), self.benefit.apply(self.basket))
+ def test_gives_no_discount_for_an_empty_basket(self):
+ self.assertEquals(D('0.00'), self.benefit.apply(self.basket))
+
+ def test_gives_no_discount_for_a_non_discountable_product(self):
+ product = create_product(price=D('5.00'), is_discountable=False)
+ self.basket.add_product(product)
+ self.assertEquals(D('0.00'), self.benefit.apply(self.basket))
+
+ def test_gives_correct_discount_for_single_item_basket_cheaper_than_threshold(self):
+ product = create_product(price=D('5.00'))
+ self.basket.add_product(product)
+ self.assertEquals(D('5.00'), self.benefit.apply(self.basket))
+
+ def test_gives_correct_discount_for_single_item_basket_equal_to_threshold(self):
+ product = create_product(price=D('10.00'))
+ self.basket.add_product(product)
+ self.assertEquals(D('10.00'), self.benefit.apply(self.basket))
+
+ def test_gives_correct_discount_for_single_item_basket_more_expensive_than_threshold(self):
+ product = create_product(price=D('16.00'))
+ self.basket.add_product(product)
+ self.assertEquals(D('10.00'), self.benefit.apply(self.basket))
+
+ def test_gives_correct_discount_for_multi_item_basket_cheaper_than_threshold(self):
+ product = create_product(price=D('2.00'))
+ self.basket.add_product(product, 3)
+ self.assertEquals(D('6.00'), self.benefit.apply(self.basket))
+
+ def test_gives_correct_discount_for_multi_item_basket_more_expensive_than_threshold(self):
+ product = create_product(price=D('5.00'))
+ self.basket.add_product(product, 3)
+ self.assertEquals(D('10.00'), self.benefit.apply(self.basket))
+
+ def test_consumes_all_lines_for_multi_item_basket_cheaper_than_threshold(self):
+ product = create_product(price=D('2.00'))
+ self.basket.add_product(product, 3)
+ self.benefit.apply(self.basket)
+ for line in self.basket.all_lines():
+ self.assertTrue(line.has_discount)
+ self.assertEqual(0, line.quantity_without_discount)
- def test_discount_for_multi_item_basket(self):
- self.basket.add_product(self.item, 3)
- self.assertEquals(Decimal('10.00'), self.benefit.apply(self.basket))
+ def test_consumes_correct_quantity_for_multi_item_basket_more_expensive_than_threshold(self):
+ product = create_product(price=D('6.00'))
+ self.basket.add_product(product, 3)
+ self.benefit.apply(self.basket)
+ line = self.basket.all_lines()[0]
+ self.assertTrue(line.has_discount)
+ self.assertEqual(1, line.quantity_without_discount)
- def test_discount_for_multi_item_basket_with_max_affected_items_set(self):
- self.basket.add_product(self.item, 3)
+ def test_gives_correct_discount_for_multi_item_basket_with_max_affected_items_set(self):
+ product = create_product(price=D('5.00'))
+ self.basket.add_product(product, 3)
self.benefit.max_affected_items = 1
- self.assertEquals(Decimal('5.00'), self.benefit.apply(self.basket))
+ self.assertEquals(D('5.00'), self.benefit.apply(self.basket))
- def test_discount_can_only_be_applied_once(self):
- # Add 3 items to make total 15.00
- self.basket.add_product(self.item, 3)
- first_discount = self.benefit.apply(self.basket)
- self.assertEquals(Decimal('10.00'), first_discount)
+ def test_gives_correct_discounts_when_applied_multiple_times(self):
+ product = create_product(price=D('5.00'))
+ self.basket.add_product(product, 3)
- second_discount = self.benefit.apply(self.basket)
- self.assertEquals(Decimal('5.00'), second_discount)
+ self.assertEquals(D('10.00'), self.benefit.apply(self.basket))
+ self.assertEquals(D('5.00'), self.benefit.apply(self.basket))
+ self.assertEquals(D('0.00'), self.benefit.apply(self.basket))
- def test_absolute_does_not_consume_twice(self):
- product = create_product(Decimal('25000'))
+ def test_gives_correct_discounts_when_applied_multiple_times_with_condition(self):
+ product = create_product(D('25000'))
rng = models.Range.objects.create(name='Dummy')
rng.included_products.add(product)
- condition = models.ValueCondition(range=rng, type='Value', value=Decimal('5000'))
- basket = Basket.objects.create()
- basket.add_product(product, 5)
- benefit = models.AbsoluteDiscountBenefit(range=rng, type='Absolute', value=Decimal('100'))
- self.assertTrue(condition.is_satisfied(basket))
- self.assertEquals(Decimal('100'), benefit.apply(basket, condition))
- self.assertTrue(condition.is_satisfied(basket))
- self.assertEquals(Decimal('100'), benefit.apply(basket, condition))
- self.assertTrue(condition.is_satisfied(basket))
- self.assertEquals(Decimal('100'), benefit.apply(basket, condition))
- self.assertTrue(condition.is_satisfied(basket))
- self.assertEquals(Decimal('100'), benefit.apply(basket, condition))
- self.assertTrue(condition.is_satisfied(basket))
- self.assertEquals(Decimal('100'), benefit.apply(basket, condition))
- self.assertFalse(condition.is_satisfied(basket))
- self.assertEquals(Decimal('0'), benefit.apply(basket, condition))
-
- def test_absolute_consumes_all(self):
- product1 = create_product(Decimal('150'))
- product2 = create_product(Decimal('300'))
- product3 = create_product(Decimal('300'))
+ condition = models.ValueCondition(range=rng, type='Value', value=D('5000'))
+
+ self.basket.add_product(product, 5)
+ benefit = models.AbsoluteDiscountBenefit(range=rng, type='Absolute', value=D('100'))
+
+ for _ in range(5):
+ self.assertTrue(condition.is_satisfied(self.basket))
+ self.assertEquals(D('100'), benefit.apply(self.basket, condition))
+
+ self.assertFalse(condition.is_satisfied(self.basket))
+ self.assertEquals(D('0'), benefit.apply(self.basket, condition))
+
+ def test_consumes_all_products_for_heterogeneous_basket(self):
rng = models.Range.objects.create(name='Dummy')
- rng.included_products.add(product1)
- rng.included_products.add(product2)
- rng.included_products.add(product3)
+ products = [create_product(D('150')),
+ create_product(D('300')),
+ create_product(D('300'))]
+ for product in products:
+ rng.included_products.add(product)
- condition = models.ValueCondition(range=rng, type='Value', value=Decimal('500'))
+ condition = models.ValueCondition(range=rng, type='Value', value=D('500'))
basket = Basket.objects.create()
- basket.add_product(product1, 1)
- basket.add_product(product2, 1)
- basket.add_product(product3, 1)
+ for product in products:
+ basket.add_product(product)
+
+ benefit = models.AbsoluteDiscountBenefit(range=rng, type='Absolute', value=D('100'))
- benefit = models.AbsoluteDiscountBenefit(range=rng, type='Absolute', value=Decimal('100'))
self.assertTrue(condition.is_satisfied(basket))
- self.assertEquals(Decimal('100'), benefit.apply(basket, condition))
- self.assertEquals(Decimal('0'), benefit.apply(basket, condition))
+ self.assertEquals(D('100'), benefit.apply(basket, condition))
+ self.assertEquals(D('0'), benefit.apply(basket, condition))
- def test_absolute_applies_line_discount(self):
- product = create_product(Decimal('500'))
+ def test_correctly_discounts_line(self):
+ product = create_product(D('500'))
rng = models.Range.objects.create(name='Dummy')
rng.included_products.add(product)
- condition = models.ValueCondition(range=rng, type='Value', value=Decimal('500'))
+ condition = models.ValueCondition(range=rng, type='Value', value=D('500'))
basket = Basket.objects.create()
basket.add_product(product, 1)
- benefit = models.AbsoluteDiscountBenefit(range=rng, type='Absolute', value=Decimal('100'))
+ benefit = models.AbsoluteDiscountBenefit(range=rng, type='Absolute', value=D('100'))
self.assertTrue(condition.is_satisfied(basket))
- self.assertEquals(Decimal('100'), benefit.apply(basket, condition))
- self.assertEquals(Decimal('100'), basket.all_lines()[0]._discount)
+ self.assertEquals(D('100'), benefit.apply(basket, condition))
+ self.assertEquals(D('100'), basket.all_lines()[0]._discount)
def test_discount_is_applied_to_lines(self):
condition = models.CountCondition.objects.create(
@@ -176,38 +204,38 @@ class MultibuyDiscountBenefitTest(OfferTest):
def setUp(self):
super(MultibuyDiscountBenefitTest, self).setUp()
self.benefit = models.MultibuyDiscountBenefit(range=self.range, type="Multibuy", value=1)
- self.item = create_product(price=Decimal('5.00'))
+ self.item = create_product(price=D('5.00'))
def test_no_discount_for_empty_basket(self):
- self.assertEquals(Decimal('0.00'), self.benefit.apply(self.basket))
+ self.assertEquals(D('0.00'), self.benefit.apply(self.basket))
def test_discount_for_single_item_basket(self):
self.basket.add_product(self.item, 1)
- self.assertEquals(Decimal('5.00'), self.benefit.apply(self.basket))
+ self.assertEquals(D('5.00'), self.benefit.apply(self.basket))
def test_discount_for_multi_item_basket(self):
self.basket.add_product(self.item, 3)
- self.assertEquals(Decimal('5.00'), self.benefit.apply(self.basket))
+ self.assertEquals(D('5.00'), self.benefit.apply(self.basket))
def test_no_discount_for_not_discountable_product(self):
self.item.is_discountable = False
self.item.save()
self.basket.add_product(self.item, 1)
- self.assertEquals(Decimal('0.00'), self.benefit.apply(self.basket))
+ self.assertEquals(D('0.00'), self.benefit.apply(self.basket))
def test_discount_does_not_consume_item_if_in_condition_range(self):
self.basket.add_product(self.item, 1)
first_discount = self.benefit.apply(self.basket)
- self.assertEquals(Decimal('5.00'), first_discount)
+ self.assertEquals(D('5.00'), first_discount)
second_discount = self.benefit.apply(self.basket)
- self.assertEquals(Decimal('5.00'), second_discount)
+ self.assertEquals(D('5.00'), second_discount)
def test_product_does_consume_item_if_not_in_condition_range(self):
# Set up condition using a different range from benefit
range = models.Range.objects.create(name="Small range")
- other_product = create_product(price=Decimal('15.00'))
+ other_product = create_product(price=D('15.00'))
range.included_products.add(other_product)
- cond = models.ValueCondition(range=range, type="Value", value=Decimal('10.00'))
+ cond = models.ValueCondition(range=range, type="Value", value=D('10.00'))
self.basket.add_product(self.item, 1)
self.benefit.apply(self.basket, cond)
@@ -216,7 +244,7 @@ def test_product_does_consume_item_if_not_in_condition_range(self):
def test_condition_consumes_most_expensive_lines_first(self):
for i in range(10, 0, -1):
- product = create_product(price=Decimal(i), title='%i'%i, upc='upc_%i' % i)
+ product = create_product(price=D(i), title='%i'%i, upc='upc_%i' % i)
self.basket.add_product(product, 1)
condition = models.CountCondition(range=self.range, type="Count", value=2)
@@ -224,34 +252,34 @@ def test_condition_consumes_most_expensive_lines_first(self):
self.assertTrue(condition.is_satisfied(self.basket))
# consume 1 and 10
first_discount = self.benefit.apply(self.basket, condition=condition)
- self.assertEquals(Decimal('1.00'), first_discount)
+ self.assertEquals(D('1.00'), first_discount)
self.assertTrue(condition.is_satisfied(self.basket))
# consume 2 and 9
second_discount = self.benefit.apply(self.basket, condition=condition)
- self.assertEquals(Decimal('2.00'), second_discount)
+ self.assertEquals(D('2.00'), second_discount)
self.assertTrue(condition.is_satisfied(self.basket))
# consume 3 and 8
third_discount = self.benefit.apply(self.basket, condition=condition)
- self.assertEquals(Decimal('3.00'), third_discount)
+ self.assertEquals(D('3.00'), third_discount)
self.assertTrue(condition.is_satisfied(self.basket))
# consume 4 and 7
fourth_discount = self.benefit.apply(self.basket, condition=condition)
- self.assertEquals(Decimal('4.00'), fourth_discount)
+ self.assertEquals(D('4.00'), fourth_discount)
self.assertTrue(condition.is_satisfied(self.basket))
# consume 5 and 6
fifth_discount = self.benefit.apply(self.basket, condition=condition)
- self.assertEquals(Decimal('5.00'), fifth_discount)
+ self.assertEquals(D('5.00'), fifth_discount)
# end of items (one not discounted item in basket)
self.assertFalse(condition.is_satisfied(self.basket))
def test_condition_consumes_most_expensive_lines_first_when_products_are_repeated(self):
for i in range(5, 0, -1):
- product = create_product(price=Decimal(i), title='%i'%i, upc='upc_%i' % i)
+ product = create_product(price=D(i), title='%i'%i, upc='upc_%i' % i)
self.basket.add_product(product, 2)
condition = models.CountCondition(range=self.range, type="Count", value=2)
@@ -260,27 +288,27 @@ def test_condition_consumes_most_expensive_lines_first_when_products_are_repeate
self.assertTrue(condition.is_satisfied(self.basket))
# consume 1 and 5
first_discount = self.benefit.apply(self.basket, condition=condition)
- self.assertEquals(Decimal('1.00'), first_discount)
+ self.assertEquals(D('1.00'), first_discount)
self.assertTrue(condition.is_satisfied(self.basket))
# consume 1 and 5
second_discount = self.benefit.apply(self.basket, condition=condition)
- self.assertEquals(Decimal('1.00'), second_discount)
+ self.assertEquals(D('1.00'), second_discount)
self.assertTrue(condition.is_satisfied(self.basket))
# consume 2 and 4
third_discount = self.benefit.apply(self.basket, condition=condition)
- self.assertEquals(Decimal('2.00'), third_discount)
+ self.assertEquals(D('2.00'), third_discount)
self.assertTrue(condition.is_satisfied(self.basket))
# consume 2 and 4
third_discount = self.benefit.apply(self.basket, condition=condition)
- self.assertEquals(Decimal('2.00'), third_discount)
+ self.assertEquals(D('2.00'), third_discount)
self.assertTrue(condition.is_satisfied(self.basket))
# consume 3 and 3
third_discount = self.benefit.apply(self.basket, condition=condition)
- self.assertEquals(Decimal('3.00'), third_discount)
+ self.assertEquals(D('3.00'), third_discount)
# end of items (one not discounted item in basket)
self.assertFalse(condition.is_satisfied(self.basket))
@@ -296,12 +324,12 @@ class FixedPriceBenefitTest(OfferTest):
def setUp(self):
super(FixedPriceBenefitTest, self).setUp()
- self.benefit = models.FixedPriceBenefit(range=self.range, type="FixedPrice", value=Decimal('10.00'))
+ self.benefit = models.FixedPriceBenefit(range=self.range, type="FixedPrice", value=D('10.00'))
def test_correct_discount_for_count_condition(self):
- products = [create_product(Decimal('7.00')),
- create_product(Decimal('8.00')),
- create_product(Decimal('12.00'))]
+ products = [create_product(D('7.00')),
+ create_product(D('8.00')),
+ create_product(D('12.00'))]
# Create range that includes the products
range = models.Range.objects.create(name="Dummy range")
@@ -313,13 +341,13 @@ def test_correct_discount_for_count_condition(self):
basket = Basket.objects.create()
[basket.add_product(p, 2) for p in products]
- benefit = models.FixedPriceBenefit(range=range, type="FixedPrice", value=Decimal('20.00'))
- self.assertEquals(Decimal('2.00'), benefit.apply(basket, condition))
- self.assertEquals(Decimal('12.00'), benefit.apply(basket, condition))
- self.assertEquals(Decimal('0.00'), benefit.apply(basket, condition))
+ benefit = models.FixedPriceBenefit(range=range, type="FixedPrice", value=D('20.00'))
+ self.assertEquals(D('2.00'), benefit.apply(basket, condition))
+ self.assertEquals(D('12.00'), benefit.apply(basket, condition))
+ self.assertEquals(D('0.00'), benefit.apply(basket, condition))
def test_correct_discount_is_returned(self):
- products = [create_product(Decimal('8.00')), create_product(Decimal('4.00'))]
+ products = [create_product(D('8.00')), create_product(D('4.00'))]
range = models.Range.objects.create(name="Dummy range")
for product in products:
range.included_products.add(product)
@@ -330,10 +358,10 @@ def test_correct_discount_is_returned(self):
condition = models.CoverageCondition(range=range, type="Coverage", value=2)
discount = self.benefit.apply(basket, condition)
- self.assertEquals(Decimal('2.00'), discount)
+ self.assertEquals(D('2.00'), discount)
def test_no_discount_when_product_not_discountable(self):
- product = create_product(Decimal('18.00'))
+ product = create_product(D('18.00'))
product.is_discountable = False
product.save()
@@ -345,10 +373,10 @@ def test_no_discount_when_product_not_discountable(self):
condition = models.CoverageCondition(range=product_range, type="Coverage", value=1)
discount = self.benefit.apply(basket, condition)
- self.assertEquals(Decimal('0.00'), discount)
+ self.assertEquals(D('0.00'), discount)
def test_no_discount_is_returned_when_value_is_greater_than_product_total(self):
- products = [create_product(Decimal('4.00')), create_product(Decimal('4.00'))]
+ products = [create_product(D('4.00')), create_product(D('4.00'))]
range = models.Range.objects.create(name="Dummy range")
for product in products:
range.included_products.add(product)
@@ -359,12 +387,12 @@ def test_no_discount_is_returned_when_value_is_greater_than_product_total(self):
condition = models.CoverageCondition(range=range, type="Coverage", value=2)
discount = self.benefit.apply(basket, condition)
- self.assertEquals(Decimal('0.00'), discount)
+ self.assertEquals(D('0.00'), discount)
def test_discount_when_more_products_than_required(self):
- products = [create_product(Decimal('4.00')),
- create_product(Decimal('8.00')),
- create_product(Decimal('12.00'))]
+ products = [create_product(D('4.00')),
+ create_product(D('8.00')),
+ create_product(D('12.00'))]
# Create range that includes the products
range = models.Range.objects.create(name="Dummy range")
@@ -377,14 +405,14 @@ def test_discount_when_more_products_than_required(self):
[basket.add_product(p) for p in products]
basket.add_product(products[0])
- benefit = models.FixedPriceBenefit(range=range, type="FixedPrice", value=Decimal('20.00'))
+ benefit = models.FixedPriceBenefit(range=range, type="FixedPrice", value=D('20.00'))
discount = benefit.apply(basket, condition)
- self.assertEquals(Decimal('4.00'), discount)
+ self.assertEquals(D('4.00'), discount)
def test_discount_when_applied_twice(self):
- products = [create_product(Decimal('4.00')),
- create_product(Decimal('8.00')),
- create_product(Decimal('12.00'))]
+ products = [create_product(D('4.00')),
+ create_product(D('8.00')),
+ create_product(D('12.00'))]
# Create range that includes the products
range = models.Range.objects.create(name="Dummy range")
@@ -396,8 +424,8 @@ def test_discount_when_applied_twice(self):
basket = Basket.objects.create()
[basket.add_product(p, 2) for p in products]
- benefit = models.FixedPriceBenefit(range=range, type="FixedPrice", value=Decimal('20.00'))
+ benefit = models.FixedPriceBenefit(range=range, type="FixedPrice", value=D('20.00'))
first_discount = benefit.apply(basket, condition)
- self.assertEquals(Decimal('4.00'), first_discount)
+ self.assertEquals(D('4.00'), first_discount)
second_discount = benefit.apply(basket, condition)
- self.assertEquals(Decimal('4.00'), second_discount)
+ self.assertEquals(D('4.00'), second_discount)
Please sign in to comment.
Something went wrong with that request. Please try again.