示例#1
0
def test_shipping_voucher_checkout_discount_not_applicable_returns_zero():
    voucher = Voucher(code='unique',
                      type=VoucherType.SHIPPING,
                      discount_value_type=DiscountValueType.FIXED,
                      discount_value=10,
                      min_amount_spent=Money(20, 'USD'))
    price = TaxedMoney(net=Money(10, 'USD'), gross=Money(10, 'USD'))
    order = Mock(get_subtotal=Mock(return_value=price),
                 shipping_price=price,
                 voucher=voucher)
    with pytest.raises(NotApplicable):
        get_voucher_discount_for_order(order)
示例#2
0
def test_shipping_voucher_checkout_discount_not_applicable_returns_zero():
    voucher = Voucher(
        code='unique', type=VoucherType.SHIPPING,
        discount_value_type=DiscountValueType.FIXED,
        discount_value=10,
        min_amount_spent=Money(20, 'USD'))
    price = TaxedMoney(net=Money(10, 'USD'), gross=Money(10, 'USD'))
    order = Mock(
        get_subtotal=Mock(return_value=price),
        shipping_price=price,
        voucher=voucher)
    with pytest.raises(NotApplicable):
        get_voucher_discount_for_order(order)
示例#3
0
def test_product_voucher_checkout_discount_raises_not_applicable(
        order_with_lines, product_with_images):
    discounted_product = product_with_images
    voucher = Voucher(code='unique',
                      type=VoucherType.PRODUCT,
                      discount_value_type=DiscountValueType.FIXED,
                      discount_value=10)
    voucher.save()
    voucher.products.add(discounted_product)
    order_with_lines.voucher = voucher
    order_with_lines.save()
    # Offer is valid only for products listed in voucher
    with pytest.raises(NotApplicable):
        get_voucher_discount_for_order(order_with_lines)
示例#4
0
def test_product_voucher_checkout_discount_raises_not_applicable(
        order_with_lines, product_with_images):
    discounted_product = product_with_images
    voucher = Voucher(
        code='unique', type=VoucherType.PRODUCT,
        discount_value_type=DiscountValueType.FIXED,
        discount_value=10)
    voucher.save()
    voucher.products.add(discounted_product)
    order_with_lines.voucher = voucher
    order_with_lines.save()
    # Offer is valid only for products listed in voucher
    with pytest.raises(NotApplicable):
        get_voucher_discount_for_order(order_with_lines)
示例#5
0
def test_category_voucher_checkout_discount_raises_not_applicable(
        order_with_lines):
    discounted_collection = Collection.objects.create(name='Discounted',
                                                      slug='discou')
    voucher = Voucher(code='unique',
                      type=VoucherType.COLLECTION,
                      discount_value_type=DiscountValueType.FIXED,
                      discount_value=10)
    voucher.save()
    voucher.collections.add(discounted_collection)
    order_with_lines.voucher = voucher
    order_with_lines.save()
    # Discount should be valid only for items in the discounted collections
    with pytest.raises(NotApplicable):
        get_voucher_discount_for_order(order_with_lines)
示例#6
0
def test_category_voucher_checkout_discount_raises_not_applicable(order_with_lines):
    discounted_collection = Collection.objects.create(name="Discounted", slug="discou")
    voucher = Voucher(
        code="unique",
        type=VoucherType.SPECIFIC_PRODUCT,
        discount_value_type=DiscountValueType.FIXED,
        discount_value=10,
    )
    voucher.save()
    voucher.collections.add(discounted_collection)
    order_with_lines.voucher = voucher
    order_with_lines.save()
    # Discount should be valid only for items in the discounted collections
    with pytest.raises(NotApplicable):
        get_voucher_discount_for_order(order_with_lines)
示例#7
0
def test_category_voucher_checkout_discount_raises_not_applicable(order_with_lines):
    discounted_collection = Collection.objects.create(name="Discounted", slug="discou")
    voucher = Voucher(
        code="unique",
        type=VoucherType.COLLECTION,
        discount_value_type=DiscountValueType.FIXED,
        discount_value=10,
    )
    voucher.save()
    voucher.collections.add(discounted_collection)
    order_with_lines.voucher = voucher
    order_with_lines.save()
    # Discount should be valid only for items in the discounted collections
    with pytest.raises(NotApplicable):
        get_voucher_discount_for_order(order_with_lines)
