Skip to content
This repository
Browse code

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
David Winterbottom authored August 13, 2012
6  oscar/test/helpers.py
@@ -27,12 +27,14 @@
27 27
 
28 28
 
29 29
 def create_product(price=None, title="Dummy title", product_class="Dummy item class",
30  
-        partner="Dummy partner", partner_sku=None, upc=None, num_in_stock=10, attributes=None):
  30
+        partner="Dummy partner", partner_sku=None, upc=None, num_in_stock=10,
  31
+        attributes=None, **kwargs):
31 32
     """
32 33
     Helper method for creating products that are used in tests.
33 34
     """
34 35
     ic,_ = ProductClass._default_manager.get_or_create(name=product_class)
35  
-    item = Product._default_manager.create(title=title, product_class=ic, upc=upc)
  36
+    item = Product._default_manager.create(title=title, product_class=ic,
  37
+                                           upc=upc, **kwargs)
36 38
     if price is not None or partner_sku or num_in_stock is not None:
37 39
         if not partner_sku:
38 40
             partner_sku = 'sku_%d_%d' % (item.id, random.randint(0, 10000))
3  tests/unit/offer/__init__.py
@@ -6,5 +6,6 @@
6 6
 
7 7
 class OfferTest(TestCase):
8 8
     def setUp(self):
9  
-        self.range = models.Range.objects.create(name="All products range", includes_all_products=True)
  9
+        self.range = models.Range.objects.create(
  10
+            name="All products range", includes_all_products=True)
10 11
         self.basket = Basket.objects.create()
278  tests/unit/offer/benefit_tests.py
... ...
@@ -1,4 +1,4 @@
1  
-from decimal import Decimal
  1
+from decimal import Decimal as D
2 2
 
3 3
 from django.conf import settings
4 4
 
@@ -12,8 +12,8 @@ class PercentageDiscountBenefitTest(OfferTest):
12 12
 
13 13
     def setUp(self):
14 14
         super(PercentageDiscountBenefitTest, self).setUp()
15  
-        self.benefit = models.PercentageDiscountBenefit(range=self.range, type="Percentage", value=Decimal('15.00'))
16  
-        self.item = create_product(price=Decimal('5.00'))
  15
+        self.benefit = models.PercentageDiscountBenefit(range=self.range, type="Percentage", value=D('15.00'))
  16
+        self.item = create_product(price=D('5.00'))
17 17
         self.original_offer_rounding_function = getattr(settings, 'OSCAR_OFFER_ROUNDING_FUNCTION', None)
18 18
         if self.original_offer_rounding_function is not None:
19 19
             delattr(settings, 'OSCAR_OFFER_ROUNDING_FUNCTION')
@@ -24,32 +24,32 @@ def tearDown(self):
24 24
             settings.OSCAR_OFFER_ROUNDING_FUNCTION = self.original_offer_rounding_function
25 25
 
26 26
     def test_no_discount_for_empty_basket(self):
27  
-        self.assertEquals(Decimal('0.00'), self.benefit.apply(self.basket))
  27
+        self.assertEquals(D('0.00'), self.benefit.apply(self.basket))
28 28
 
29 29
     def test_no_discount_for_not_discountable_product(self):
30 30
         self.item.is_discountable = False
31 31
         self.item.save()
32 32
         self.basket.add_product(self.item, 1)
33  
-        self.assertEquals(Decimal('0.00'), self.benefit.apply(self.basket))
  33
+        self.assertEquals(D('0.00'), self.benefit.apply(self.basket))
34 34
 
35 35
     def test_discount_for_single_item_basket(self):
36 36
         self.basket.add_product(self.item, 1)
37  
-        self.assertEquals(Decimal('0.15') * Decimal('5.00'), self.benefit.apply(self.basket))
  37
+        self.assertEquals(D('0.15') * D('5.00'), self.benefit.apply(self.basket))
38 38
 
39 39
     def test_discount_for_multi_item_basket(self):
40 40
         self.basket.add_product(self.item, 3)
