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.SPECIFIC_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)
def test_category_voucher_checkout_discount_raises_not_applicable( order_with_lines): discounted_collection = Collection.objects.create(name="Discounted", slug="discount") 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)
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)
def test_value_voucher_order_discount(subtotal, discount_value, discount_type, min_spent_amount, expected_value): voucher = Voucher( code="unique", type=VoucherType.ENTIRE_ORDER, discount_value_type=discount_type, discount_value=discount_value, min_spent=Money(min_spent_amount, "USD") if min_spent_amount is not None else None, ) subtotal = Money(subtotal, "USD") subtotal = TaxedMoney(net=subtotal, gross=subtotal) order = Mock(get_subtotal=Mock(return_value=subtotal), voucher=voucher) discount = get_voucher_discount_for_order(order) assert discount == Money(expected_value, "USD")
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_spent_amount=None, ) subtotal = Money(100, "USD") subtotal = TaxedMoney(net=subtotal, gross=subtotal) shipping_total = 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")
def test_get_discount_for_order_specific_products_voucher( order_with_lines, discount_value, discount_type, apply_once_per_order, discount_amount, ): voucher = Voucher.objects.create( code="unique", type=VoucherType.SPECIFIC_PRODUCT, discount_value_type=discount_type, discount_value=discount_value, apply_once_per_order=apply_once_per_order, ) voucher.products.add(order_with_lines.lines.first().variant.product) voucher.products.add(order_with_lines.lines.last().variant.product) order_with_lines.voucher = voucher order_with_lines.save() discount = get_voucher_discount_for_order(order_with_lines) assert discount == Money(discount_amount, "USD")