当前位置: 首页>>代码示例>>Python>>正文


Python Basket.add方法代码示例

本文整理汇总了Python中oscar.apps.basket.models.Basket.add方法的典型用法代码示例。如果您正苦于以下问题:Python Basket.add方法的具体用法?Python Basket.add怎么用?Python Basket.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在oscar.apps.basket.models.Basket的用法示例。


在下文中一共展示了Basket.add方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestAddingAProductToABasket

# 需要导入模块: from oscar.apps.basket.models import Basket [as 别名]
# 或者: from oscar.apps.basket.models.Basket import add [as 别名]
class TestAddingAProductToABasket(TestCase):

    def setUp(self):
        self.basket = Basket()
        self.basket.strategy = strategy.Default()
        self.product = factories.create_product()
        self.record = factories.create_stockrecord(
            currency='GBP',
            product=self.product, price_excl_tax=D('10.00'))
        self.stockinfo = factories.create_stockinfo(self.record)
        self.basket.add(self.product)

    def test_creates_a_line(self):
        self.assertEqual(1, self.basket.num_lines)

    def test_sets_line_prices(self):
        line = self.basket.lines.all()[0]
        self.assertEqual(line.price_incl_tax, self.stockinfo.price.incl_tax)
        self.assertEqual(line.price_excl_tax, self.stockinfo.price.excl_tax)

    def test_means_another_currency_product_cannot_be_added(self):
        product = factories.create_product()
        factories.create_stockrecord(
            currency='USD', product=product, price_excl_tax=D('20.00'))
        with self.assertRaises(ValueError):
            self.basket.add(product)
开发者ID:ButchershopCreative,项目名称:django-oscar,代码行数:28,代码来源:model_tests.py

示例2: test_line_tax_for_zero_tax_strategies

# 需要导入模块: from oscar.apps.basket.models import Basket [as 别名]
# 或者: from oscar.apps.basket.models.Basket import add [as 别名]
    def test_line_tax_for_zero_tax_strategies(self):
        basket = Basket()
        basket.strategy = strategy.Default()
        product = factories.create_product()
        # Tax for the default strategy will be 0
        factories.create_stockrecord(
            product, price_excl_tax=D('75.00'), num_in_stock=10)
        basket.add(product, 1)

        self.assertEqual(basket.lines.first().line_tax, D('0'))
开发者ID:django-oscar,项目名称:django-oscar,代码行数:12,代码来源:test_models.py

示例3: test_totals_for_free_products

# 需要导入模块: from oscar.apps.basket.models import Basket [as 别名]
# 或者: from oscar.apps.basket.models.Basket import add [as 别名]
    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)
开发者ID:django-oscar,项目名称:django-oscar,代码行数:14,代码来源:test_models.py

示例4: test_line_tax_for_unknown_tax_strategies

# 需要导入模块: from oscar.apps.basket.models import Basket [as 别名]
# 或者: from oscar.apps.basket.models.Basket import add [as 别名]
    def test_line_tax_for_unknown_tax_strategies(self):

        class UnknownTaxStrategy(strategy.Default):
            """ A test strategy where the tax is not known """

            def pricing_policy(self, product, stockrecord):
                return prices.FixedPrice('GBP', stockrecord.price_excl_tax, tax=None)

        basket = Basket()
        basket.strategy = UnknownTaxStrategy()
        product = factories.create_product()
        factories.create_stockrecord(product, num_in_stock=10)
        basket.add(product, 1)

        self.assertEqual(basket.lines.first().line_tax, None)
开发者ID:django-oscar,项目名称:django-oscar,代码行数:17,代码来源:test_models.py

示例5: TestANonEmptyBasket

# 需要导入模块: from oscar.apps.basket.models import Basket [as 别名]
# 或者: from oscar.apps.basket.models.Basket import add [as 别名]
class TestANonEmptyBasket(TestCase):

    def setUp(self):
        self.basket = Basket()
        self.basket.strategy = strategy.Default()
        self.product = factories.create_product()
        self.record = factories.create_stockrecord(
            self.product, price_excl_tax=D('10.00'))
        self.stockinfo = factories.create_stockinfo(self.record)
        self.basket.add(self.product, 10)

    def test_can_be_flushed(self):
        self.basket.flush()
        self.assertEqual(self.basket.num_items, 0)

    def test_returns_correct_product_quantity(self):
        self.assertEqual(10, self.basket.product_quantity(
            self.product))

    def test_returns_correct_line_quantity_for_existing_product_and_stockrecord(self):
        self.assertEqual(10, self.basket.line_quantity(
            self.product, self.record))

    def test_returns_zero_line_quantity_for_alternative_stockrecord(self):
        record = factories.create_stockrecord(
            self.product, price_excl_tax=D('5.00'))
        self.assertEqual(0, self.basket.line_quantity(
            self.product, record))

    def test_returns_zero_line_quantity_for_missing_product_and_stockrecord(self):
        product = factories.create_product()
        record = factories.create_stockrecord(
            product, price_excl_tax=D('5.00'))
        self.assertEqual(0, self.basket.line_quantity(
            product, record))

    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))