41  
-        self.assertEquals(Decimal('3') * Decimal('0.15') * Decimal('5.00'), self.benefit.apply(self.basket))
  41
+        self.assertEquals(D('3') * D('0.15') * D('5.00'), self.benefit.apply(self.basket))
42 42
 
43 43
     def test_discount_for_multi_item_basket_with_max_affected_items_set(self):
44 44
         self.basket.add_product(self.item, 3)
45 45
         self.benefit.max_affected_items = 1
46  
-        self.assertEquals(Decimal('0.15') * Decimal('5.00'), self.benefit.apply(self.basket))
  46
+        self.assertEquals(D('0.15') * D('5.00'), self.benefit.apply(self.basket))
47 47
 
48 48
     def test_discount_can_only_be_applied_once(self):
49 49
         self.basket.add_product(self.item, 3)
50 50
         self.benefit.apply(self.basket)
51 51
         second_discount = self.benefit.apply(self.basket)
52  
-        self.assertEquals(Decimal('0.00'), second_discount)
  52
+        self.assertEquals(D('0.00'), second_discount)
53 53
 
54 54
     def test_discount_can_be_applied_several_times_when_max_is_set(self):
55 55
         self.basket.add_product(self.item, 3)
@@ -58,110 +58,138 @@ def test_discount_can_be_applied_several_times_when_max_is_set(self):
58 58
             self.assertTrue(self.benefit.apply(self.basket) > 0)
59 59
 
60 60
 
61  
-class AbsoluteDiscountBenefitTest(OfferTest):
  61
+class TestAbsoluteDiscount(OfferTest):
62 62
 
63 63
     def setUp(self):
64  
-        super(AbsoluteDiscountBenefitTest, self).setUp()
  64
+        super(TestAbsoluteDiscount, self).setUp()
  65
+
65 66
         self.benefit = models.AbsoluteDiscountBenefit(
66  
-            range=self.range, type="Absolute", value=Decimal('10.00'))
67  
-        self.item = create_product(price=Decimal('5.00'))
68  
-        self.original_offer_rounding_function = getattr(settings, 'OSCAR_OFFER_ROUNDING_FUNCTION', None)
  67
+            range=self.range, type="Absolute", value=D('10.00'))
  68
+        self.item = create_product(price=D('5.00'))
  69
+
  70
+        self.original_offer_rounding_function = getattr(
  71
+            settings, 'OSCAR_OFFER_ROUNDING_FUNCTION', None)
69 72
         if self.original_offer_rounding_function is not None:
70 73
             delattr(settings, 'OSCAR_OFFER_ROUNDING_FUNCTION')
71 74
 
72 75
     def tearDown(self):
73  
-        super(AbsoluteDiscountBenefitTest, self).tearDown()
74 76
         if self.original_offer_rounding_function is not None:
75 77
             settings.OSCAR_OFFER_ROUNDING_FUNCTION = self.original_offer_rounding_function
76 78
 
77  
-    def test_no_discount_for_empty_basket(self):
78  
-        self.assertEquals(Decimal('0.00'), self.benefit.apply(self.basket))
79  
-
80  
-    def test_no_discount_for_not_discountable_product(self):
81  
-        self.item.is_discountable = False
82  
-        self.item.save()
83  
-        self.basket.add_product(self.item, 1)
84  
-        self.assertEquals(Decimal('0.00'), self.benefit.apply(self.basket))
85  
-
86  
-    def test_discount_for_single_item_basket(self):
87  
-        self.basket.add_product(self.item, 1)
88  
-        self.assertEquals(Decimal('5.00'), self.benefit.apply(self.basket))
  79
+    def test_gives_no_discount_for_an_empty_basket(self):
  80
+        self.assertEquals(D('0.00'), self.benefit.apply(self.basket))
  81
+
  82
+    def test_gives_no_discount_for_a_non_discountable_product(self):
  83
+        product = create_product(price=D('5.00'), is_discountable=False)
  84
+        self.basket.add_product(product)
  85
+        self.assertEquals(D('0.00'), self.benefit.apply(self.basket))
  86
+
  87
