|
|
@@ -1,6 +1,6 @@
|
|
1
|
1
|
from decimal import Decimal as D
|
|
2
|
2
|
|
|
3
|
|
-from django.test import TestCase
|
|
|
3
|
+from django.test import TestCase, override_settings
|
|
4
|
4
|
from django.conf import settings
|
|
5
|
5
|
import mock
|
|
6
|
6
|
|
|
|
@@ -65,8 +65,8 @@ class TestBasketLineForm(TestCase):
|
|
65
|
65
|
form = self.build_form(quantity=invalid_qty)
|
|
66
|
66
|
self.assertFalse(form.is_valid())
|
|
67
|
67
|
|
|
|
68
|
+ @override_settings(OSCAR_MAX_BASKET_QUANTITY_THRESHOLD=10)
|
|
68
|
69
|
def test_enforce_max_line_quantity_for_existing_product(self):
|
|
69
|
|
- settings.OSCAR_MAX_BASKET_QUANTITY_THRESHOLD = 10
|
|
70
|
70
|
self.basket.flush()
|
|
71
|
71
|
product = factories.create_product(num_in_stock=20)
|
|
72
|
72
|
add_product(self.basket, D('100'), 4, product)
|
|
|
@@ -77,6 +77,23 @@ class TestBasketLineForm(TestCase):
|
|
77
|
77
|
form = self.build_form(quantity=11)
|
|
78
|
78
|
self.assertFalse(form.is_valid())
|
|
79
|
79
|
|
|
|
80
|
+ def test_line_quantity_max_attribute_per_num_available(self):
|
|
|
81
|
+ self.basket.flush()
|
|
|
82
|
+ product = factories.create_product(num_in_stock=20)
|
|
|
83
|
+ add_product(self.basket, D('100'), 4, product)
|
|
|
84
|
+ self.line = self.basket.all_lines()[0]
|
|
|
85
|
+ form = self.build_form()
|
|
|
86
|
+ self.assertIn('max="20"', str(form['quantity']))
|
|
|
87
|
+
|
|
|
88
|
+ @override_settings(OSCAR_MAX_BASKET_QUANTITY_THRESHOLD=10)
|
|
|
89
|
+ def test_line_quantity_max_attribute_per_basket_threshold(self):
|
|
|
90
|
+ self.basket.flush()
|
|
|
91
|
+ product = factories.create_product(num_in_stock=20)
|
|
|
92
|
+ add_product(self.basket, D('100'), 4, product)
|
|
|
93
|
+ self.line = self.basket.all_lines()[0]
|
|
|
94
|
+ form = self.build_form()
|
|
|
95
|
+ self.assertIn('max="6"', str(form['quantity']))
|
|
|
96
|
+
|
|
80
|
97
|
def test_basketline_formset_ordering(self):
|
|
81
|
98
|
# when we use a unordered queryset in the Basketlineformset, the
|
|
82
|
99
|
# discounts will be lost because django will query the database
|