|
|
@@ -118,7 +118,7 @@ class TestLineOfferConsumer:
|
|
118
|
118
|
line.consume(99)
|
|
119
|
119
|
assert line.quantity_with_discount == 10
|
|
120
|
120
|
|
|
121
|
|
- def test_consumed_with_exclusive_offer(self, filled_basket):
|
|
|
121
|
+ def test_consumed_with_exclusive_offer_1(self, filled_basket):
|
|
122
|
122
|
offer1 = ConditionalOfferFactory(name='offer1')
|
|
123
|
123
|
offer2 = ConditionalOfferFactory(name='offer2')
|
|
124
|
124
|
offer3 = ConditionalOfferFactory(name='offer3')
|
|
|
@@ -132,7 +132,9 @@ class TestLineOfferConsumer:
|
|
132
|
132
|
|
|
133
|
133
|
line1, line2 = list(filled_basket.all_lines())
|
|
134
|
134
|
|
|
|
135
|
+ # exclusive offer consumes one item on line1
|
|
135
|
136
|
line1.consumer.consume(1, offer1)
|
|
|
137
|
+
|
|
136
|
138
|
# offer1 is exclusive so that blocks other offers
|
|
137
|
139
|
assert line1.is_available_for_offer_discount(offer2) is False
|
|
138
|
140
|
|
|
|
@@ -153,9 +155,126 @@ class TestLineOfferConsumer:
|
|
153
|
155
|
# but still room for offer3!
|
|
154
|
156
|
assert line2.is_available_for_offer_discount(offer3) is True
|
|
155
|
157
|
|
|
|
158
|
+ def test_consumed_with_exclusive_offer_2(self, filled_basket):
|
|
|
159
|
+ offer1 = ConditionalOfferFactory(name='offer1')
|
|
|
160
|
+ offer2 = ConditionalOfferFactory(name='offer2')
|
|
|
161
|
+ offer3 = ConditionalOfferFactory(name='offer3')
|
|
|
162
|
+ offer1.exclusive = True
|
|
|
163
|
+ offer2.exclusive = False
|
|
|
164
|
+ offer3.exclusive = False
|
|
|
165
|
+
|
|
|
166
|
+ for line in filled_basket.all_lines():
|
|
|
167
|
+ assert line.consumer.consumed(offer1) == 0
|
|
|
168
|
+ assert line.consumer.consumed(offer2) == 0
|
|
|
169
|
+
|
|
|
170
|
+ line1, line2 = list(filled_basket.all_lines())
|
|
|
171
|
+
|
|
|
172
|
+ # exclusive offer consumes one item on line1
|
|
|
173
|
+ line1.consumer.consume(1, offer1)
|
|
|
174
|
+ remaining1 = line1.quantity - 1
|
|
|
175
|
+
|
|
|
176
|
+ assert line1.quantity_with_offer_discount(offer1) == 1
|
|
|
177
|
+ assert line1.quantity_with_offer_discount(offer2) == 0
|
|
|
178
|
+ assert line1.quantity_with_offer_discount(offer3) == 0
|
|
|
179
|
+
|
|
|
180
|
+ assert line1.quantity_without_offer_discount(offer1) == remaining1
|
|
|
181
|
+ assert line1.quantity_without_offer_discount(offer2) == 0
|
|
|
182
|
+ assert line1.quantity_without_offer_discount(offer3) == 0
|
|
|
183
|
+
|
|
|
184
|
+ # exclusive offer consumes all items on line1
|
|
|
185
|
+ line1.consumer.consume(remaining1, offer1)
|
|
|
186
|
+ assert line1.quantity_with_offer_discount(offer1) == line1.quantity
|
|
|
187
|
+ assert line1.quantity_with_offer_discount(offer2) == 0
|
|
|
188
|
+ assert line1.quantity_with_offer_discount(offer3) == 0
|
|
|
189
|
+
|
|
|
190
|
+ assert line1.quantity_without_offer_discount(offer1) == 0
|
|
|
191
|
+ assert line1.quantity_without_offer_discount(offer2) == 0
|
|
|
192
|
+ assert line1.quantity_without_offer_discount(offer3) == 0
|
|
|
193
|
+
|
|
|
194
|
+ # non-exclusive offer consumes one item on line2
|
|
|
195
|
+ line2.consumer.consume(1, offer2)
|
|
|
196
|
+ remaining2 = line2.quantity - 1
|
|
|
197
|
+
|
|
|
198
|
+ assert line2.quantity_with_offer_discount(offer1) == 0
|
|
|
199
|
+ assert line2.quantity_with_offer_discount(offer2) == 1
|
|
|
200
|
+ assert line2.quantity_with_offer_discount(offer3) == 0
|
|
|
201
|
+
|
|
|
202
|
+ assert line2.quantity_without_offer_discount(offer1) == 0
|
|
|
203
|
+ assert line2.quantity_without_offer_discount(offer2) == remaining2
|
|
|
204
|
+ assert line2.quantity_without_offer_discount(offer3) == line2.quantity
|
|
|
205
|
+
|
|
|
206
|
+ # non-exclusive offer consumes all items on line2
|
|
|
207
|
+ line2.consumer.consume(remaining2, offer2)
|
|
|
208
|
+
|
|
|
209
|
+ assert line2.quantity_with_offer_discount(offer1) == 0
|
|
|
210
|
+ assert line2.quantity_with_offer_discount(offer2) == line2.quantity
|
|
|
211
|
+ assert line2.quantity_with_offer_discount(offer3) == 0
|
|
|
212
|
+
|
|
|
213
|
+ assert line2.quantity_without_offer_discount(offer1) == 0
|
|
|
214
|
+ assert line2.quantity_without_offer_discount(offer2) == 0
|
|
|
215
|
+ assert line2.quantity_without_offer_discount(offer3) == line2.quantity
|
|
|
216
|
+
|
|
156
|
217
|
def test_consumed_by_application(self, filled_basket, single_offer):
|
|
157
|
218
|
basket = filled_basket
|
|
158
|
219
|
Applicator().apply(basket)
|
|
159
|
220
|
assert len(basket.offer_applications.offer_discounts) == 1
|
|
160
|
|
-
|
|
161
|
221
|
assert [x.consumer.consumed() for x in basket.all_lines()] == [1, 0]
|
|
|
222
|
+
|
|
|
223
|
+ def test_consumed_with_combined_offer(self, filled_basket):
|
|
|
224
|
+ offer1 = ConditionalOfferFactory(name='offer1')
|
|
|
225
|
+ offer2 = ConditionalOfferFactory(name='offer2')
|
|
|
226
|
+ offer3 = ConditionalOfferFactory(name='offer3')
|
|
|
227
|
+ offer4 = ConditionalOfferFactory(name='offer4')
|
|
|
228
|
+ offer1.exclusive = True
|
|
|
229
|
+ offer2.exclusive = False
|
|
|
230
|
+ offer3.exclusive = False
|
|
|
231
|
+ offer4.exclusive = False
|
|
|
232
|
+ offer2.combinations.add(offer3)
|
|
|
233
|
+ assert offer3 in offer2.combined_offers
|
|
|
234
|
+ assert offer2 in offer3.combined_offers
|
|
|
235
|
+
|
|
|
236
|
+ for line in filled_basket.all_lines():
|
|
|
237
|
+ assert line.consumer.consumed(offer1) == 0
|
|
|
238
|
+ assert line.consumer.consumed(offer2) == 0
|
|
|
239
|
+ assert line.consumer.consumed(offer3) == 0
|
|
|
240
|
+
|
|
|
241
|
+ line1 = filled_basket.all_lines()[0]
|
|
|
242
|
+
|
|
|
243
|
+ # combinable offer consumes one item of line1
|
|
|
244
|
+ line1.consumer.consume(1, offer2)
|
|
|
245
|
+ remaining1 = line1.quantity - 1
|
|
|
246
|
+
|
|
|
247
|
+ assert line1.quantity_with_offer_discount(offer1) == 0
|
|
|
248
|
+ assert line1.quantity_with_offer_discount(offer2) == 1
|
|
|
249
|
+ assert line1.quantity_with_offer_discount(offer3) == 0
|
|
|
250
|
+ assert line1.quantity_with_offer_discount(offer4) == 0
|
|
|
251
|
+
|
|
|
252
|
+ assert line1.quantity_without_offer_discount(offer1) == 0
|
|
|
253
|
+ assert line1.quantity_without_offer_discount(offer2) == remaining1
|
|
|
254
|
+ assert line1.quantity_without_offer_discount(offer3) == line1.quantity
|
|
|
255
|
+ assert line1.quantity_without_offer_discount(offer4) == 0
|
|
|
256
|
+
|
|
|
257
|
+ # combinable offer consumes one item of line1
|
|
|
258
|
+ line1.consumer.consume(1, offer3)
|
|
|
259
|
+ assert line1.quantity_with_offer_discount(offer1) == 0
|
|
|
260
|
+ assert line1.quantity_with_offer_discount(offer2) == 1
|
|
|
261
|
+ assert line1.quantity_with_offer_discount(offer3) == 1
|
|
|
262
|
+ assert line1.quantity_with_offer_discount(offer4) == 0
|
|
|
263
|
+
|
|
|
264
|
+ assert line1.quantity_without_offer_discount(offer1) == 0
|
|
|
265
|
+ assert line1.quantity_without_offer_discount(offer2) == remaining1
|
|
|
266
|
+ assert line1.quantity_without_offer_discount(offer3) == remaining1
|
|
|
267
|
+ assert line1.quantity_without_offer_discount(offer4) == 0
|
|
|
268
|
+
|
|
|
269
|
+ # combinable offer consumes all items of line1
|
|
|
270
|
+ line1.consumer.consume(remaining1, offer2)
|
|
|
271
|
+
|
|
|
272
|
+ assert line1.quantity_with_offer_discount(offer1) == 0
|
|
|
273
|
+ assert line1.quantity_with_offer_discount(offer2) == line1.quantity
|
|
|
274
|
+ assert line1.quantity_with_offer_discount(offer3) == 1
|
|
|
275
|
+ assert line1.quantity_with_offer_discount(offer4) == 0
|
|
|
276
|
+
|
|
|
277
|
+ assert line1.quantity_without_offer_discount(offer1) == 0
|
|
|
278
|
+ assert line1.quantity_without_offer_discount(offer2) == 0
|
|
|
279
|
+ assert line1.quantity_without_offer_discount(offer3) == remaining1
|
|
|
280
|
+ assert line1.quantity_without_offer_discount(offer4) == 0
|