+    def test_gives_correct_discount_for_single_item_basket_cheaper_than_threshold(self):
  88
+        product = create_product(price=D('5.00'))
  89
+        self.basket.add_product(product)
  90
+        self.assertEquals(D('5.00'), self.benefit.apply(self.basket))
  91
+
  92
+    def test_gives_correct_discount_for_single_item_basket_equal_to_threshold(self):
  93
+        product = create_product(price=D('10.00'))
  94
+        self.basket.add_product(product)
  95
+        self.assertEquals(D('10.00'), self.benefit.apply(self.basket))
  96
+
  97
+    def test_gives_correct_discount_for_single_item_basket_more_expensive_than_threshold(self):
  98
+        product = create_product(price=D('16.00'))
  99
+        self.basket.add_product(product)
  100
+        self.assertEquals(D('10.00'), self.benefit.apply(self.basket))
  101
+
  102
+    def test_gives_correct_discount_for_multi_item_basket_cheaper_than_threshold(self):
  103
+        product = create_product(price=D('2.00'))
  104
+        self.basket.add_product(product, 3)
  105
+        self.assertEquals(D('6.00'), self.benefit.apply(self.basket))
  106
+
  107
+    def test_gives_correct_discount_for_multi_item_basket_more_expensive_than_threshold(self):
  108
+        product = create_product(price=D('5.00'))
  109
+        self.basket.add_product(product, 3)
  110
+        self.assertEquals(D('10.00'), self.benefit.apply(self.basket))
  111
+
  112
+    def test_consumes_all_lines_for_multi_item_basket_cheaper_than_threshold(self):
  113
+        product = create_product(price=D('2.00'))
  114
+        self.basket.add_product(product, 3)
  115
+        self.benefit.apply(self.basket)
  116
+        for line in self.basket.all_lines():
  117
+            self.assertTrue(line.has_discount)
  118
+            self.assertEqual(0, line.quantity_without_discount)
89 119
 
90  
-    def test_discount_for_multi_item_basket(self):
91  
-        self.basket.add_product(self.item, 3)
92  
-        self.assertEquals(Decimal('10.00'), self.benefit.apply(self.basket))
  120
+    def test_consumes_correct_quantity_for_multi_item_basket_more_expensive_than_threshold(self):
  121
+        product = create_product(price=D('6.00'))
  122
+        self.basket.add_product(product, 3)
  123
+        self.benefit.apply(self.basket)
  124
+        line = self.basket.all_lines()[0]
  125
+        self.assertTrue(line.has_discount)
  126
+        self.assertEqual(1, line.quantity_without_discount)
93 127
 
94  
-    def test_discount_for_multi_item_basket_with_max_affected_items_set(self):
95  
-        self.basket.add_product(self.item, 3)
  128
+    def test_gives_correct_discount_for_multi_item_basket_with_max_affected_items_set(self):
  129
+        product = create_product(price=D('5.00'))
  130
+        self.basket.add_product(product, 3)
96 131
         self.benefit.max_affected_items = 1
97  
-        self.assertEquals(Decimal('5.00'), self.benefit.apply(self.basket))
  132
+        self.assertEquals(D('5.00'), self.benefit.apply(self.basket))
98 133
 
99  
-    def test_discount_can_only_be_applied_once(self):
100  
-        # Add 3 items to make total 15.00
101  
-        self.basket.add_product(self.item, 3)
102  
-        first_discount = self.benefit.apply(self.basket)
103  
-        self.assertEquals(Decimal('10.00'), first_discount)
  134
+    def test_gives_correct_discounts_when_applied_multiple_times(self):
  135
+        product = create_product(price=D('5.00'))
  136
+        self.basket.add_product(product, 3)
104 137
 
105  
-        second_discount = self.benefit.apply(self.basket)
106  
-        self.assertEquals(Decimal('5.00'), second_discount)
  138
+        self.assertEquals(D('10.00'), self.benefit.apply(self.basket))
  139
+        self.assertEquals(D('5.00'), self.benefit.apply(self.basket))
  140
