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


Python Basket.line_quantity方法代码示例

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


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

示例1: TestAddingAProductToABasket

# 需要导入模块: from oscar.apps.basket.models import Basket [as 别名]
# 或者: from oscar.apps.basket.models.Basket import line_quantity [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.purchase_info = factories.create_purchase_info(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.purchase_info.price.incl_tax)
        self.assertEqual(line.price_excl_tax, self.purchase_info.price.excl_tax)

    def test_adding_negative_quantity(self):
        self.assertEqual(1, self.basket.num_lines)
        self.basket.add(self.product, quantity=4)
        self.assertEqual(5, self.basket.line_quantity(self.product, self.record))
        self.basket.add(self.product, quantity=-10)
        self.assertEqual(0, self.basket.line_quantity(self.product, self.record))

    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:AdrianRibao,项目名称:django-oscar,代码行数:35,代码来源:model_tests.py

示例2: TestABasket

# 需要导入模块: from oscar.apps.basket.models import Basket [as 别名]
# 或者: from oscar.apps.basket.models.Basket import line_quantity [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))
        self.assertEqual(1, self.basket.product_quantity(self.product))

    def test_has_method_to_test_if_submitted(self):
        self.basket.set_as_submitted()
        self.assertTrue(self.basket.is_submitted())
开发者ID:AndreaCrotti,项目名称:django-oscar,代码行数:57,代码来源:basket_tests.py

示例3: TestANonEmptyBasket

# 需要导入模块: from oscar.apps.basket.models import Basket [as 别名]
# 或者: from oscar.apps.basket.models.Basket import line_quantity [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

示例4: TestANonEmptyBasket

# 需要导入模块: from oscar.apps.basket.models import Basket [as 别名]
# 或者: from oscar.apps.basket.models.Basket import line_quantity [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

示例5: TestANonEmptyBasket

# 需要导入模块: from oscar.apps.basket.models import Basket [as 别名]
# 或者: from oscar.apps.basket.models.Basket import line_quantity [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.line_quantity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。