|
|
@@ -16,7 +16,7 @@ from oscar.apps.partner import strategy
|
|
16
|
16
|
from oscar.core.compat import get_user_model
|
|
17
|
17
|
from oscar.test import factories
|
|
18
|
18
|
from oscar.test.basket import add_product
|
|
19
|
|
-from oscar.test.factories import create_product
|
|
|
19
|
+from oscar.test.factories import OptionFactory, create_product
|
|
20
|
20
|
from oscar.test.testcases import WebTestCase
|
|
21
|
21
|
|
|
22
|
22
|
User = get_user_model()
|
|
|
@@ -482,3 +482,39 @@ class BasketFormSetTests(WebTestCase):
|
|
482
|
482
|
self.assertFalse(response.context['formset'].forms[0].is_valid())
|
|
483
|
483
|
self.assertEqual(basket.lines.count(), 1)
|
|
484
|
484
|
self.assertEqual(basket.lines.all()[0].quantity, 1)
|
|
|
485
|
+
|
|
|
486
|
+ def test_formset_quantity_update_with_options(self):
|
|
|
487
|
+ product = create_product(num_in_stock=2)
|
|
|
488
|
+ option = OptionFactory()
|
|
|
489
|
+ # Add the option to the product class
|
|
|
490
|
+ product.get_product_class().options.add(option)
|
|
|
491
|
+
|
|
|
492
|
+ basket = factories.create_basket(empty=True)
|
|
|
493
|
+ basket.owner = self.user
|
|
|
494
|
+ basket.save()
|
|
|
495
|
+ basket.add_product(product, options=[{"option": option, "value": "Test 1"}])
|
|
|
496
|
+ basket.add_product(product, options=[{"option": option, "value": "Test 2"}])
|
|
|
497
|
+
|
|
|
498
|
+ response = self.get(reverse('basket:summary'))
|
|
|
499
|
+ formset = response.context['formset']
|
|
|
500
|
+ self.assertEqual(len(formset.forms), 2)
|
|
|
501
|
+
|
|
|
502
|
+ # Now update one of the quantities to 2
|
|
|
503
|
+ data = {
|
|
|
504
|
+ formset.add_prefix('TOTAL_FORMS'): formset.management_form.initial['TOTAL_FORMS'],
|
|
|
505
|
+ formset.add_prefix('INITIAL_FORMS'): formset.management_form.initial['INITIAL_FORMS'],
|
|
|
506
|
+ formset.add_prefix('MIN_NUM_FORMS'): formset.management_form.initial['MIN_NUM_FORMS'],
|
|
|
507
|
+ formset.add_prefix('MAX_NUM_FORMS'): formset.management_form.initial['MAX_NUM_FORMS'],
|
|
|
508
|
+ formset.forms[0].add_prefix('id'): formset.forms[0].instance.pk,
|
|
|
509
|
+ formset.forms[0].add_prefix('quantity'): 2,
|
|
|
510
|
+ formset.forms[1].add_prefix('id'): formset.forms[1].instance.pk,
|
|
|
511
|
+ formset.forms[1].add_prefix('quantity'): formset.forms[1].instance.quantity,
|
|
|
512
|
+ }
|
|
|
513
|
+ response = self.post(reverse('basket:summary'), params=data, xhr=True)
|
|
|
514
|
+
|
|
|
515
|
+ self.assertEqual(response.status_code, 200)
|
|
|
516
|
+ self.assertFalse(response.context['formset'].forms[0].is_valid())
|
|
|
517
|
+ self.assertIn(
|
|
|
518
|
+ "can be bought which has been exceeded because you have multiple lines of the same product.",
|
|
|
519
|
+ str(response.context['formset'].forms[0].errors)
|
|
|
520
|
+ )
|