+        self.assertEquals(D('0.00'), self.benefit.apply(self.basket))
107 141
 
108  
-    def test_absolute_does_not_consume_twice(self):
109  
-        product = create_product(Decimal('25000'))
  142
+    def test_gives_correct_discounts_when_applied_multiple_times_with_condition(self):
  143
+        product = create_product(D('25000'))
110 144
         rng = models.Range.objects.create(name='Dummy')
111 145
         rng.included_products.add(product)
112  
-        condition = models.ValueCondition(range=rng, type='Value', value=Decimal('5000'))
113  
-        basket = Basket.objects.create()
114  
-        basket.add_product(product, 5)
115  
-        benefit = models.AbsoluteDiscountBenefit(range=rng, type='Absolute', value=Decimal('100'))
116 146
 
117  
-        self.assertTrue(condition.is_satisfied(basket))
118  
-        self.assertEquals(Decimal('100'), benefit.apply(basket, condition))
119  
-        self.assertTrue(condition.is_satisfied(basket))
120  
-        self.assertEquals(Decimal('100'), benefit.apply(basket, condition))
121  
-        self.assertTrue(condition.is_satisfied(basket))
122  
-        self.assertEquals(Decimal('100'), benefit.apply(basket, condition))
123  
-        self.assertTrue(condition.is_satisfied(basket))
124  
-        self.assertEquals(Decimal('100'), benefit.apply(basket, condition))
125  
-        self.assertTrue(condition.is_satisfied(basket))
126  
-        self.assertEquals(Decimal('100'), benefit.apply(basket, condition))
127  
-        self.assertFalse(condition.is_satisfied(basket))
128  
-        self.assertEquals(Decimal('0'), benefit.apply(basket, condition))
129  
-
130  
-    def test_absolute_consumes_all(self):
131  
-        product1 = create_product(Decimal('150'))
132  
-        product2 = create_product(Decimal('300'))
133  
-        product3 = create_product(Decimal('300'))
  147
+        condition = models.ValueCondition(range=rng, type='Value', value=D('5000'))
  148
+
  149
+        self.basket.add_product(product, 5)
  150
+        benefit = models.AbsoluteDiscountBenefit(range=rng, type='Absolute', value=D('100'))
  151
+
  152
+        for _ in range(5):
  153
+            self.assertTrue(condition.is_satisfied(self.basket))
  154
+            self.assertEquals(D('100'), benefit.apply(self.basket, condition))
  155
+
  156
+        self.assertFalse(condition.is_satisfied(self.basket))
  157
+        self.assertEquals(D('0'), benefit.apply(self.basket, condition))
  158
+
  159
+    def test_consumes_all_products_for_heterogeneous_basket(self):
134 160
         rng = models.Range.objects.create(name='Dummy')
135  
-        rng.included_products.add(product1)
136  
-        rng.included_products.add(product2)
137  
-        rng.included_products.add(product3)
  161
+        products = [create_product(D('150')),
  162
+                    create_product(D('300')),
  163
+                    create_product(D('300'))]
  164
+        for product in products:
  165
+            rng.included_products.add(product)
138 166
 
139  
-        condition = models.ValueCondition(range=rng, type='Value', value=Decimal('500'))
  167
+        condition = models.ValueCondition(range=rng, type='Value', value=D('500'))
140 168
 
141 169
         basket = Basket.objects.create()
142  
-        basket.add_product(product1, 1)
143  
-        basket.add_product(product2, 1)
144  
-        basket.add_product(product3, 1)
  170
+        for product in products:
  171
+            basket.add_product(product)
  172
+
  173
+        benefit = models.AbsoluteDiscountBenefit(range=rng, type='Absolute', value=D('100'))
145 174
 
146  
-        benefit = models.AbsoluteDiscountBenefit(range=rng, type='Absolute', value=Decimal('100'))
147 175
         self.assertTrue(condition.is_satisfied(basket))
148  
-        self.assertEquals(Decimal('100'), benefit.apply(basket, condition))
149  
-        self.assertEquals(Decimal('0'), benefit.apply(basket, condition))
  176
