本文整理汇总了Python中oscar.apps.basket.models.Basket.max_allowed_quantity方法的典型用法代码示例。如果您正苦于以下问题:Python Basket.max_allowed_quantity方法的具体用法?Python Basket.max_allowed_quantity怎么用?Python Basket.max_allowed_quantity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oscar.apps.basket.models.Basket
的用法示例。
在下文中一共展示了Basket.max_allowed_quantity方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestANonEmptyBasket
# 需要导入模块: from oscar.apps.basket.models import Basket [as 别名]
# 或者: from oscar.apps.basket.models.Basket import max_allowed_quantity [as 别名]
#.........这里部分代码省略.........
def test_returns_correct_quantity_for_existing_product_and_stockrecord_and_options(self):
product = factories.create_product()
record = factories.create_stockrecord(
product, price_excl_tax=D('5.00'))
option = Option.objects.create(name="Message")
options = [{"option": option, "value": "2"}]
self.basket.add(product, options=options)
self.assertEqual(0, self.basket.line_quantity(
product, record))
self.assertEqual(1, self.basket.line_quantity(
product, record, options))
def test_total_sums_product_totals(self):
product = factories.create_product()
factories.create_stockrecord(
product, price_excl_tax=D('5.00'))
self.basket.add(product, 1)
self.assertEqual(self.basket.total_excl_tax, 105)
def test_totals_for_free_products(self):
basket = Basket()
basket.strategy = strategy.Default()
# Add a zero-priced product to the basket
product = factories.create_product()
factories.create_stockrecord(
product, price_excl_tax=D('0.00'), num_in_stock=10)
basket.add(product, 1)
self.assertEqual(basket.lines.count(), 1)
self.assertEqual(basket.total_excl_tax, 0)
self.assertEqual(basket.total_incl_tax, 0)
def test_basket_prices_calculation_for_unavailable_pricing(self):
new_product = factories.create_product()
factories.create_stockrecord(
new_product, price_excl_tax=D('5.00'))
self.basket.add(new_product, 1)
class UnavailableProductStrategy(strategy.Default):
""" A test strategy that makes a specific product unavailable """
def availability_policy(self, product, stockrecord):
if product == new_product:
return availability.Unavailable()
return super().availability_policy(product, stockrecord)
def pricing_policy(self, product, stockrecord):
if product == new_product:
return prices.Unavailable()
return super().pricing_policy(product, stockrecord)
self.basket.strategy = UnavailableProductStrategy()
line = self.basket.all_lines()[1]
self.assertEqual(line.get_warning(), "'D\xf9\uff4d\u03fb\u03d2 title' is no longer available")
self.assertIsNone(line.line_price_excl_tax)
self.assertIsNone(line.line_price_incl_tax)
self.assertIsNone(line.line_price_excl_tax_incl_discounts)
self.assertIsNone(line.line_price_incl_tax_incl_discounts)
self.assertIsNone(line.line_tax)
self.assertEqual(self.basket.total_excl_tax, 100)
self.assertEqual(self.basket.total_incl_tax, 100)
self.assertEqual(self.basket.total_excl_tax_excl_discounts, 100)
self.assertEqual(self.basket.total_incl_tax_excl_discounts, 100)
def test_max_allowed_quantity(self):
self.basket.add_product(self.product, quantity=3)
# max allowed here is 7 (20-10+3)
with self.settings(OSCAR_MAX_BASKET_QUANTITY_THRESHOLD=20):
max_allowed, basket_threshold = self.basket.max_allowed_quantity()
self.assertEqual(max_allowed, 7)
self.assertEqual(basket_threshold, 20)
# but we can also completely disable the threshold
with self.settings(OSCAR_MAX_BASKET_QUANTITY_THRESHOLD=None):
max_allowed, basket_threshold = self.basket.max_allowed_quantity()
self.assertEqual(max_allowed, None)
self.assertEqual(basket_threshold, None)
def test_is_quantity_allowed(self):
with self.settings(OSCAR_MAX_BASKET_QUANTITY_THRESHOLD=20):
# 7 or below is possible
allowed, message = self.basket.is_quantity_allowed(qty=7)
self.assertTrue(allowed)
self.assertIsNone(message)
# but above it's not
allowed, message = self.basket.is_quantity_allowed(qty=11)
self.assertFalse(allowed)
self.assertIsNotNone(message)
with self.settings(OSCAR_MAX_BASKET_QUANTITY_THRESHOLD=None):
# with the treshold disabled all quantities are possible
allowed, message = self.basket.is_quantity_allowed(qty=7)
self.assertTrue(allowed)
self.assertIsNone(message)
allowed, message = self.basket.is_quantity_allowed(qty=5000)
self.assertTrue(allowed)
self.assertIsNone(message)