本文整理汇总了Python中oscar.apps.basket.models.Basket.add_product方法的典型用法代码示例。如果您正苦于以下问题:Python Basket.add_product方法的具体用法?Python Basket.add_product怎么用?Python Basket.add_product使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oscar.apps.basket.models.Basket
的用法示例。
在下文中一共展示了Basket.add_product方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_weight_calculation_of_basket
# 需要导入模块: from oscar.apps.basket.models import Basket [as 别名]
# 或者: from oscar.apps.basket.models.Basket import add_product [as 别名]
def test_weight_calculation_of_basket(self):
basket = Basket()
basket.add_product(create_product(attributes={'weight': 1}))
basket.add_product(create_product(attributes={'weight': 2}))
scales = Scales(attribute_code='weight')
self.assertEquals(1+2, scales.weigh_basket(basket))
示例2: test_weight_calculation_of_basket_with_line_quantity
# 需要导入模块: from oscar.apps.basket.models import Basket [as 别名]
# 或者: from oscar.apps.basket.models.Basket import add_product [as 别名]
def test_weight_calculation_of_basket_with_line_quantity(self):
basket = Basket()
basket.add_product(create_product(attributes={"weight": 1}), quantity=3)
basket.add_product(create_product(attributes={"weight": 2}), quantity=4)
scales = Scales(attribute_code="weight")
self.assertEquals(1 * 3 + 2 * 4, scales.weigh_basket(basket))
示例3: setUp
# 需要导入模块: from oscar.apps.basket.models import Basket [as 别名]
# 或者: from oscar.apps.basket.models.Basket import add_product [as 别名]
def setUp(self):
basket = Basket()
basket.add_product(create_product(price=D("10.00")), 4)
self.order = create_order(number="100002", basket=basket)
self.line = self.order.lines.all()[0]
self.order_placed, __ = ShippingEventType.objects.get_or_create(code="order_placed", name="Order placed")
self.dispatched, __ = ShippingEventType.objects.get_or_create(code="dispatched", name="Dispatched")
示例4: setUp
# 需要导入模块: from oscar.apps.basket.models import Basket [as 别名]
# 或者: from oscar.apps.basket.models.Basket import add_product [as 别名]
def setUp(self):
basket = Basket()
basket.add_product(create_product(price=D('10.00')), 4)
self.order = create_order(number='100002', basket=basket)
self.line = self.order.lines.all()[0]
self.order_placed,_ = ShippingEventType.objects.get_or_create(code='order_placed',
name='Order placed')
self.dispatched,_ = ShippingEventType.objects.get_or_create(code='dispatched',
name='Dispatched')
示例5: StockActionTests
# 需要导入模块: from oscar.apps.basket.models import Basket [as 别名]
# 或者: from oscar.apps.basket.models.Basket import add_product [as 别名]
class StockActionTests(TestCase):
def setUp(self):
self.product = create_product(price=D('12.00'), num_in_stock=5)
self.basket = Basket()
self.basket.add_product(self.product)
def tearDown(self):
StockAlert.objects.all().delete()
def set_threshold(self, threshold):
self.product.stockrecord.low_stock_threshold = threshold
self.product.stockrecord.save()
def test_stock_is_allocated_after_checkout(self):
order = OrderCreator().place_order(self.basket)
record = StockRecord.objects.get(product=self.product)
self.assertEqual(5, record.num_in_stock)
self.assertEqual(1, record.num_allocated)
self.assertEqual(4, record.net_stock_level)
def test_no_alert_raised_if_threshold_not_breached(self):
self.set_threshold(3)
order = OrderCreator().place_order(self.basket)
alerts = StockAlert.objects.all()
self.assertEqual(0, len(alerts))
def test_alert_created_when_threhold_met(self):
self.set_threshold(5)
order = OrderCreator().place_order(self.basket)
alerts = StockAlert.objects.filter(stockrecord=self.product.stockrecord)
self.assertEqual(1, len(alerts))
def test_alert_only_created_when_no_alert_exists_already(self):
self.set_threshold(5)
StockAlert.objects.create(stockrecord=self.product.stockrecord,
threshold=10)
order = OrderCreator().place_order(self.basket)
alerts = StockAlert.objects.filter(stockrecord=self.product.stockrecord)
self.assertEqual(1, len(alerts))
def test_alert_closed_when_stock_replenished(self):
self.set_threshold(5)
order = OrderCreator().place_order(self.basket)
alert = StockAlert.objects.get(stockrecord=self.product.stockrecord)
self.assertEqual(StockAlert.OPEN, alert.status)
self.product.stockrecord.num_in_stock = 15
self.product.stockrecord.save()
alert = StockAlert.objects.get(stockrecord=self.product.stockrecord)
self.assertEqual(StockAlert.CLOSED, alert.status)
示例6: test_basket_lines_are_converted_to_xml
# 需要导入模块: from oscar.apps.basket.models import Basket [as 别名]
# 或者: from oscar.apps.basket.models.Basket import add_product [as 别名]
def test_basket_lines_are_converted_to_xml(self):
product = factories.create_product(price=D('12.99'))
basket = Basket()
basket.add_product(product)
data = the3rdman.build_data_dict(
basket=basket)
doc = the3rdman.add_fraud_fields(**data)
xml = doc.toxml()
self.assertXmlElementEquals(xml, '3',
'The3rdMan.CustomerInformation.sales_channel')
示例7: TestBasketModel
# 需要导入模块: from oscar.apps.basket.models import Basket [as 别名]
# 或者: from oscar.apps.basket.models.Basket import add_product [as 别名]
class TestBasketModel(TestCase):
def setUp(self):
self.basket = Basket()
self.product = create_product()
def test_an_empty_basket_has_zero_lines(self):
self.assertEqual(0, self.basket.num_lines)
def test_new_baskets_are_empty(self):
self.assertTrue(self.basket.is_empty)
def test_adding_product_creates_line(self):
self.basket.add_product(self.product)
self.assertEqual(1, self.basket.num_lines)
def test_adding_multiproduct_line_returns_correct_number_of_items(self):
self.basket.add_product(self.product, 10)
self.assertEqual(self.basket.num_items, 10)
self.assertEqual(self.basket.num_lines, 1)
def test_add_product_creates_line(self):
self.basket.add_product(self.product)
self.assertTrue(self.basket.num_lines == 1)
def test_flushing_basket_removes_all_lines(self):
self.basket.add_product(self.product, 10)
self.assertEqual(self.basket.num_items, 10)
self.basket.flush()
self.assertEqual(self.basket.num_items, 0)
示例8: TestOrderCreatorErrorCases
# 需要导入模块: from oscar.apps.basket.models import Basket [as 别名]
# 或者: from oscar.apps.basket.models.Basket import add_product [as 别名]
class TestOrderCreatorErrorCases(TestCase):
def setUp(self):
self.creator = OrderCreator()
self.basket = Basket()
def test_raises_exception_when_empty_basket_passed(self):
with self.assertRaises(ValueError):
self.creator.place_order(basket=self.basket)
def test_raises_exception_if_duplicate_order_number_passed(self):
self.basket.add_product(create_product(price=D('12.00')))
self.creator.place_order(basket=self.basket, order_number='1234')
with self.assertRaises(ValueError):
self.creator.place_order(basket=self.basket, order_number='1234')
示例9: test_basket_lines_are_converted_to_xml
# 需要导入模块: from oscar.apps.basket.models import Basket [as 别名]
# 或者: from oscar.apps.basket.models.Basket import add_product [as 别名]
def test_basket_lines_are_converted_to_xml(self):
product = factories.create_product(price=D("12.99"))
basket = Basket()
# Nasty hack to make test suite work with both Oscar 0.5 and 0.6
try:
from oscar.apps.partner import strategy
except ImportError:
pass
else:
basket.strategy = strategy.Default()
basket.add_product(product)
data = the3rdman.build_data_dict(basket=basket)
doc = the3rdman.add_fraud_fields(**data)
xml = doc.toxml()
self.assertXmlElementEquals(xml, "3", "The3rdMan.CustomerInformation.sales_channel")
示例10: TestPlacingAnOrder
# 需要导入模块: from oscar.apps.basket.models import Basket [as 别名]
# 或者: from oscar.apps.basket.models.Basket import add_product [as 别名]
class TestPlacingAnOrder(TestCase):
def setUp(self):
self.product = create_product(price=D('12.00'), num_in_stock=5)
self.basket = Basket()
self.basket.add_product(self.product)
def set_threshold(self, threshold):
self.product.stockrecord.low_stock_threshold = threshold
self.product.stockrecord.save()
def test_correctly_allocates_stock(self):
OrderCreator().place_order(self.basket)
record = StockRecord.objects.get(product=self.product)
self.assertEqual(5, record.num_in_stock)
self.assertEqual(1, record.num_allocated)
self.assertEqual(4, record.net_stock_level)
def test_does_not_raise_an_alert_if_threshold_not_broken(self):
self.set_threshold(4)
OrderCreator().place_order(self.basket)
alerts = StockAlert.objects.all()
self.assertEqual(0, len(alerts))
def test_raises_alert_when_threshold_is_reached(self):
self.set_threshold(5)
OrderCreator().place_order(self.basket)
alerts = StockAlert.objects.filter(
stockrecord=self.product.stockrecord)
self.assertEqual(1, len(alerts))
def test_only_raises_an_alert_once(self):
self.set_threshold(5)
StockAlert.objects.create(stockrecord=self.product.stockrecord,
threshold=10)
OrderCreator().place_order(self.basket)
alerts = StockAlert.objects.filter(
stockrecord=self.product.stockrecord)
self.assertEqual(1, len(alerts))
示例11: BasketMergingTests
# 需要导入模块: from oscar.apps.basket.models import Basket [as 别名]
# 或者: from oscar.apps.basket.models.Basket import add_product [as 别名]
class BasketMergingTests(TestCase):
def setUp(self):
self.product = create_product()
self.user_basket = Basket()
self.user_basket.add_product(self.product)
self.cookie_basket = Basket()
self.cookie_basket.add_product(self.product, 2)
self.user_basket.merge(self.cookie_basket, add_quantities=False)
def test_cookie_basket_has_status_set(self):
self.assertEqual('Merged', self.cookie_basket.status)
def test_lines_are_moved_across(self):
self.assertEqual(1, self.user_basket.lines.all().count())
def test_merge_line_takes_max_quantity(self):
line = self.user_basket.lines.get(product=self.product)
self.assertEqual(2, line.quantity)
示例12: TestRestockingProduct
# 需要导入模块: from oscar.apps.basket.models import Basket [as 别名]
# 或者: from oscar.apps.basket.models.Basket import add_product [as 别名]
class TestRestockingProduct(TestCase):
def setUp(self):
self.product = create_product(price=D('12.00'), num_in_stock=5)
self.basket = Basket()
self.basket.add_product(self.product)
def set_threshold(self, threshold):
self.product.stockrecord.low_stock_threshold = threshold
self.product.stockrecord.save()
def test_closes_open_alert(self):
self.set_threshold(5)
OrderCreator().place_order(self.basket)
alert = StockAlert.objects.get(stockrecord=self.product.stockrecord)
self.assertEqual(StockAlert.OPEN, alert.status)
# Restock product
self.product.stockrecord.num_in_stock = 15
self.product.stockrecord.save()
alert = StockAlert.objects.get(stockrecord=self.product.stockrecord)
self.assertEqual(StockAlert.CLOSED, alert.status)
示例13: TestANonEmptyBasket
# 需要导入模块: from oscar.apps.basket.models import Basket [as 别名]
# 或者: from oscar.apps.basket.models.Basket import add_product [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)
示例14: test_shipping_is_free_for_nonempty_basket
# 需要导入模块: from oscar.apps.basket.models import Basket [as 别名]
# 或者: from oscar.apps.basket.models.Basket import add_product [as 别名]
def test_shipping_is_free_for_nonempty_basket(self):
basket = Basket()
basket.add_product(create_product())
self.method.set_basket(basket)
self.assertEquals(D('0.00'), self.method.basket_charge_incl_tax())
self.assertEquals(D('0.00'), self.method.basket_charge_excl_tax())
示例15: TestABasket
# 需要导入模块: from oscar.apps.basket.models import Basket [as 别名]
# 或者: from oscar.apps.basket.models.Basket import add_product [as 别名]
class TestABasket(TestCase):
def setUp(self):
self.basket = Basket()
self.product = create_product()
def test_an_empty_basket_has_zero_lines(self):
self.assertEqual(0, self.basket.num_lines)
def test_new_baskets_are_empty(self):
self.assertTrue(self.basket.is_empty)
def test_adding_product_creates_line(self):
self.basket.add_product(self.product)
self.assertEqual(1, self.basket.num_lines)
def test_adding_multiproduct_line_returns_correct_number_of_items(self):
self.basket.add_product(self.product, 10)
self.assertEqual(self.basket.num_items, 10)
self.assertEqual(self.basket.num_lines, 1)
def test_add_product_creates_line(self):
self.basket.add_product(self.product)
self.assertTrue(self.basket.num_lines == 1)
def test_add_product_sets_line_prices(self):
self.basket.add_product(self.product)
basket_line = self.basket.lines.all()[0]
self.assertEqual(basket_line.price_incl_tax, D('10.00'))
self.assertEqual(basket_line.price_excl_tax, D('10.00'))
def test_flushing_basket_removes_all_lines(self):
self.basket.add_product(self.product, 10)
self.assertEqual(self.basket.num_items, 10)
self.basket.flush()
self.assertEqual(self.basket.num_items, 0)
def test_returns_correct_quantity_for_missing_product(self):
self.assertEqual(0, self.basket.line_quantity(self.product))
def test_returns_correct_quantity_for_existing_product(self):
self.basket.add_product(self.product)
self.assertEqual(1, self.basket.line_quantity(self.product))
def test_returns_correct_quantity_for_existing_product_with_options(self):
option = Option.objects.create(name="Message")
options = [{"option": option, "value": "2"}]
self.basket.add_product(self.product, options=options)
self.assertEqual(0, self.basket.line_quantity(self.product))
self.assertEqual(1, self.basket.line_quantity(self.product, options))
def test_has_method_to_test_if_submitted(self):
self.basket.set_as_submitted()
self.assertTrue(self.basket.is_submitted())