+        self.assertEquals(D('100'), benefit.apply(basket, condition))
  177
+        self.assertEquals(D('0'), benefit.apply(basket, condition))
150 178
 
151  
-    def test_absolute_applies_line_discount(self):
152  
-        product = create_product(Decimal('500'))
  179
+    def test_correctly_discounts_line(self):
  180
+        product = create_product(D('500'))
153 181
         rng = models.Range.objects.create(name='Dummy')
154 182
         rng.included_products.add(product)
155 183
 
156  
-        condition = models.ValueCondition(range=rng, type='Value', value=Decimal('500'))
  184
+        condition = models.ValueCondition(range=rng, type='Value', value=D('500'))
157 185
         basket = Basket.objects.create()
158 186
         basket.add_product(product, 1)
159 187
 
160  
-        benefit = models.AbsoluteDiscountBenefit(range=rng, type='Absolute', value=Decimal('100'))
  188
+        benefit = models.AbsoluteDiscountBenefit(range=rng, type='Absolute', value=D('100'))
161 189
 
162 190
         self.assertTrue(condition.is_satisfied(basket))
163  
-        self.assertEquals(Decimal('100'), benefit.apply(basket, condition))
164  
-        self.assertEquals(Decimal('100'), basket.all_lines()[0]._discount)
  191
+        self.assertEquals(D('100'), benefit.apply(basket, condition))
  192
+        self.assertEquals(D('100'), basket.all_lines()[0]._discount)
165 193
 
166 194
     def test_discount_is_applied_to_lines(self):
