Beispiel #1
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)
Beispiel #2
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'))
Beispiel #3
0
    def test_hurry_mode_not_set_multiple_stockrecords(self):
        # Two stockrecords, 5 items in stock for one. No need to hurry.
        create_stockrecord(self.product, num_in_stock=1)
        create_stockrecord(self.product, num_in_stock=5)
        ProductAlert.objects.create(user=self.user, product=self.product)

        send_product_alerts(self.product)

        self.assertNotIn('Beware that the amount of items in stock is limited',
                         mail.outbox[0].body)
Beispiel #4
0
    def test_hurry_mode_not_set_when_stock_high(self):
        # One alert, 5 items in stock. No need to hurry.
        create_stockrecord(self.product, num_in_stock=5)
        ProductAlert.objects.create(user=self.user, product=self.product)

        send_product_alerts(self.product)

        self.assertEqual(1, len(mail.outbox))
        self.assertNotIn('Beware that the amount of items in stock is limited',
                         mail.outbox[0].body)
Beispiel #5
0
    def test_hurry_mode_set_when_stock_low(self):
        # Two alerts, 1 item in stock. Hurry mode should be set.
        create_stockrecord(self.product, num_in_stock=1)
        ProductAlert.objects.create(user=self.user, product=self.product)
        ProductAlert.objects.create(user=UserFactory(), product=self.product)

        send_product_alerts(self.product)

        self.assertEqual(2, len(mail.outbox))
        self.assertIn('Beware that the amount of items in stock is limited',
                      mail.outbox[0].body)
Beispiel #6
0
    def test_hurry_mode_set_multiple_stockrecords(self):
        # Two stockrecords, low stock on both. Hurry mode should be set.
        create_stockrecord(self.product, num_in_stock=1)
        create_stockrecord(self.product, num_in_stock=1)
        ProductAlert.objects.create(user=self.user, product=self.product)
        ProductAlert.objects.create(user=UserFactory(), product=self.product)

        send_product_alerts(self.product)

        self.assertIn('Beware that the amount of items in stock is limited',
                      mail.outbox[0].body)
Beispiel #7
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)
Beispiel #8
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)
Beispiel #9
0
    def test_basket_on_threshold(self):
        record = factories.create_stockrecord(price_excl_tax=D('5.00'))
        self.basket.add_product(record.product, quantity=4)

        charge = self.method.calculate(self.basket)

        self.assertEqual(D('0.00'), charge.incl_tax)
 def setUp(self):
     self.product = factories.create_product()
     self.stockrecord = factories.create_stockrecord(self.product,
                                                     D('12.00'),
                                                     num_in_stock=5)
     self.basket = factories.create_basket(empty=True)
     add_product(self.basket, product=self.product)
Beispiel #11
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)
Beispiel #12
0
    def test_allocate_does_nothing(self):
        product = factories.ProductFactory(product_class=self.product_class)
        stockrecord = factories.create_stockrecord(
            product, price_excl_tax=D('10.00'), num_in_stock=10)

        self.assertFalse(stockrecord.can_track_allocations)
        stockrecord.allocate(5)
        self.assertEqual(stockrecord.num_allocated, None)
Beispiel #13
0
    def test_multi_item_basket(self):
        basket = factories.create_basket(empty=True)
        record = factories.create_stockrecord()
        basket.add_product(record.product, 7)

        charge = self.method.calculate(basket)

        self.assertEqual(D('5.00') + 7 * D('1.00'), charge.incl_tax)
Beispiel #14
0
 def setUp(self):
     self.user = UserFactory()
     self.product = create_product()
     self.stockrecord = create_stockrecord(self.product, num_in_stock=0)
     product_page = self.app.get(self.product.get_absolute_url(),
                                 user=self.user)
     form = product_page.forms['alert_form']
     form.submit()
Beispiel #15
0
    def test_allocate_does_nothing_for_child_product(self):
        parent_product = factories.ProductFactory(
            structure='parent', product_class=self.product_class)
        child_product = factories.ProductFactory(
            parent=parent_product, product_class=None, structure='child')
        stockrecord = factories.create_stockrecord(
            child_product, price_excl_tax=D('10.00'), num_in_stock=10)

        self.assertFalse(stockrecord.can_track_allocations)
        stockrecord.allocate(5)
        self.assertEqual(stockrecord.num_allocated, None)
Beispiel #16
0
    def test_single_item_basket_that_doesnt_require_shipping(self):
        # Create a product that doesn't require shipping
        record = factories.create_stockrecord()
        product = record.product
        product.product_class.requires_shipping = False
        product.product_class.save()
        basket = factories.create_basket(empty=True)
        basket.add_product(record.product)

        charge = self.method.calculate(basket)

        self.assertEqual(D('5.00'), charge.incl_tax)
Beispiel #17
0
    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))
Beispiel #18
0
    def test_does_not_allocate_stock(self):
        ProductClass.objects.create(
            name="Digital", track_stock=False)
        product = factories.create_product(product_class="Digital")
        record = factories.create_stockrecord(product, num_in_stock=None)
        self.assertTrue(record.num_allocated is None)

        add_product(self.basket, D('12.00'), product=product)
        place_order(self.creator, basket=self.basket, order_number='1234')

        product = Product.objects.get(id=product.id)
        stockrecord = product.stockrecords.all()[0]
        self.assertTrue(stockrecord.num_in_stock is None)
        self.assertTrue(stockrecord.num_allocated is None)
Beispiel #19
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)
Beispiel #20
0
def add_product(basket, price=None, quantity=1, product=None):
    """
    Helper to add a product to the basket.
    """
    has_strategy = False
    try:
        has_strategy = hasattr(basket, 'strategy')
    except RuntimeError:
        pass
    if not has_strategy:
        basket.strategy = Default()
    if price is None:
        price = D('1')
    if product and product.has_stockrecords:
        record = product.stockrecords.all()[0]
    else:
        record = factories.create_stockrecord(product=product,
                                              price_excl_tax=price,
                                              num_in_stock=quantity + 1)
    basket.add_product(record.product, quantity)
Beispiel #21
0
 def setUp(self):
     self.user = UserFactory()
     self.product = create_product()
     create_stockrecord(self.product, num_in_stock=1)
Beispiel #22
0
 def test_free_shipping_with_nonempty_basket(self):
     record = factories.create_stockrecord(price_excl_tax=D('5.00'))
     self.basket.add_product(record.product)
     charge = self.method.calculate(self.basket)
     self.assertEqual(D('0.00'), charge.incl_tax)
Beispiel #23
0
 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)
Beispiel #24
0
 def setUp(self):
     self.product = factories.create_product()
     self.stockrecord = factories.create_stockrecord(
         self.product, price_excl_tax=D('10.00'), num_in_stock=10)
Beispiel #25
0
 def test_selects_first_stockrecord_for_product(self):
     stockrecord = factories.create_stockrecord(self.product)
     selected = self.mixin.select_stockrecord(self.product)
     self.assertEqual(selected.id, stockrecord.id)
Beispiel #26
0
 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))
Beispiel #27
0
 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))
Beispiel #28
0
 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)