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


Python models.Basket类代码示例

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


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

示例1: TestAddingAProductToABasket

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,代码行数:33,代码来源:model_tests.py

示例2: test_weight_calculation_of_basket

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

示例3: TestBasketModel

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

示例4: setUp

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

示例5: test_weight_calculation_of_basket_with_line_quantity

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

示例6: setUp

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

示例7: setUp

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

示例8: StockActionTests

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

示例9: test_basket_lines_are_converted_to_xml

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

示例10: test_line_tax_for_zero_tax_strategies

    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,代码行数:10,代码来源:test_models.py

示例11: TestASubmittedBasket

class TestASubmittedBasket(TestCase):
    def setUp(self):
        self.basket = Basket()
        self.basket.strategy = strategy.Default()
        self.basket.submit()

    def test_has_correct_status(self):
        self.assertTrue(self.basket.is_submitted)

    def test_can_be_edited(self):
        self.assertFalse(self.basket.can_be_edited)
开发者ID:jduarte,项目名称:django-oscar,代码行数:11,代码来源:model_tests.py

示例12: test_totals_for_free_products

    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,代码行数:12,代码来源:test_models.py

示例13: setUp

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

示例14: test_line_tax_for_unknown_tax_strategies

    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,代码行数:15,代码来源:test_models.py

示例15: TestOrderCreatorErrorCases

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')
开发者ID:Per-Ine,项目名称:django-oscar,代码行数:15,代码来源:creator_tests.py


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