示例#8
0
def test_value_voucher_order_discount_not_applicable_returns_zero(settings):
    voucher = Voucher(code='unique',
                      type=VoucherType.VALUE,
                      discount_value_type=DiscountValueType.FIXED,
                      discount_value=10,
                      limit=Money(100, 'USD'))
    subtotal = TaxedMoney(net=Money(10, 'USD'), gross=Money(10, 'USD'))
    order = Mock(get_subtotal=Mock(return_value=subtotal), voucher=voucher)
    discount = get_voucher_discount_for_order(order)
    assert discount == Money(0, 'USD')
示例#9
0
def test_value_voucher_order_discount_not_applicable_returns_zero(settings):
    voucher = Voucher(
        code='unique', type=VoucherType.VALUE,
        discount_value_type=DiscountValueType.FIXED,
        discount_value=10,
        limit=Money(100, 'USD'))
    subtotal = TaxedMoney(net=Money(10, 'USD'), gross=Money(10, 'USD'))
    order = Mock(get_subtotal=Mock(return_value=subtotal), voucher=voucher)
    discount = get_voucher_discount_for_order(order)
    assert discount == Money(0, 'USD')
示例#10
0
def test_category_voucher_checkout_discount_not_applicable(monkeypatch):
    monkeypatch.setattr(
        'saleor.dashboard.order.utils.get_category_variants_and_prices',
        lambda order, product: [])
    voucher = Voucher(
        code='unique', type=VoucherType.CATEGORY,
        discount_value_type=DiscountValueType.FIXED,
        discount_value=10)
    order = Mock(voucher=voucher)
    discount = get_voucher_discount_for_order(order)
    assert discount == Money(0, 'USD')
示例#11
0
def test_value_voucher_order_discount(
        settings, total, discount_value, discount_type, limit, expected_value):
    voucher = Voucher(
        code='unique', type=VoucherType.VALUE,
        discount_value_type=discount_type,
        discount_value=discount_value,
        limit=Money(limit, 'USD') if limit is not None else None)
    subtotal = TaxedMoney(net=Money(total, 'USD'), gross=Money(total, 'USD'))
    order = Mock(get_subtotal=Mock(return_value=subtotal), voucher=voucher)
    discount = get_voucher_discount_for_order(order)
    assert discount == Money(expected_value, 'USD')
示例#12
0
def test_value_voucher_order_discount(settings, total, discount_value,
                                      discount_type, limit, expected_value):
    voucher = Voucher(code='unique',
                      type=VoucherType.VALUE,
                      discount_value_type=discount_type,
                      discount_value=discount_value,
                      limit=Money(limit, 'USD') if limit is not None else None)
    subtotal = TaxedMoney(net=Money(total, 'USD'), gross=Money(total, 'USD'))
    order = Mock(get_subtotal=Mock(return_value=subtotal), voucher=voucher)
    discount = get_voucher_discount_for_order(order)
    assert discount == Money(expected_value, 'USD')
示例#13
0
def test_category_voucher_checkout_discount_not_applicable(monkeypatch):
    monkeypatch.setattr(
        'saleor.dashboard.order.utils.get_category_variants_and_prices',
        lambda order, product: [])
    voucher = Voucher(code='unique',
                      type=VoucherType.CATEGORY,
                      discount_value_type=DiscountValueType.FIXED,
                      discount_value=10)
    order = Mock(voucher=voucher)
    discount = get_voucher_discount_for_order(order)
    assert discount == Money(0, 'USD')
示例#14
0
def test_shipping_voucher_checkout_discount_not_applicable_returns_zero():
    voucher = Voucher(code='unique',
                      type=VoucherType.SHIPPING,
                      discount_value_type=DiscountValueType.FIXED,
                      discount_value=10,
                      limit=Money(20, 'USD'))
    price = TaxedMoney(net=Money(10, 'USD'), gross=Money(10, 'USD'))
    order = Mock(get_subtotal=Mock(return_value=price),
                 shipping_price=price,
                 voucher=voucher)
    discount = get_voucher_discount_for_order(order)
    assert discount == Money(0, 'USD')
示例#15
0
def test_shipping_voucher_checkout_discount_not_applicable_returns_zero(
        total, total_quantity, min_spent_amount, min_checkout_items_quantity,
        voucher_type):
    voucher = Voucher(
        code="unique",
        type=voucher_type,
        discount_value_type=DiscountValueType.FIXED,
        discount_value=10,
        min_spent=(Money(min_spent_amount, "USD")
                   if min_spent_amount is not None else None),
        min_checkout_items_quantity=min_checkout_items_quantity,
    )
    price = Money(total, "USD")
    price = TaxedMoney(net=price, gross=price)
    order = Mock(
        get_subtotal=Mock(return_value=price),
        get_total_quantity=Mock(return_value=total_quantity),
        shipping_price=price,
        voucher=voucher,
    )
    with pytest.raises(NotApplicable):
        get_voucher_discount_for_order(order)
