示例#1
0
 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)
示例#2
0
 def setUp(self):
     self.product = create_product(num_in_stock=10)
     self.user_basket = Basket()
     self.user_basket.strategy = strategy.Default()
     add_product(self.user_basket, product=self.product)
     self.cookie_basket = Basket()
     self.cookie_basket.strategy = strategy.Default()
     add_product(self.cookie_basket, quantity=2, product=self.product)
     self.user_basket.merge(self.cookie_basket, add_quantities=False)
示例#3
0
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)
示例#4
0
    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'))
示例#5
0
    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)
示例#6
0
    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)
示例#7
0
    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)
示例#8
0
class TestANewBasket(TestCase):
    def setUp(self):
        self.basket = Basket()
        self.basket.strategy = strategy.Default()

    def test_has_zero_lines(self):
        self.assertEqual(0, self.basket.num_lines)

    def test_has_zero_items(self):
        self.assertEqual(0, self.basket.num_items)

    def test_doesnt_contain_vouchers(self):
        self.assertFalse(self.basket.contains_a_voucher)

    def test_can_be_edited(self):
        self.assertTrue(self.basket.can_be_edited)

    def test_is_empty(self):
        self.assertTrue(self.basket.is_empty)

    def test_is_not_submitted(self):
        self.assertFalse(self.basket.is_submitted)

    def test_has_no_applied_offers(self):
        self.assertEqual({}, self.basket.applied_offers())
示例#9
0
class TestBasketMerging(TestCase):
    def setUp(self):
        self.product = create_product(num_in_stock=10)
        self.user_basket = Basket()
        self.user_basket.strategy = strategy.Default()
        add_product(self.user_basket, product=self.product)
        self.cookie_basket = Basket()
        self.cookie_basket.strategy = strategy.Default()
        add_product(self.cookie_basket, quantity=2, product=self.product)
        self.user_basket.merge(self.cookie_basket, add_quantities=False)

    def test_cookie_basket_has_status_set(self):
        self.assertEqual(Basket.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)
示例#10
0
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.assertEqual(1, self.main_basket.num_lines)

    def test_changes_status_of_merge_basket(self):
        self.assertEqual(Basket.MERGED, self.merge_basket.status)
示例#11
0
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)

    def test_cannot_add_a_product_without_price(self):
        product = factories.create_product(price=None)
        with self.assertRaises(ValueError):
            self.basket.add(product)
示例#12
0
 def test_discounts_charge(self):
     basket = Basket()
     charge = self.method.calculate(basket)
     self.assertEqual(D('7.00'), charge.incl_tax)
示例#13
0
 def test_delegates_is_tax_known(self):
     basket = Basket()
     charge = self.method.calculate(basket)
     self.assertTrue(charge.is_tax_known)
示例#14
0
 def test_can_have_tax_set_later(self):
     basket = Basket()
     charge = self.method.calculate(basket)
     charge.tax = D('1.00')
     self.assertEqual(D('9.00'), charge.incl_tax)
示例#15
0
 def setUp(self):
     self.method = methods.FixedPrice(charge_excl_tax=D('10.00'),
                                      charge_incl_tax=D('12.00'))
     basket = Basket()
     self.charge = self.method.calculate(basket)
示例#16
0
 def setUp(self):
     self.method = methods.FixedPrice(D('10.00'))
     basket = Basket()
     self.charge = self.method.calculate(basket)
示例#17
0
 def setUp(self):
     self.method = methods.NoShippingRequired()
     basket = Basket()
     self.charge = self.method.calculate(basket)
示例#18
0
 def setUp(self):
     self.method = methods.Free()
     self.basket = Basket()
     self.charge = self.method.calculate(self.basket)
示例#19
0
    def test_returns_zero_for_empty_basket(self):
        basket = Basket()

        scale = Scale(attribute_code='weight')
        self.assertEqual(0, scale.weigh_basket(basket))
示例#20
0
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(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)

        self.basket.strategy = UnavailableProductStrategy()
        line = self.basket.all_lines()[1]
        self.assertEqual(
            line.get_warning(),
            u"'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(WSHOP_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(WSHOP_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(WSHOP_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(WSHOP_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)
示例#21
0
 def setUp(self):
     self.basket = Basket()
     self.basket.strategy = strategy.Default()
     self.basket.submit()