Пример #1
0
    def test_has_discount_recorded_correctly_when_order_is_placed(self):
        add_product(self.basket, D('12.00'), 1)
        utils.Applicator().apply(self.basket)
        self.assertEqual(1, len(self.basket.offer_applications))

        shipping_method = WeightBased.objects.first()
        shipping_method = Repository().apply_shipping_offer(
            self.basket, shipping_method, self.offer)
        order = factories.create_order(basket=self.basket,
                                       shipping_method=shipping_method)

        discounts = order.discounts.all()
        self.assertEqual(1, len(discounts))

        discount = discounts[0]
        self.assertTrue(discount.is_shipping_discount)
        self.assertEqual(D('9.00'), discount.amount)
Пример #2
0
    def test_basket_offers_are_ordered(self):
        voucher = Voucher.objects.create(
            name="Test voucher",
            code="test",
            start_datetime=timezone.now(),
            end_datetime=timezone.now() + datetime.timedelta(days=12))

        voucher.offers.set([
            factories.create_offer(name="A", priority=0),
            factories.create_offer(name="B", priority=7),
            factories.create_offer(name="C", priority=5),
            factories.create_offer(name="D", priority=7),
            factories.create_offer(name="E", priority=1),
        ])

        basket = factories.create_basket()
        user = mock.Mock()

        # Apply voucher to basket
        basket.vouchers.add(voucher)

        offers = utils.Applicator().get_basket_offers(basket, user)
        ordered_names = [offer.name for offer in offers]
        self.assertEqual(["B", "D", "C", "E", "A"], ordered_names)
 def test_applies_correctly_to_basket_which_exceeds_condition(self):
     add_product(self.basket, D('12.00'), 2)
     utils.Applicator().apply(self.basket)
     self.assertEqual(1, len(self.basket.offer_applications))
Пример #4
0
 def setUp(self):
     self.basket = factories.create_basket(empty=True)
     add_product(self.basket, D('12.00'), 1)
     create_offer()
     utils.Applicator().apply(self.basket)