167 195
         condition = models.CountCondition.objects.create(
@@ -176,38 +204,38 @@ class MultibuyDiscountBenefitTest(OfferTest):
176 204
     def setUp(self):
177 205
         super(MultibuyDiscountBenefitTest, self).setUp()
178 206
         self.benefit = models.MultibuyDiscountBenefit(range=self.range, type="Multibuy", value=1)
179  
-        self.item = create_product(price=Decimal('5.00'))
  207
+        self.item = create_product(price=D('5.00'))
180 208
 
181 209
     def test_no_discount_for_empty_basket(self):
182  
-        self.assertEquals(Decimal('0.00'), self.benefit.apply(self.basket))
  210
+        self.assertEquals(D('0.00'), self.benefit.apply(self.basket))
183 211
 
184 212
     def test_discount_for_single_item_basket(self):
185 213
         self.basket.add_product(self.item, 1)
186  
-        self.assertEquals(Decimal('5.00'), self.benefit.apply(self.basket))
  214
+        self.assertEquals(D('5.00'), self.benefit.apply(self.basket))
187 215
 
188 216
     def test_discount_for_multi_item_basket(self):
189 217
         self.basket.add_product(self.item, 3)
190  
-        self.assertEquals(Decimal('5.00'), self.benefit.apply(self.basket))
  218
+        self.assertEquals(D('5.00'), self.benefit.apply(self.basket))
191 219
 
192 220
     def test_no_discount_for_not_discountable_product(self):
193 221
         self.item.is_discountable = False
194 222
         self.item.save()
195 223
         self.basket.add_product(self.item, 1)
196  
-        self.assertEquals(Decimal('0.00'), self.benefit.apply(self.basket))
  224
+        self.assertEquals(D('0.00'), self.benefit.apply(self.basket))
197 225
 
198 226
     def test_discount_does_not_consume_item_if_in_condition_range(self):
199 227
         self.basket.add_product(self.item, 1)
200 228
         first_discount = self.benefit.apply(self.basket)
201  
-        self.assertEquals(Decimal('5.00'), first_discount)
  229
+        self.assertEquals(D('5.00'), first_discount)
202 230
         second_discount = self.benefit.apply(self.basket)
203  
-        self.assertEquals(Decimal('5.00'), second_discount)
  231
+        self.assertEquals(D('5.00'), second_discount)
204 232
 
205 233
     def test_product_does_consume_item_if_not_in_condition_range(self):
206 234
         # Set up condition using a different range from benefit
207 235
         range = models.Range.objects.create(name="Small range")
208  
-        other_product = create_product(price=Decimal('15.00'))
  236
+        other_product = create_product(price=D('15.00'))
209 237
         range.included_products.add(other_product)
210  
-        cond = models.ValueCondition(range=range, type="Value", value=Decimal('10.00'))
  238
+        cond = models.ValueCondition(range=range, type="Value", value=D('10.00'))
211 239
 
212 240
         self.basket.add_product(self.item, 1)
213 241
         self.benefit.apply(self.basket, cond)
@@ -216,7 +244,7 @@ def test_product_does_consume_item_if_not_in_condition_range(self):
216 244
 
217 245
     def test_condition_consumes_most_expensive_lines_first(self):
218 246
         for i in range(10, 0, -1):
219  
-            product = create_product(price=Decimal(i), title='%i'%i, upc='upc_%i' % i)
  247
+            product = create_product(price=D(i), title='%i'%i, upc='upc_%i' % i)
220 248
             self.basket.add_product(product, 1)
221 249
 
222 250
         condition = models.CountCondition(range=self.range, type="Count", value=2)
@@ -224,34 +252,34 @@ def test_condition_consumes_most_expensive_lines_first(self):
224 252
         self.assertTrue(condition.is_satisfied(self.basket))
225 253
         # consume 1 and 10
226 254
         first_discount = self.benefit.apply(self.basket, condition=condition)
227  
-        self.assertEquals(Decimal('1.00'), first_discount)
  255
+        self.assertEquals(D('1.00'), first_discount)
228 256
 
229 257
         self.assertTrue(condition.is_satisfied(self.basket))
230 258
         # consume 2 and 9
231 259
         second_discount = self.benefit.apply(self.basket, condition=condition)
232  
-        self.assertEquals(Decimal('2.00'), second_discount)
  260
+        self.assertEquals(D('2.00'), second_discount)
233 261
 
234 262
         self.assertTrue(condition.is_satisfied(self.basket))
235 263
         # consume 3 and 8
236 264
         third_discount = self.benefit.apply(self.basket, condition=condition)
237  
-        self.assertEquals(Decimal('3.00'), third_discount)
  265
+        self.assertEquals(D('3.00'), third_discount)
238 266
 
239 267
         self.assertTrue(condition.is_satisfied(self.basket))
240 268
         # consume 4 and 7
241 269
         fourth_discount = self.benefit.apply(self.basket, condition=condition)
242  
-        self.assertEquals(Decimal('4.00'), fourth_discount)
  270
+        self.assertEquals(D('4.00'), fourth_discount)
243 271
 
244 272
         self.assertTrue(condition.is_satisfied(self.basket))
245 273
         # consume 5 and 6
246 274
         fifth_discount = self.benefit.apply(self.basket, condition=condition)
247  
-        self.assertEquals(Decimal('5.00'), fifth_discount)
  275
+        self.assertEquals(D('5.00'), fifth_discount)
248 276
 
249 277
         # end of items (one not discounted item in basket)
250 278
         self.assertFalse(condition.is_satisfied(self.basket))
251 279
 
252 280
     def test_condition_consumes_most_expensive_lines_first_when_products_are_repeated(self):
253 281
         for i in range(5, 0, -1):
254  
-            product = create_product(price=Decimal(i), title='%i'%i, upc='upc_%i' % i)
  282
+            product = create_product(price=D(i), title='%i'%i, upc='upc_%i' % i)
255 283
             self.basket.add_product(product, 2)
256 284
 
257 285
         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
260 288
         self.assertTrue(condition.is_satisfied(self.basket))
261 289
         # consume 1 and 5
262 290
         first_discount = self.benefit.apply(self.basket, condition=condition)
263  
-        self.assertEquals(Decimal('1.00'), first_discount)
  291
+        self.assertEquals(D('1.00'), first_discount)
264 292
 
265 293
         self.assertTrue(condition.is_satisfied(self.basket))
266 294
         # consume 1 and 5
267 295
         second_discount = self.benefit.apply(self.basket, condition=condition)
268  
-        self.assertEquals(Decimal('1.00'), second_discount)
  296
+        self.assertEquals(D('1.00'), second_discount)
269 297
 
270 298
         self.assertTrue(condition.is_satisfied(self.basket))
271 299
         # consume 2 and 4
272 300
         third_discount = self.benefit.apply(self.basket, condition=condition)
273  
-        self.assertEquals(Decimal('2.00'), third_discount)
  301
+        self.assertEquals(D('2.00'), third_discount)
274 302
 
275 303
         self.assertTrue(condition.is_satisfied(self.basket))
276 304
         # consume 2 and 4
277 305
         third_discount = self.benefit.apply(self.basket, condition=condition)
278  
-        self.assertEquals(Decimal('2.00'), third_discount)
  306
+        self.assertEquals(D('2.00'), third_discount)
279 307
 
280 308
         self.assertTrue(condition.is_satisfied(self.basket))
281 309
         # consume 3 and 3
282 310
         third_discount = self.benefit.apply(self.basket, condition=condition)
283  
-        self.assertEquals(Decimal('3.00'), third_discount)
  311
+        self.assertEquals(D('3.00'), third_discount)
284 312
 
285 313
         # end of items (one not discounted item in basket)
286 314
         self.assertFalse(condition.is_satisfied(self.basket))
@@ -296,12 +324,12 @@ class FixedPriceBenefitTest(OfferTest):
296 324
 
297 325
     def setUp(self):
298 326
         super(FixedPriceBenefitTest, self).setUp()
299  
-        self.benefit = models.FixedPriceBenefit(range=self.range, type="FixedPrice", value=Decimal('10.00'))
  327
+        self.benefit = models.FixedPriceBenefit(range=self.range, type="FixedPrice", value=D('10.00'))
300 328
 
301 329
     def test_correct_discount_for_count_condition(self):
302  
-        products = [create_product(Decimal('7.00')),
303  
-                    create_product(Decimal('8.00')),
304  
-                    create_product(Decimal('12.00'))]
  330
+        products = [create_product(D('7.00')),
  331
+                    create_product(D('8.00')),
  332
+                    create_product(D('12.00'))]
305 333
 
306 334
         # Create range that includes the products
307 335
         range = models.Range.objects.create(name="Dummy range")
@@ -313,13 +341,13 @@ def test_correct_discount_for_count_condition(self):
313 341
         basket = Basket.objects.create()
314 342
         [basket.add_product(p, 2) for p in products]
315 343
 
316  
-        benefit = models.FixedPriceBenefit(range=range, type="FixedPrice", value=Decimal('20.00'))
317  
-        self.assertEquals(Decimal('2.00'), benefit.apply(basket, condition))
318  
-        self.assertEquals(Decimal('12.00'), benefit.apply(basket, condition))
319  
-        self.assertEquals(Decimal('0.00'), benefit.apply(basket, condition))
  344
+        benefit = models.FixedPriceBenefit(range=range, type="FixedPrice", value=D('20.00'))
  345
+        self.assertEquals(D('2.00'), benefit.apply(basket, condition))
  346
+        self.assertEquals(D('12.00'), benefit.apply(basket, condition))
  347
+        self.assertEquals(D('0.00'), benefit.apply(basket, condition))
320 348
 
321 349
     def test_correct_discount_is_returned(self):
322  
-        products = [create_product(Decimal('8.00')), create_product(Decimal('4.00'))]
  350
+        products = [create_product(D('8.00')), create_product(D('4.00'))]
323 351
         range = models.Range.objects.create(name="Dummy range")
324 352
         for product in products:
325 353
             range.included_products.add(product)
@@ -330,10 +358,10 @@ def test_correct_discount_is_returned(self):
330 358
 
331 359
         condition = models.CoverageCondition(range=range, type="Coverage", value=2)
332 360
         discount = self.benefit.apply(basket, condition)
333  
-        self.assertEquals(Decimal('2.00'), discount)
  361
+        self.assertEquals(D('2.00'), discount)
334 362
 
335 363
     def test_no_discount_when_product_not_discountable(self):
336  
-        product = create_product(Decimal('18.00'))
  364
+        product = create_product(D('18.00'))
337 365
         product.is_discountable = False
338 366
         product.save()
339 367
 
@@ -345,10 +373,10 @@ def test_no_discount_when_product_not_discountable(self):
345 373
 
346 374
         condition = models.CoverageCondition(range=product_range, type="Coverage", value=1)
347 375
         discount = self.benefit.apply(basket, condition)
348  
-        self.assertEquals(Decimal('0.00'), discount)
  376
+        self.assertEquals(D('0.00'), discount)
349 377
 
350 378
     def test_no_discount_is_returned_when_value_is_greater_than_product_total(self):
351  
-        products = [create_product(Decimal('4.00')), create_product(Decimal('4.00'))]
  379
+        products = [create_product(D('4.00')), create_product(D('4.00'))]
352 380
         range = models.Range.objects.create(name="Dummy range")
353 381
         for product in products:
354 382
             range.included_products.add(product)
@@ -359,12 +387,12 @@ def test_no_discount_is_returned_when_value_is_greater_than_product_total(self):
359 387
 
360 388
         condition = models.CoverageCondition(range=range, type="Coverage", value=2)
361 389
         discount = self.benefit.apply(basket, condition)
362  
-        self.assertEquals(Decimal('0.00'), discount)
  390
+        self.assertEquals(D('0.00'), discount)
363 391
 
364 392
     def test_discount_when_more_products_than_required(self):
365  
-        products = [create_product(Decimal('4.00')),
366  
-                    create_product(Decimal('8.00')),
367  
-                    create_product(Decimal('12.00'))]
  393
+        products = [create_product(D('4.00')),
  394
+                    create_product(D('8.00')),
  395
+                    create_product(D('12.00'))]
368 396
 
369 397
         # Create range that includes the products
370 398
         range = models.Range.objects.create(name="Dummy range")
@@ -377,14 +405,14 @@ def test_discount_when_more_products_than_required(self):
377 405
         [basket.add_product(p) for p in products]
378 406
         basket.add_product(products[0])
379 407
 
380  
-        benefit = models.FixedPriceBenefit(range=range, type="FixedPrice", value=Decimal('20.00'))
  408
+        benefit = models.FixedPriceBenefit(range=range, type="FixedPrice", value=D('20.00'))
381 409
         discount = benefit.apply(basket, condition)
382  
-        self.assertEquals(Decimal('4.00'), discount)
  410
+        self.assertEquals(D('4.00'), discount)
383 411
 
384 412
     def test_discount_when_applied_twice(self):
385  
-        products = [create_product(Decimal('4.00')),
386  
-                    create_product(Decimal('8.00')),
387  
-                    create_product(Decimal('12.00'))]
  413
+        products = [create_product(D('4.00')),
  414
+                    create_product(D('8.00')),
  415
+                    create_product(D('12.00'))]
388 416
 
389 417
         # Create range that includes the products
390 418
         range = models.Range.objects.create(name="Dummy range")
@@ -396,8 +424,8 @@ def test_discount_when_applied_twice(self):
396 424
         basket = Basket.objects.create()
397 425
         [basket.add_product(p, 2) for p in products]
398 426
 
399  
-        benefit = models.FixedPriceBenefit(range=range, type="FixedPrice", value=Decimal('20.00'))
  427
+        benefit = models.FixedPriceBenefit(range=range, type="FixedPrice", value=D('20.00'))
400 428
         first_discount = benefit.apply(basket, condition)
401  
-        self.assertEquals(Decimal('4.00'), first_discount)
  429
+        self.assertEquals(D('4.00'), first_discount)
402 430
         second_discount = benefit.apply(basket, condition)
403  
-        self.assertEquals(Decimal('4.00'), second_discount)
  431
+        self.assertEquals(D('4.00'), second_discount)

0 notes on commit da2f16f

Please sign in to comment.
Something went wrong with that request. Please try again.