Example #1
0
def test_valid_voucher_min_amount_spent(settings, min_amount_spent, value):
    voucher = Voucher(code='unique',
                      type=VoucherType.DELIVERY,
                      discount_value_type=DiscountValueType.FIXED,
                      discount_value=Money(10, 'USD'),
                      min_amount_spent=min_amount_spent)
    voucher.validate_min_amount_spent(TaxedMoney(net=value, gross=value))
Example #2
0
def test_get_value_voucher_discount(total, min_amount_spent, discount_value,
                                    discount_value_type, expected_value):
    voucher = Voucher(code='unique',
                      type=VoucherType.VALUE,
                      discount_value_type=discount_value_type,
                      discount_value=discount_value,
                      min_amount_spent=get_min_amount_spent(min_amount_spent))
    voucher.save()
    total_price = TaxedMoney(net=Money(total, 'USD'),
                             gross=Money(total, 'USD'))
    discount = get_value_voucher_discount(voucher, total_price)
    assert discount == Money(expected_value, 'USD')
Example #3
0
def test_get_discount_for_cart_collection_voucher_not_applicable(monkeypatch):
    monkeypatch.setattr(
        'remote_works.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.'
def test_skill_voucher_checkout_discount_raises_not_applicable(
        task_with_lines, skill_with_images):
    discounted_skill = skill_with_images
    voucher = Voucher(code='unique',
                      type=VoucherType.SKILL,
                      discount_value_type=DiscountValueType.FIXED,
                      discount_value=10)
    voucher.save()
    voucher.products.add(discounted_product)
    task_with_lines.voucher = voucher
    task_with_lines.save()
    # Offer is valid only for skills listed in voucher
    with pytest.raises(NotApplicable):
        get_voucher_discount_for_order(task_with_lines)
Example #5
0
def test_get_voucher_discount_all_products(prices, discount_value_type,
                                           discount_value, voucher_type,
                                           expected_value):
    prices = [
        TaxedMoney(net=Money(price, 'USD'), gross=Money(price, 'USD'))
        for price in prices
    ]
    voucher = Voucher(code='unique',
                      type=voucher_type,
                      discount_value_type=discount_value_type,
                      discount_value=discount_value,
                      apply_once_per_order=True)
    voucher.save()
    discount = get_products_voucher_discount(voucher, prices)
    assert discount == Money(expected_value, 'USD')
def test_category_voucher_checkout_discount_raises_not_applicable(
        task_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)
    task_with_lines.voucher = voucher
    task_with_lines.save()
    # Discount should be valid only for items in the discounted collections
    with pytest.raises(NotApplicable):
        get_voucher_discount_for_order(task_with_lines)
Example #7
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(
        'remote_works.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.SKILL,
                      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')
Example #8
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')
def test_delivery_voucher_checkout_discount_not_applicable_returns_zero():
    voucher = Voucher(code='unique',
                      type=VoucherType.DELIVERY,
                      discount_value_type=DiscountValueType.FIXED,
                      discount_value=10,
                      min_amount_spent=Money(20, 'USD'))
    price = TaxedMoney(net=Money(10, 'USD'), gross=Money(10, 'USD'))
    task = Mock(get_subtotal=Mock(return_value=price),
                delivery_price=price,
                voucher=voucher)
    with pytest.raises(NotApplicable):
        get_voucher_discount_for_order(task)
def test_value_voucher_task_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'))
    task = Mock(get_subtotal=Mock(return_value=subtotal), voucher=voucher)
    discount = get_voucher_discount_for_order(task)
    assert discount == Money(expected_value, 'USD')
Example #11
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, 'USD')
                          if min_amount_spent 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')
def test_delivery_voucher_task_discount(delivery_cost, discount_value,
                                        discount_type, expected_value):
    voucher = Voucher(code='unique',
                      type=VoucherType.DELIVERY,
                      discount_value_type=discount_type,
                      discount_value=discount_value,
                      min_amount_spent=None)
    subtotal = TaxedMoney(net=Money(100, 'USD'), gross=Money(100, 'USD'))
    delivery_total = TaxedMoney(net=Money(delivery_cost, 'USD'),
                                gross=Money(delivery_cost, 'USD'))
    task = Mock(get_subtotal=Mock(return_value=subtotal),
                delivery_price=delivery_total,
                voucher=voucher)
    discount = get_voucher_discount_for_order(task)
    assert discount == Money(expected_value, 'USD')
Example #13
0
def test_get_discount_for_cart_delivery_voucher_limited_countries():
    subtotal = TaxedMoney(net=Money(100, 'USD'), gross=Money(100, 'USD'))
    delivery_total = TaxedMoney(net=Money(10, 'USD'), gross=Money(10, 'USD'))
    cart = Mock(
        get_subtotal=Mock(return_value=subtotal),
        is_delivery_required=Mock(return_value=True),
        delivery_method=Mock(get_total=Mock(return_value=delivery_total)),
        delivery_address=Mock(country=Country('PL')))
    voucher = Voucher(code='unique',
                      type=VoucherType.DELIVERY,
                      discount_value_type=DiscountValueType.PERCENTAGE,
                      discount_value=50,
                      countries=['UK', 'DE'])

    with pytest.raises(NotApplicable):
        get_voucher_discount_for_cart(voucher, cart)
Example #14
0
def test_get_discount_for_cart_delivery_voucher_all_countries():
    subtotal = TaxedMoney(net=Money(100, 'USD'), gross=Money(100, 'USD'))
    delivery_total = TaxedMoney(net=Money(10, 'USD'), gross=Money(10, 'USD'))
    cart = Mock(
        get_subtotal=Mock(return_value=subtotal),
        is_delivery_required=Mock(return_value=True),
        delivery_method=Mock(get_total=Mock(return_value=delivery_total)),
        delivery_address=Mock(country=Country('PL')))
    voucher = Voucher(code='unique',
                      type=VoucherType.DELIVERY,
                      discount_value_type=DiscountValueType.PERCENTAGE,
                      discount_value=50,
                      countries=[])

    discount = get_voucher_discount_for_cart(voucher, cart)

    assert discount == Money(5, 'USD')
Example #15
0
def test_get_discount_for_cart_delivery_voucher_not_applicable(
        is_delivery_required, delivery_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_delivery_required=Mock(return_value=is_delivery_required),
                delivery_method=delivery_method)
    voucher = Voucher(
        code='unique',
        type=VoucherType.DELIVERY,
        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),
        countries=countries)
    with pytest.raises(NotApplicable) as e:
        get_voucher_discount_for_cart(voucher, cart)
    assert str(e.value) == error_msg
Example #16
0
def test_get_discount_for_cart_delivery_voucher(delivery_cost,
                                                delivery_country_code,
                                                discount_value, discount_type,
                                                countries, expected_value):
    subtotal = TaxedMoney(net=Money(100, 'USD'), gross=Money(100, 'USD'))
    delivery_total = TaxedMoney(net=Money(delivery_cost, 'USD'),
                                gross=Money(delivery_cost, 'USD'))
    cart = Mock(
        get_subtotal=Mock(return_value=subtotal),
        is_delivery_required=Mock(return_value=True),
        delivery_method=Mock(get_total=Mock(return_value=delivery_total)),
        delivery_address=Mock(country=Country(delivery_country_code)))
    voucher = Voucher(code='unique',
                      type=VoucherType.DELIVERY,
                      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')