Esempio n. 1
0
def test_recalculate_checkout_discount_with_sale(
        checkout_with_voucher_percentage, discount_info):
    checkout = checkout_with_voucher_percentage
    recalculate_checkout_discount(checkout, [discount_info], None)
    assert checkout.discount_amount == Money("1.50", "USD")
    total = TaxedMoney(net=Money("13.50", "USD"), gross=Money("13.50", "USD"))
    assert checkout.get_total(discounts=[discount_info]) == total
Esempio n. 2
0
def test_recalculate_checkout_discount_with_sale(
        checkout_with_voucher_percentage, discount_info):
    checkout = checkout_with_voucher_percentage
    recalculate_checkout_discount(checkout, [discount_info])
    assert checkout.discount == Money("1.50", "USD")
    assert calculations.checkout_total(
        checkout, discounts=[discount_info]).gross == Money("13.50", "USD")
def test_recalculate_checkout_discount(checkout_with_voucher, voucher,
                                       voucher_translation_fr, settings):
    settings.LANGUAGE_CODE = 'fr'
    voucher.discount_value = 10
    voucher.save()

    recalculate_checkout_discount(checkout_with_voucher, None, None)
    assert checkout_with_voucher.translated_discount_name == voucher_translation_fr.name  # noqa
    assert checkout_with_voucher.discount_amount == Money('10.00', 'USD')
Esempio n. 4
0
def test_recalculate_checkout_discount_free_shipping_for_checkout_without_shipping(
        checkout_with_voucher_percentage, voucher_free_shipping):
    checkout = checkout_with_voucher_percentage

    recalculate_checkout_discount(checkout, list(checkout), None)

    assert not checkout.discount_name
    assert not checkout.voucher_code
    assert checkout.discount == zero_money()
Esempio n. 5
0
def test_recalculate_checkout_discount(checkout_with_voucher, voucher,
                                       voucher_translation_fr, settings):
    settings.LANGUAGE_CODE = "fr"
    voucher.discount_value = 10
    voucher.save()

    recalculate_checkout_discount(checkout_with_voucher, None)
    assert (checkout_with_voucher.translated_discount_name ==
            voucher_translation_fr.name)  # noqa
    assert checkout_with_voucher.discount == Money("10.00", "USD")
Esempio n. 6
0
def test_recalculate_checkout_discount_expired_voucher(checkout_with_voucher, voucher):
    checkout = checkout_with_voucher
    date_yesterday = timezone.now() - datetime.timedelta(days=1)
    voucher.end_date = date_yesterday
    voucher.save()

    recalculate_checkout_discount(checkout_with_voucher, None)

    assert not checkout.voucher_code
    assert not checkout.discount_name
    assert checkout.discount == zero_money()
Esempio n. 7
0
def test_recalculate_checkout_discount_voucher_not_applicable(
        checkout_with_voucher, voucher):
    checkout = checkout_with_voucher
    voucher.min_amount_spent = 100
    voucher.save()

    recalculate_checkout_discount(checkout_with_voucher, None, None)

    assert not checkout.voucher_code
    assert not checkout.discount_name
    assert checkout.discount_amount == ZERO_MONEY
Esempio n. 8
0
def test_recalculate_checkout_discount_expired_voucher(checkout_with_voucher, voucher):
    checkout = checkout_with_voucher
    date_yesterday = datetime.date.today() - datetime.timedelta(days=1)
    voucher.end_date = date_yesterday
    voucher.save()

    recalculate_checkout_discount(checkout_with_voucher, None, None)

    assert not checkout.voucher_code
    assert not checkout.discount_name
    assert checkout.discount_amount == ZERO_MONEY
Esempio n. 9
0
def test_recalculate_checkout_discount_voucher_not_applicable(
        checkout_with_voucher, voucher):
    checkout = checkout_with_voucher
    voucher.min_spent = Money(100, "USD")
    voucher.save(update_fields=["min_spent_amount", "currency"])

    recalculate_checkout_discount(checkout_with_voucher, None)

    assert not checkout.voucher_code
    assert not checkout.discount_name
    assert checkout.discount == zero_money()
Esempio n. 10
0
def test_recalculate_checkout_discount_expired_voucher(checkout_with_voucher,
                                                       voucher):
    checkout = checkout_with_voucher
    date_yesterday = datetime.date.today() - datetime.timedelta(days=1)
    voucher.end_date = date_yesterday
    voucher.save()

    recalculate_checkout_discount(checkout_with_voucher, None, None)

    assert not checkout.voucher_code
    assert not checkout.discount_name
    assert checkout.discount_amount == ZERO_MONEY
Esempio n. 11
0
def test_recalculate_checkout_discount_voucher_not_applicable(
    checkout_with_voucher, voucher
):
    checkout = checkout_with_voucher
    voucher.min_amount_spent = 100
    voucher.save()

    recalculate_checkout_discount(checkout_with_voucher, None, None)

    assert not checkout.voucher_code
    assert not checkout.discount_name
    assert checkout.discount_amount == ZERO_MONEY
Esempio n. 12
0
def test_recalculate_checkout_discount(
    checkout_with_voucher, voucher, voucher_translation_fr, settings
):
    settings.LANGUAGE_CODE = "fr"
    voucher.discount_value = 10
    voucher.save()

    recalculate_checkout_discount(checkout_with_voucher, None, None)
    assert (
        checkout_with_voucher.translated_discount_name == voucher_translation_fr.name
    )  # noqa
    assert checkout_with_voucher.discount_amount == Money("10.00", "USD")
Esempio n. 13
0
def test_recalculate_checkout_discount_free_shipping_subtotal_bigger_than_shipping(
    checkout_with_voucher_percentage_and_shipping,
    voucher_free_shipping,
    shipping_method,
):
    checkout = checkout_with_voucher_percentage_and_shipping

    shipping_method.price = calculations.checkout_subtotal(
        checkout).gross - Money("1.00", "USD")
    shipping_method.save()

    recalculate_checkout_discount(checkout, None)

    assert checkout.discount == shipping_method.price
    assert checkout.discount_name == "Free shipping"
    assert calculations.checkout_total(
        checkout) == calculations.checkout_subtotal(checkout)