|
|
@@ -60,7 +60,7 @@ def multi_offers():
|
|
60
|
60
|
class TestLineOfferConsumer:
|
|
61
|
61
|
def test_consumed_no_offer(self, filled_basket):
|
|
62
|
62
|
for line in filled_basket.all_lines():
|
|
63
|
|
- assert line.consumer.consumed() == 0
|
|
|
63
|
+ assert line.discounts.num_consumed() == 0
|
|
64
|
64
|
|
|
65
|
65
|
def test_available_with_offer(self):
|
|
66
|
66
|
basket = BasketFactory()
|
|
|
@@ -78,8 +78,8 @@ class TestLineOfferConsumer:
|
|
78
|
78
|
|
|
79
|
79
|
offer1 = ConditionalOfferFactory(name="offer1", benefit=benefit)
|
|
80
|
80
|
lines = basket.all_lines()
|
|
81
|
|
- assert lines[0].consumer.available(offer1) == 1
|
|
82
|
|
- assert lines[1].consumer.available(offer1) == 10
|
|
|
81
|
+ assert lines[0].discounts.available(offer1) == 1
|
|
|
82
|
+ assert lines[1].discounts.available(offer1) == 10
|
|
83
|
83
|
|
|
84
|
84
|
def test_consumed_with_offer(self, filled_basket):
|
|
85
|
85
|
offer1 = ConditionalOfferFactory(name="offer1")
|
|
|
@@ -88,31 +88,31 @@ class TestLineOfferConsumer:
|
|
88
|
88
|
offer2.exclusive = False
|
|
89
|
89
|
|
|
90
|
90
|
for line in filled_basket.all_lines():
|
|
91
|
|
- assert line.consumer.consumed(offer1) == 0
|
|
92
|
|
- assert line.consumer.consumed(offer2) == 0
|
|
|
91
|
+ assert line.discounts.num_consumed(offer1) == 0
|
|
|
92
|
+ assert line.discounts.num_consumed(offer2) == 0
|
|
93
|
93
|
|
|
94
|
94
|
line1 = filled_basket.all_lines()[0]
|
|
95
|
95
|
line2 = filled_basket.all_lines()[1]
|
|
96
|
96
|
|
|
97
|
|
- line1.consumer.consume(1, offer1)
|
|
98
|
|
- assert line1.consumer.consumed() == 1
|
|
99
|
|
- assert line1.consumer.consumed(offer1) == 1
|
|
100
|
|
- assert line1.consumer.consumed(offer2) == 0
|
|
|
97
|
+ line1.discounts.consume(1, offer1)
|
|
|
98
|
+ assert line1.discounts.num_consumed() == 1
|
|
|
99
|
+ assert line1.discounts.num_consumed(offer1) == 1
|
|
|
100
|
+ assert line1.discounts.num_consumed(offer2) == 0
|
|
101
|
101
|
|
|
102
|
|
- line1.consumer.consume(9, offer1)
|
|
103
|
|
- assert line1.consumer.consumed() == line1.quantity
|
|
104
|
|
- assert line1.consumer.consumed(offer1) == line1.quantity
|
|
105
|
|
- assert line1.consumer.consumed(offer2) == 0
|
|
|
102
|
+ line1.discounts.consume(9, offer1)
|
|
|
103
|
+ assert line1.discounts.num_consumed() == line1.quantity
|
|
|
104
|
+ assert line1.discounts.num_consumed(offer1) == line1.quantity
|
|
|
105
|
+ assert line1.discounts.num_consumed(offer2) == 0
|
|
106
|
106
|
|
|
107
|
|
- line1.consumer.consume(99, offer1)
|
|
108
|
|
- assert line1.consumer.consumed(offer1) == line1.quantity
|
|
109
|
|
- assert line1.consumer.consumed(offer2) == 0
|
|
|
107
|
+ line1.discounts.consume(99, offer1)
|
|
|
108
|
+ assert line1.discounts.num_consumed(offer1) == line1.quantity
|
|
|
109
|
+ assert line1.discounts.num_consumed(offer2) == 0
|
|
110
|
110
|
|
|
111
|
|
- line1.consumer.consume(1, offer2)
|
|
112
|
|
- line2.consumer.consume(1, offer2)
|
|
|
111
|
+ line1.discounts.consume(1, offer2)
|
|
|
112
|
+ line2.discounts.consume(1, offer2)
|
|
113
|
113
|
|
|
114
|
|
- assert line1.consumer.consumed(offer2) == 1
|
|
115
|
|
- assert line2.consumer.consumed(offer2) == 1
|
|
|
114
|
+ assert line1.discounts.num_consumed(offer2) == 1
|
|
|
115
|
+ assert line2.discounts.num_consumed(offer2) == 1
|
|
116
|
116
|
|
|
117
|
117
|
def test_consume(self, filled_basket):
|
|
118
|
118
|
line = filled_basket.all_lines()[0]
|
|
|
@@ -130,29 +130,29 @@ class TestLineOfferConsumer:
|
|
130
|
130
|
offer3.exclusive = False
|
|
131
|
131
|
|
|
132
|
132
|
for line in filled_basket.all_lines():
|
|
133
|
|
- assert line.consumer.consumed(offer1) == 0
|
|
134
|
|
- assert line.consumer.consumed(offer2) == 0
|
|
|
133
|
+ assert line.discounts.num_consumed(offer1) == 0
|
|
|
134
|
+ assert line.discounts.num_consumed(offer2) == 0
|
|
135
|
135
|
|
|
136
|
136
|
line1, line2 = list(filled_basket.all_lines())
|
|
137
|
137
|
|
|
138
|
138
|
# exclusive offer consumes one item on line1
|
|
139
|
|
- line1.consumer.consume(1, offer1)
|
|
|
139
|
+ line1.discounts.consume(1, offer1)
|
|
140
|
140
|
|
|
141
|
141
|
# offer1 is exclusive so that blocks other offers
|
|
142
|
142
|
assert line1.is_available_for_offer_discount(offer2) is False
|
|
143
|
143
|
|
|
144
|
|
- line1.consumer.consume(99, offer1)
|
|
|
144
|
+ line1.discounts.consume(99, offer1)
|
|
145
|
145
|
# ran out of room for offer1
|
|
146
|
146
|
assert line1.is_available_for_offer_discount(offer1) is False
|
|
147
|
147
|
# offer2 was never an option
|
|
148
|
148
|
assert line1.is_available_for_offer_discount(offer2) is False
|
|
149
|
149
|
|
|
150
|
150
|
# exclusivity is per line so line2 is available for offer2
|
|
151
|
|
- line2.consumer.consume(1, offer2)
|
|
|
151
|
+ line2.discounts.consume(1, offer2)
|
|
152
|
152
|
# nope: exclusive and non-exclusive don't mix
|
|
153
|
153
|
assert line2.is_available_for_offer_discount(offer1) is False
|
|
154
|
154
|
|
|
155
|
|
- line2.consumer.consume(99, offer2)
|
|
|
155
|
+ line2.discounts.consume(99, offer2)
|
|
156
|
156
|
# ran out of room for offer2
|
|
157
|
157
|
assert line2.is_available_for_offer_discount(offer1) is False
|
|
158
|
158
|
# but still room for offer3!
|
|
|
@@ -167,13 +167,13 @@ class TestLineOfferConsumer:
|
|
167
|
167
|
offer3.exclusive = False
|
|
168
|
168
|
|
|
169
|
169
|
for line in filled_basket.all_lines():
|
|
170
|
|
- assert line.consumer.consumed(offer1) == 0
|
|
171
|
|
- assert line.consumer.consumed(offer2) == 0
|
|
|
170
|
+ assert line.discounts.num_consumed(offer1) == 0
|
|
|
171
|
+ assert line.discounts.num_consumed(offer2) == 0
|
|
172
|
172
|
|
|
173
|
173
|
line1, line2 = list(filled_basket.all_lines())
|
|
174
|
174
|
|
|
175
|
175
|
# exclusive offer consumes one item on line1
|
|
176
|
|
- line1.consumer.consume(1, offer1)
|
|
|
176
|
+ line1.discounts.consume(1, offer1)
|
|
177
|
177
|
remaining1 = line1.quantity - 1
|
|
178
|
178
|
|
|
179
|
179
|
assert line1.quantity_with_offer_discount(offer1) == 1
|
|
|
@@ -185,7 +185,7 @@ class TestLineOfferConsumer:
|
|
185
|
185
|
assert line1.quantity_without_offer_discount(offer3) == 0
|
|
186
|
186
|
|
|
187
|
187
|
# exclusive offer consumes all items on line1
|
|
188
|
|
- line1.consumer.consume(remaining1, offer1)
|
|
|
188
|
+ line1.discounts.consume(remaining1, offer1)
|
|
189
|
189
|
assert line1.quantity_with_offer_discount(offer1) == line1.quantity
|
|
190
|
190
|
assert line1.quantity_with_offer_discount(offer2) == 0
|
|
191
|
191
|
assert line1.quantity_with_offer_discount(offer3) == 0
|
|
|
@@ -195,7 +195,7 @@ class TestLineOfferConsumer:
|
|
195
|
195
|
assert line1.quantity_without_offer_discount(offer3) == 0
|
|
196
|
196
|
|
|
197
|
197
|
# non-exclusive offer consumes one item on line2
|
|
198
|
|
- line2.consumer.consume(1, offer2)
|
|
|
198
|
+ line2.discounts.consume(1, offer2)
|
|
199
|
199
|
remaining2 = line2.quantity - 1
|
|
200
|
200
|
|
|
201
|
201
|
assert line2.quantity_with_offer_discount(offer1) == 0
|
|
|
@@ -207,7 +207,7 @@ class TestLineOfferConsumer:
|
|
207
|
207
|
assert line2.quantity_without_offer_discount(offer3) == line2.quantity
|
|
208
|
208
|
|
|
209
|
209
|
# non-exclusive offer consumes all items on line2
|
|
210
|
|
- line2.consumer.consume(remaining2, offer2)
|
|
|
210
|
+ line2.discounts.consume(remaining2, offer2)
|
|
211
|
211
|
|
|
212
|
212
|
assert line2.quantity_with_offer_discount(offer1) == 0
|
|
213
|
213
|
assert line2.quantity_with_offer_discount(offer2) == line2.quantity
|
|
|
@@ -222,7 +222,7 @@ class TestLineOfferConsumer:
|
|
222
|
222
|
basket = filled_basket
|
|
223
|
223
|
Applicator().apply(basket)
|
|
224
|
224
|
assert len(basket.offer_applications.offer_discounts) == 1
|
|
225
|
|
- assert [x.consumer.consumed() for x in basket.all_lines()] == [1, 0]
|
|
|
225
|
+ assert [x.discounts.num_consumed() for x in basket.all_lines()] == [1, 0]
|
|
226
|
226
|
|
|
227
|
227
|
def test_apply_multiple_vouchers(self, filled_basket):
|
|
228
|
228
|
offer1 = ConditionalOfferFactory(
|
|
|
@@ -264,14 +264,14 @@ class TestLineOfferConsumer:
|
|
264
|
264
|
assert offer2 in offer3.combined_offers
|
|
265
|
265
|
|
|
266
|
266
|
for line in filled_basket.all_lines():
|
|
267
|
|
- assert line.consumer.consumed(offer1) == 0
|
|
268
|
|
- assert line.consumer.consumed(offer2) == 0
|
|
269
|
|
- assert line.consumer.consumed(offer3) == 0
|
|
|
267
|
+ assert line.discounts.num_consumed(offer1) == 0
|
|
|
268
|
+ assert line.discounts.num_consumed(offer2) == 0
|
|
|
269
|
+ assert line.discounts.num_consumed(offer3) == 0
|
|
270
|
270
|
|
|
271
|
271
|
line1 = filled_basket.all_lines()[0]
|
|
272
|
272
|
|
|
273
|
273
|
# combinable offer consumes one item of line1
|
|
274
|
|
- line1.consumer.consume(1, offer2)
|
|
|
274
|
+ line1.discounts.consume(1, offer2)
|
|
275
|
275
|
remaining1 = line1.quantity - 1
|
|
276
|
276
|
|
|
277
|
277
|
assert line1.quantity_with_offer_discount(offer1) == 0
|
|
|
@@ -285,7 +285,7 @@ class TestLineOfferConsumer:
|
|
285
|
285
|
assert line1.quantity_without_offer_discount(offer4) == 0
|
|
286
|
286
|
|
|
287
|
287
|
# combinable offer consumes one item of line1
|
|
288
|
|
- line1.consumer.consume(1, offer3)
|
|
|
288
|
+ line1.discounts.consume(1, offer3)
|
|
289
|
289
|
assert line1.quantity_with_offer_discount(offer1) == 0
|
|
290
|
290
|
assert line1.quantity_with_offer_discount(offer2) == 1
|
|
291
|
291
|
assert line1.quantity_with_offer_discount(offer3) == 1
|
|
|
@@ -297,7 +297,7 @@ class TestLineOfferConsumer:
|
|
297
|
297
|
assert line1.quantity_without_offer_discount(offer4) == 0
|
|
298
|
298
|
|
|
299
|
299
|
# combinable offer consumes all items of line1
|
|
300
|
|
- line1.consumer.consume(remaining1, offer2)
|
|
|
300
|
+ line1.discounts.consume(remaining1, offer2)
|
|
301
|
301
|
|
|
302
|
302
|
assert line1.quantity_with_offer_discount(offer1) == 0
|
|
303
|
303
|
assert line1.quantity_with_offer_discount(offer2) == line1.quantity
|