示例#16
0
def test_shipping_voucher_checkout_discount_not_applicable_returns_zero():
    voucher = Voucher(
        code='unique', type=VoucherType.SHIPPING,
        discount_value_type=DiscountValueType.FIXED,
        discount_value=10,
        limit=Money(20, 'USD'))
    price = TaxedMoney(net=Money(10, 'USD'), gross=Money(10, 'USD'))
    order = Mock(
        get_subtotal=Mock(return_value=price),
        shipping_price=price,
        voucher=voucher)
    discount = get_voucher_discount_for_order(order)
    assert discount == Money(0, 'USD')
示例#17
0
def test_value_voucher_order_discount(total, discount_value, discount_type,
                                      min_amount_spent, expected_value):
    voucher = Voucher(
        code="unique",
        type=VoucherType.VALUE,
        discount_value_type=discount_type,
        discount_value=discount_value,
        min_amount_spent=Money(min_amount_spent, "USD")
        if min_amount_spent is not None else None,
    )
    subtotal = TaxedMoney(net=Money(total, "USD"), gross=Money(total, "USD"))
    order = Mock(get_subtotal=Mock(return_value=subtotal), voucher=voucher)
    discount = get_voucher_discount_for_order(order)
    assert discount == Money(expected_value, "USD")
示例#18
0
def test_shipping_voucher_order_discount(shipping_cost, discount_value,
                                         discount_type, expected_value):
    voucher = Voucher(code='unique',
                      type=VoucherType.SHIPPING,
                      discount_value_type=discount_type,
                      discount_value=discount_value,
                      min_amount_spent=None)
    subtotal = TaxedMoney(net=Money(100, 'USD'), gross=Money(100, 'USD'))
    shipping_total = TaxedMoney(net=Money(shipping_cost, 'USD'),
                                gross=Money(shipping_cost, 'USD'))
    order = Mock(get_subtotal=Mock(return_value=subtotal),
                 shipping_price=shipping_total,
                 voucher=voucher)
    discount = get_voucher_discount_for_order(order)
    assert discount == Money(expected_value, 'USD')
示例#19
0
def test_value_voucher_order_discount(
    settings, total, discount_value, discount_type, min_amount_spent, expected_value
):
    voucher = Voucher(
        code="unique",
        type=VoucherType.VALUE,
        discount_value_type=discount_type,
        discount_value=discount_value,
        min_amount_spent=Money(min_amount_spent, "USD")
        if min_amount_spent is not None
        else None,
    )
    subtotal = TaxedMoney(net=Money(total, "USD"), gross=Money(total, "USD"))
    order = Mock(get_subtotal=Mock(return_value=subtotal), voucher=voucher)
    discount = get_voucher_discount_for_order(order)
    assert discount == Money(expected_value, "USD")
示例#20
0
def test_shipping_voucher_order_discount(
        shipping_cost, discount_value, discount_type, expected_value):
    voucher = Voucher(
        code='unique', type=VoucherType.SHIPPING,
        discount_value_type=discount_type,
        discount_value=discount_value,
        limit=None)
    subtotal = TaxedMoney(net=Money(100, 'USD'), gross=Money(100, 'USD'))
    shipping_total = TaxedMoney(
        net=Money(shipping_cost, 'USD'), gross=Money(shipping_cost, 'USD'))
    order = Mock(
        get_subtotal=Mock(return_value=subtotal),
        shipping_price=shipping_total,
        voucher=voucher)
    discount = get_voucher_discount_for_order(order)
    assert discount == Money(expected_value, 'USD')
示例#21
0
def test_shipping_voucher_order_discount(
    shipping_cost, discount_value, discount_type, expected_value
):
    voucher = Voucher(
        code="unique",
        type=VoucherType.SHIPPING,
        discount_value_type=discount_type,
        discount_value=discount_value,
        min_amount_spent=None,
    )
    subtotal = TaxedMoney(net=Money(100, "USD"), gross=Money(100, "USD"))
    shipping_total = TaxedMoney(
        net=Money(shipping_cost, "USD"), gross=Money(shipping_cost, "USD")
    )
    order = Mock(
        get_subtotal=Mock(return_value=subtotal),
        shipping_price=shipping_total,
        voucher=voucher,
    )
    discount = get_voucher_discount_for_order(order)
    assert discount == Money(expected_value, "USD")