Ejemplo n.º 1
0
def test_get_discount_for_cart_value_voucher_not_applicable():
    voucher = Voucher(code='unique',
                      type=VoucherType.VALUE,
                      discount_value_type=DiscountValueType.FIXED,
                      discount_value=10,
                      min_amount_spent=Money(100, 'USD'))
    subtotal = TaxedMoney(net=Money(10, 'USD'), gross=Money(10, 'USD'))
    cart = Mock(get_subtotal=Mock(return_value=subtotal))
    with pytest.raises(NotApplicable) as e:
        get_voucher_discount_for_cart(voucher, cart)
    assert e.value.min_amount_spent == Money(100, 'USD')
Ejemplo n.º 2
0
def test_get_discount_for_cart_value_voucher_not_applicable(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'))
    cart = Mock(get_subtotal=Mock(return_value=subtotal))
    with pytest.raises(NotApplicable) as e:
        get_voucher_discount_for_cart(voucher, cart)
    assert e.value.limit == Money(100, 'USD')
Ejemplo n.º 3
0
def test_get_discount_for_cart_collection_voucher_not_applicable(monkeypatch):
    monkeypatch.setattr(
        'saleor.checkout.utils.get_prices_of_products_in_discounted_collections',  # noqa
        lambda cart, product: [])
    voucher = Voucher(
        code='unique', type=VoucherType.COLLECTION,
        discount_value_type=DiscountValueType.FIXED,
        discount_value=10)
    voucher.save()
    cart = Mock()

    with pytest.raises(NotApplicable) as e:
        get_voucher_discount_for_cart(voucher, cart)
    assert str(e.value) == 'This offer is only valid for selected items.'
Ejemplo n.º 4
0
def test_get_discount_for_cart_category_voucher_not_applicable(
        settings, monkeypatch):
    monkeypatch.setattr(
        'saleor.checkout.utils.get_category_variants_and_prices',
        lambda cart, product: [])
    voucher = Voucher(
        code='unique', type=VoucherType.CATEGORY,
        discount_value_type=DiscountValueType.FIXED,
        discount_value=10)
    cart = Mock()

    with pytest.raises(NotApplicable) as e:
        get_voucher_discount_for_cart(voucher, cart)
    assert str(e.value) == 'This offer is only valid for selected items.'
Ejemplo n.º 5
0
def test_get_discount_for_cart_collection_voucher_not_applicable(monkeypatch):
    monkeypatch.setattr(
        'saleor.checkout.utils.get_prices_of_products_in_discounted_collections',  # noqa
        lambda cart, product: [])
    voucher = Voucher(code='unique',
                      type=VoucherType.COLLECTION,
                      discount_value_type=DiscountValueType.FIXED,
                      discount_value=10)
    voucher.save()
    cart = Mock()

    with pytest.raises(NotApplicable) as e:
        get_voucher_discount_for_cart(voucher, cart)
    assert str(e.value) == 'This offer is only valid for selected items.'
Ejemplo n.º 6
0
def test_get_discount_for_cart_category_voucher_not_applicable(
        settings, monkeypatch):
    monkeypatch.setattr(
        'saleor.checkout.utils.get_category_variants_and_prices',
        lambda cart, product: [])
    voucher = Voucher(code='unique',
                      type=VoucherType.CATEGORY,
                      discount_value_type=DiscountValueType.FIXED,
                      discount_value=10)
    cart = Mock()

    with pytest.raises(NotApplicable) as e:
        get_voucher_discount_for_cart(voucher, cart)
    assert str(e.value) == 'This offer is only valid for selected items.'
Ejemplo n.º 7
0
def test_get_discount_for_cart_shipping_voucher_limited_countries():
    subtotal = TaxedMoney(net=Money(100, 'USD'), gross=Money(100, 'USD'))
    shipping_total = TaxedMoney(net=Money(10, 'USD'), gross=Money(10, 'USD'))
    cart = Mock(
        get_subtotal=Mock(return_value=subtotal),
        is_shipping_required=Mock(return_value=True),
        shipping_method=Mock(get_total=Mock(return_value=shipping_total)),
        shipping_address=Mock(country=Country('PL')))
    voucher = Voucher(
        code='unique', type=VoucherType.SHIPPING,
        discount_value_type=DiscountValueType.PERCENTAGE,
        discount_value=50, countries=['UK', 'DE'])

    with pytest.raises(NotApplicable):
        get_voucher_discount_for_cart(voucher, cart)
Ejemplo n.º 8
0
def test_get_discount_for_cart_shipping_voucher_limited_countries():
    subtotal = TaxedMoney(net=Money(100, 'USD'), gross=Money(100, 'USD'))
    shipping_total = TaxedMoney(net=Money(10, 'USD'), gross=Money(10, 'USD'))
    cart = Mock(
        get_subtotal=Mock(return_value=subtotal),
        is_shipping_required=Mock(return_value=True),
        shipping_method=Mock(get_total=Mock(return_value=shipping_total)),
        shipping_address=Mock(country=Country('PL')))
    voucher = Voucher(code='unique',
                      type=VoucherType.SHIPPING,
                      discount_value_type=DiscountValueType.PERCENTAGE,
                      discount_value=50,
                      countries=['UK', 'DE'])

    with pytest.raises(NotApplicable):
        get_voucher_discount_for_cart(voucher, cart)
Ejemplo n.º 9
0
def test_get_discount_for_cart_shipping_voucher_not_applicable(
        settings, is_shipping_required, shipping_method, discount_value,
        discount_type, apply_to, limit, subtotal, error_msg):
    subtotal_price = TaxedMoney(net=subtotal, gross=subtotal)
    cart = Mock(get_subtotal=Mock(return_value=subtotal_price),
                is_shipping_required=Mock(return_value=is_shipping_required),
                shipping_method=shipping_method)
    voucher = Voucher(code='unique',
                      type=VoucherType.SHIPPING,
                      discount_value_type=discount_type,
                      discount_value=discount_value,
                      limit=Money(limit, 'USD') if limit is not None else None,
                      apply_to=apply_to)
    with pytest.raises(NotApplicable) as e:
        get_voucher_discount_for_cart(voucher, cart)
    assert str(e.value) == error_msg
Ejemplo n.º 10
0
def test_get_discount_for_cart_shipping_voucher_not_applicable(
        settings, is_shipping_required, shipping_method, discount_value,
        discount_type, apply_to, limit, subtotal, error_msg):
    subtotal_price = TaxedMoney(net=subtotal, gross=subtotal)
    cart = Mock(
        get_subtotal=Mock(return_value=subtotal_price),
        is_shipping_required=Mock(return_value=is_shipping_required),
        shipping_method=shipping_method)
    voucher = Voucher(
        code='unique', type=VoucherType.SHIPPING,
        discount_value_type=discount_type,
        discount_value=discount_value,
        limit=Money(limit, 'USD') if limit is not None else None,
        apply_to=apply_to)
    with pytest.raises(NotApplicable) as e:
        get_voucher_discount_for_cart(voucher, cart)
    assert str(e.value) == error_msg
Ejemplo n.º 11
0
def test_get_discount_for_cart_shipping_voucher_not_applicable(
        is_shipping_required, shipping_method, discount_value, discount_type,
        countries, min_amount_spent, subtotal, error_msg):
    subtotal_price = TaxedMoney(net=subtotal, gross=subtotal)
    cart = Mock(get_subtotal=Mock(return_value=subtotal_price),
                is_shipping_required=Mock(return_value=is_shipping_required),
                shipping_method=shipping_method)
    voucher = Voucher(
        code='unique',
        type=VoucherType.SHIPPING,
        discount_value_type=discount_type,
        discount_value=discount_value,
        min_amount_spent=(Money(min_amount_spent, 'RUB')
                          if min_amount_spent is not None else None),
        countries=countries)
    with pytest.raises(NotApplicable) as e:
        get_voucher_discount_for_cart(voucher, cart)
    assert str(e.value) == error_msg
Ejemplo n.º 12
0
def test_get_discount_for_cart_value_voucher(settings, total, discount_value,
                                             discount_type, limit,
                                             discount_amount):
    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'))
    cart = Mock(get_subtotal=Mock(return_value=subtotal))
    discount = get_voucher_discount_for_cart(voucher, cart)
    assert discount == Money(discount_amount, 'USD')
Ejemplo n.º 13
0
def test_get_discount_for_cart_value_voucher(
        settings, total, discount_value, discount_type, limit,
        discount_amount):
    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'))
    cart = Mock(get_subtotal=Mock(return_value=subtotal))
    discount = get_voucher_discount_for_cart(voucher, cart)
    assert discount == Money(discount_amount, 'USD')
Ejemplo n.º 14
0
def test_get_discount_for_cart_value_voucher(total, discount_value,
                                             discount_type, min_amount_spent,
                                             discount_amount):
    voucher = Voucher(
        code='unique',
        type=VoucherType.VALUE,
        discount_value_type=discount_type,
        discount_value=discount_value,
        min_amount_spent=(Money(min_amount_spent, 'RUB')
                          if min_amount_spent is not None else None))
    subtotal = TaxedMoney(net=Money(total, 'RUB'), gross=Money(total, 'RUB'))
    cart = Mock(get_subtotal=Mock(return_value=subtotal))
    discount = get_voucher_discount_for_cart(voucher, cart)
    assert discount == Money(discount_amount, 'RUB')
Ejemplo n.º 15
0
def test_products_voucher_checkout_discount_not(settings, monkeypatch, prices,
                                                discount_value, discount_type,
                                                apply_to, expected_value):
    monkeypatch.setattr(
        'saleor.checkout.utils.get_product_variants_and_prices',
        lambda cart, product:
        ((None, TaxedMoney(net=Money(price, 'USD'), gross=Money(price, 'USD')))
         for price in prices))
    voucher = Voucher(code='unique',
                      type=VoucherType.PRODUCT,
                      discount_value_type=discount_type,
                      discount_value=discount_value,
                      apply_to=apply_to)
    checkout = Mock(cart=Mock())
    discount = get_voucher_discount_for_cart(voucher, checkout)
    assert discount == Money(expected_value, 'USD')
Ejemplo n.º 16
0
def test_get_discount_for_cart_shipping_voucher_all_countries():
    subtotal = TaxedMoney(net=Money(100, 'USD'), gross=Money(100, 'USD'))
    shipping_total = TaxedMoney(net=Money(10, 'USD'), gross=Money(10, 'USD'))
    cart = Mock(
        get_subtotal=Mock(return_value=subtotal),
        is_shipping_required=Mock(return_value=True),
        shipping_method=Mock(get_total=Mock(return_value=shipping_total)),
        shipping_address=Mock(country=Country('PL')))
    voucher = Voucher(
        code='unique', type=VoucherType.SHIPPING,
        discount_value_type=DiscountValueType.PERCENTAGE,
        discount_value=50, countries=[])

    discount = get_voucher_discount_for_cart(voucher, cart)

    assert discount == Money(5, 'USD')
Ejemplo n.º 17
0
def test_get_discount_for_cart_shipping_voucher_all_countries():
    subtotal = TaxedMoney(net=Money(100, 'USD'), gross=Money(100, 'USD'))
    shipping_total = TaxedMoney(net=Money(10, 'USD'), gross=Money(10, 'USD'))
    cart = Mock(
        get_subtotal=Mock(return_value=subtotal),
        is_shipping_required=Mock(return_value=True),
        shipping_method=Mock(get_total=Mock(return_value=shipping_total)),
        shipping_address=Mock(country=Country('PL')))
    voucher = Voucher(code='unique',
                      type=VoucherType.SHIPPING,
                      discount_value_type=DiscountValueType.PERCENTAGE,
                      discount_value=50,
                      countries=[])

    discount = get_voucher_discount_for_cart(voucher, cart)

    assert discount == Money(5, 'USD')
Ejemplo n.º 18
0
def test_products_voucher_checkout_discount_not(
        settings, monkeypatch, prices, discount_value, discount_type,
        expected_value, apply_once_per_order, cart_with_item):
    monkeypatch.setattr(
        'saleor.checkout.utils.get_prices_of_discounted_products',
        lambda lines, discounted_products: (
            TaxedMoney(net=Money(price, 'USD'), gross=Money(price, 'USD'))
            for price in prices))
    voucher = Voucher(
        code='unique', type=VoucherType.PRODUCT,
        discount_value_type=discount_type,
        discount_value=discount_value,
        apply_once_per_order=apply_once_per_order)
    voucher.save()
    checkout = cart_with_item
    discount = get_voucher_discount_for_cart(voucher, checkout)
    assert discount == Money(expected_value, 'USD')
Ejemplo n.º 19
0
def test_get_discount_for_cart_shipping_voucher(shipping_cost,
                                                shipping_country_code,
                                                discount_value, discount_type,
                                                countries, expected_value):
    subtotal = TaxedMoney(net=Money(100, 'USD'), gross=Money(100, 'USD'))
    shipping_total = TaxedMoney(net=Money(shipping_cost, 'USD'),
                                gross=Money(shipping_cost, 'USD'))
    cart = Mock(
        get_subtotal=Mock(return_value=subtotal),
        is_shipping_required=Mock(return_value=True),
        shipping_method=Mock(get_total=Mock(return_value=shipping_total)),
        shipping_address=Mock(country=Country(shipping_country_code)))
    voucher = Voucher(code='unique',
                      type=VoucherType.SHIPPING,
                      discount_value_type=discount_type,
                      discount_value=discount_value,
                      countries=countries)
    discount = get_voucher_discount_for_cart(voucher, cart)
    assert discount == Money(expected_value, 'USD')
Ejemplo n.º 20
0
def test_get_discount_for_cart_shipping_voucher(
        shipping_cost, shipping_country_code, discount_value,
        discount_type, countries, expected_value):
    subtotal = TaxedMoney(net=Money(100, 'USD'), gross=Money(100, 'USD'))
    shipping_total = TaxedMoney(
        net=Money(shipping_cost, 'USD'), gross=Money(shipping_cost, 'USD'))
    cart = Mock(
        get_subtotal=Mock(return_value=subtotal),
        is_shipping_required=Mock(return_value=True),
        shipping_method=Mock(
            get_total=Mock(return_value=shipping_total)),
        shipping_address=Mock(country=Country(shipping_country_code)))
    voucher = Voucher(
        code='unique', type=VoucherType.SHIPPING,
        discount_value_type=discount_type,
        discount_value=discount_value,
        countries=countries)
    discount = get_voucher_discount_for_cart(voucher, cart)
    assert discount == Money(expected_value, 'USD')
Ejemplo n.º 21
0
def test_get_discount_for_cart_shipping_voucher(settings, shipping_cost,
                                                shipping_country_code,
                                                discount_value, discount_type,
                                                apply_to, expected_value):
    subtotal = TaxedMoney(net=Money(100, 'USD'), gross=Money(100, 'USD'))
    shipping_total = TaxedMoney(net=Money(shipping_cost, 'USD'),
                                gross=Money(shipping_cost, 'USD'))
    cart = Mock(get_subtotal=Mock(return_value=subtotal),
                is_shipping_required=Mock(return_value=True),
                shipping_method=Mock(
                    price=Money(shipping_cost, 'USD'),
                    country_code=shipping_country_code,
                    get_total_price=Mock(return_value=shipping_total)))
    voucher = Voucher(code='unique',
                      type=VoucherType.SHIPPING,
                      discount_value_type=discount_type,
                      discount_value=discount_value,
                      apply_to=apply_to,
                      limit=None)
    discount = get_voucher_discount_for_cart(voucher, cart)
    assert discount == Money(expected_value, 'USD')
Ejemplo n.º 22
0
def test_get_discount_for_cart_shipping_voucher(
        settings, shipping_cost, shipping_country_code, discount_value,
        discount_type, apply_to, expected_value):
    subtotal = TaxedMoney(net=Money(100, 'USD'), gross=Money(100, 'USD'))
    shipping_total = TaxedMoney(
        net=Money(shipping_cost, 'USD'), gross=Money(shipping_cost, 'USD'))
    cart = Mock(
        get_subtotal=Mock(return_value=subtotal),
        is_shipping_required=Mock(return_value=True),
        shipping_method=Mock(
            price=Money(shipping_cost, 'USD'),
            country_code=shipping_country_code,
            get_total_price=Mock(return_value=shipping_total)))
    voucher = Voucher(
        code='unique', type=VoucherType.SHIPPING,
        discount_value_type=discount_type,
        discount_value=discount_value,
        apply_to=apply_to,
        limit=None)
    discount = get_voucher_discount_for_cart(voucher, cart)
    assert discount == Money(expected_value, 'USD')