def test_get_shipping_voucher_discount(total, limit, shipping_price, discount_value, discount_value_type, expected_value): voucher = Voucher(code='unique', type=VoucherType.VALUE, discount_value_type=discount_value_type, discount_value=discount_value, limit=Money(limit, 'USD') if limit is not None else None) total = TaxedMoney(net=Money(total, 'USD'), gross=Money(total, 'USD')) shipping_price = TaxedMoney(net=Money(shipping_price, 'USD'), gross=Money(shipping_price, 'USD')) discount = get_shipping_voucher_discount(voucher, total, shipping_price) assert discount == Money(expected_value, 'USD')
def test_get_shipping_voucher_discount(total, min_amount_spent, shipping_price, 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 = TaxedMoney(net=Money(total, 'USD'), gross=Money(total, 'USD')) shipping_price = TaxedMoney(net=Money(shipping_price, 'USD'), gross=Money(shipping_price, 'USD')) discount = get_shipping_voucher_discount(voucher, total, shipping_price) assert discount == Money(expected_value, 'USD')
def test_get_shipping_voucher_discount_not_applicable( total, min_amount_spent, total_quantity, min_checkout_items_quantity, shipping_price, discount_value, discount_value_type, ): voucher = Voucher( code="unique", type=VoucherType.ENTIRE_ORDER, discount_value_type=discount_value_type, discount_value=discount_value, min_amount_spent=get_min_amount_spent(min_amount_spent), min_checkout_items_quantity=min_checkout_items_quantity, ) voucher.save() total = Money(total, "USD") shipping_price = Money(shipping_price, "USD") with pytest.raises(NotApplicable): get_shipping_voucher_discount(voucher, total, shipping_price, total_quantity)
def test_get_shipping_voucher_discount( total, min_amount_spent, shipping_price, 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 = TaxedMoney( net=Money(total, 'USD'), gross=Money(total, 'USD')) shipping_price = TaxedMoney( net=Money(shipping_price, 'USD'), gross=Money(shipping_price, 'USD')) discount = get_shipping_voucher_discount(voucher, total, shipping_price) assert discount == Money(expected_value, 'USD')
def test_get_shipping_voucher_discount( total, min_amount_spent, shipping_price, discount_value, discount_value_type, expected_value, ): voucher = Voucher( code="unique", type=VoucherType.ENTIRE_ORDER, discount_value_type=discount_value_type, discount_value=discount_value, min_amount_spent=get_min_amount_spent(min_amount_spent), ) voucher.save() total = Money(total, "USD") shipping_price = Money(shipping_price, "USD") discount = get_shipping_voucher_discount(voucher, total, shipping_price) assert discount == Money(expected_value, "USD")