|
|
@@ -1,4 +1,6 @@
|
|
1
|
1
|
import httplib
|
|
|
2
|
+from mock import patch
|
|
|
3
|
+from decimal import Decimal as D
|
|
2
|
4
|
|
|
3
|
5
|
from django.test.client import Client
|
|
4
|
6
|
from django.contrib.auth.models import User
|
|
|
@@ -123,7 +125,7 @@ class AuthStaffRedirectTests(TestCase):
|
|
123
|
125
|
|
|
124
|
126
|
class ReorderTests(ClientTestCase):
|
|
125
|
127
|
|
|
126
|
|
- def test_can_reorder_product(self):
|
|
|
128
|
+ def test_can_reorder(self):
|
|
127
|
129
|
order = create_order(user=self.user)
|
|
128
|
130
|
Basket.objects.all().delete()
|
|
129
|
131
|
|
|
|
@@ -179,4 +181,49 @@ class ReorderTests(ClientTestCase):
|
|
179
|
181
|
{'action': 'reorder'})
|
|
180
|
182
|
|
|
181
|
183
|
basket = Basket.objects.all()[0]
|
|
182
|
|
- self.assertEquals(len(basket.all_lines()), 0)
|
|
|
184
|
+ self.assertEquals(len(basket.all_lines()), 0)
|
|
|
185
|
+
|
|
|
186
|
+ @patch('django.conf.settings.OSCAR_MAX_BASKET_QUANTITY_THRESHOLD', 1)
|
|
|
187
|
+ def test_cannot_reorder_when_basket_maximum_exceeded(self):
|
|
|
188
|
+ order = create_order(user=self.user)
|
|
|
189
|
+ line = order.lines.all()[0]
|
|
|
190
|
+
|
|
|
191
|
+ Basket.objects.all().delete()
|
|
|
192
|
+ #add a product
|
|
|
193
|
+ product = create_product(price=D('12.00'))
|
|
|
194
|
+ self.client.post(reverse('basket:add'), {'product_id': product.id,
|
|
|
195
|
+ 'quantity': 1})
|
|
|
196
|
+
|
|
|
197
|
+
|
|
|
198
|
+ basket = Basket.objects.all()[0]
|
|
|
199
|
+ self.assertEquals(len(basket.all_lines()), 1)
|
|
|
200
|
+
|
|
|
201
|
+ #try to reorder a product
|
|
|
202
|
+ response = self.client.post(reverse('customer:order',
|
|
|
203
|
+ args=(order.number,)),
|
|
|
204
|
+ {'order_id': order.pk,
|
|
|
205
|
+ 'action': 'reorder'})
|
|
|
206
|
+
|
|
|
207
|
+ self.assertEqual(len(basket.all_lines()), 1)
|
|
|
208
|
+ self.assertNotEqual(line.product.pk, product.pk)
|
|
|
209
|
+
|
|
|
210
|
+ @patch('django.conf.settings.OSCAR_MAX_BASKET_QUANTITY_THRESHOLD', 1)
|
|
|
211
|
+ def test_cannot_reorder_line_when_basket_maximum_exceeded(self):
|
|
|
212
|
+ order = create_order(user=self.user)
|
|
|
213
|
+ line = order.lines.all()[0]
|
|
|
214
|
+
|
|
|
215
|
+ Basket.objects.all().delete()
|
|
|
216
|
+ #add a product
|
|
|
217
|
+ product = create_product(price=D('12.00'))
|
|
|
218
|
+ self.client.post(reverse('basket:add'), {'product_id': product.id,
|
|
|
219
|
+ 'quantity': 1})
|
|
|
220
|
+
|
|
|
221
|
+ basket = Basket.objects.all()[0]
|
|
|
222
|
+ self.assertEquals(len(basket.all_lines()), 1)
|
|
|
223
|
+
|
|
|
224
|
+ response = self.client.post(reverse('customer:order-line',
|
|
|
225
|
+ args=(order.number, line.pk)),
|
|
|
226
|
+ {'action': 'reorder'})
|
|
|
227
|
+
|
|
|
228
|
+ self.assertEquals(len(basket.all_lines()), 1)
|
|
|
229
|
+ self.assertNotEqual(line.product.pk, product.pk)
|