开发者ID:ButchershopCreative,项目名称:django-oscar,代码行数:50,代码来源:model_tests.py

示例6: TestMergingTwoBaskets

# 需要导入模块: from oscar.apps.basket.models import Basket [as 别名]
# 或者: from oscar.apps.basket.models.Basket import add [as 别名]
class TestMergingTwoBaskets(TestCase):
    def setUp(self):
        self.product = factories.create_product()
        self.record = factories.create_stockrecord(self.product, price_excl_tax=D("10.00"))
        self.purchase_info = factories.create_purchase_info(self.record)

        self.main_basket = Basket()
        self.main_basket.strategy = strategy.Default()
        self.main_basket.add(self.product, quantity=2)

        self.merge_basket = Basket()
        self.merge_basket.strategy = strategy.Default()
        self.merge_basket.add(self.product, quantity=1)

        self.main_basket.merge(self.merge_basket)

    def test_doesnt_sum_quantities(self):
        self.assertEquals(1, self.main_basket.num_lines)

    def test_changes_status_of_merge_basket(self):
        self.assertEquals(Basket.MERGED, self.merge_basket.status)
开发者ID:jduarte,项目名称:django-oscar,代码行数:23,代码来源:model_tests.py

示例7: TestANonEmptyBasket

# 需要导入模块: from oscar.apps.basket.models import Basket [as 别名]
# 或者: from oscar.apps.basket.models.Basket import add [as 别名]
class TestANonEmptyBasket(TestCase):

    def setUp(self):
        self.basket = Basket()
        self.basket.strategy = strategy.Default()
        self.product = factories.create_product()
        self.record = factories.create_stockrecord(
            self.product, price_excl_tax=D('10.00'))
        self.purchase_info = factories.create_purchase_info(self.record)
        self.basket.add(self.product, 10)

    def test_can_be_flushed(self):
        self.basket.flush()
        self.assertEqual(self.basket.num_items, 0)

    def test_returns_correct_product_quantity(self):
        self.assertEqual(10, self.basket.product_quantity(
            self.product))

    def test_returns_correct_line_quantity_for_existing_product_and_stockrecord(self):
        self.assertEqual(10, self.basket.line_quantity(
            self.product, self.record))

    def test_returns_zero_line_quantity_for_alternative_stockrecord(self):
        record = factories.create_stockrecord(
            self.product, price_excl_tax=D('5.00'))
        self.assertEqual(0, self.basket.line_quantity(
            self.product, record))

    def test_returns_zero_line_quantity_for_missing_product_and_stockrecord(self):
        product = factories.create_product()
        record = factories.create_stockrecord(
            product, price_excl_tax=D('5.00'))
        self.assertEqual(0, self.basket.line_quantity(
            product, record))

    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)
#.........这里部分代码省略.........
开发者ID:django-oscar,项目名称:django-oscar,代码行数:103,代码来源:test_models.py

示例8: TestANonEmptyBasket

# 需要导入模块: from oscar.apps.basket.models import Basket [as 别名]
# 或者: from oscar.apps.basket.models.Basket import add [as 别名]
class TestANonEmptyBasket(TestCase):

    def setUp(self):
        self.basket = Basket()
        self.basket.strategy = strategy.Default()
        self.product = factories.create_product()
        self.record = factories.create_stockrecord(
            self.product, price_excl_tax=D('10.00'))
        self.purchase_info = factories.create_purchase_info(self.record)
        self.basket.add(self.product, 10)

    def test_can_be_flushed(self):
        self.basket.flush()
        self.assertEqual(self.basket.num_items, 0)

    def test_returns_correct_product_quantity(self):
        self.assertEqual(10, self.basket.product_quantity(
            self.product))

    def test_returns_correct_line_quantity_for_existing_product_and_stockrecord(self):
        self.assertEqual(10, self.basket.line_quantity(
            self.product, self.record))

    def test_returns_zero_line_quantity_for_alternative_stockrecord(self):
        record = factories.create_stockrecord(
            self.product, price_excl_tax=D('5.00'))
        self.assertEqual(0, self.basket.line_quantity(
            self.product, record))

    def test_returns_zero_line_quantity_for_missing_product_and_stockrecord(self):
        product = factories.create_product()
        record = factories.create_stockrecord(
            product, price_excl_tax=D('5.00'))
        self.assertEqual(0, self.basket.line_quantity(
            product, record))

    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_total_excludes_unavailable_products_with_unknown_price(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(UnavailableProductStrategy, self).availability_policy(product, stockrecord)

            def pricing_policy(self, product, stockrecord):
                if product == new_product:
                    return prices.Unavailable()
                return super(UnavailableProductStrategy, self).pricing_policy(product, stockrecord)


        try:
            self.basket.strategy = UnavailableProductStrategy()
            self.assertEqual(self.basket.all_lines()[1].get_warning(), u"'D\xf9\uff4d\u03fb\u03d2 title' is no longer available")
            self.assertEqual(self.basket.total_excl_tax, 100)
        finally:
            self.basket.strategy = strategy.Default()
开发者ID:AdrianRibao,项目名称:django-oscar,代码行数:84,代码来源:model_tests.py


注:本文中的oscar.apps.basket.models.Basket.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。