Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add and fix test for voucher with apply_once_per_order
fowczarek57435f0a4740
diff --git a/tests/conftest.py b/tests/conftest.pyindex d88835633a..82825bd840 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -93,6 +93,17 @@ def checkout_with_item(checkout, product):return checkout+def checkout_with_items(checkout, product_list, product):+ variant = product.variants.get()+ add_variant_to_checkout(checkout, variant, 1)+ for prod in product_list:+ variant = prod.variants.get()+ add_variant_to_checkout(checkout, variant, 1)+ checkout.save()+ return checkout++@pytest.fixturedef checkout_with_voucher(checkout, product, voucher):variant = product.variants.get()@@ -508,6 +519,12 @@ def product_list(product_type, category):),])+ sku = 0+ for product in products:+ ProductVariant.objects.create(+ product=product, sku=sku, track_inventory=True, quantity=100+ )+ sku = sku + 1return productsdiff --git a/tests/test_checkout.py b/tests/test_checkout.pyindex 0cb24e2e85..c89586fd46 100644--- a/tests/test_checkout.py+++ b/tests/test_checkout.py@@ -849,6 +849,38 @@ def test_get_discount_for_checkout_value_voucher(assert discount == Money(discount_amount, "USD")+ "discount_value, discount_type, apply_once_per_order, discount_amount",+ [+ (5, DiscountValueType.FIXED, True, 5),+ (5, DiscountValueType.FIXED, False, 15),+ (10000, DiscountValueType.FIXED, True, 10),+ (10, DiscountValueType.PERCENTAGE, True, 1),+ (10, DiscountValueType.PERCENTAGE, False, 5),+ ],+)+def test_get_discount_for_checkout_apply_once_per_order(+ checkout_with_items,+ product_list,+ discount_value,+ discount_type,+ apply_once_per_order,+ discount_amount,+):+ 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()+ for product in product_list:+ voucher.products.add(product)+ discount = get_voucher_discount_for_checkout(voucher, checkout_with_items)+ assert discount == Money(discount_amount, "USD")++def test_get_discount_for_checkout_value_voucher_not_applicable():voucher = Voucher(code="unique",diff --git a/tests/test_discounts.py b/tests/test_discounts.pyindex c921603157..45bf2cbb03 100644--- a/tests/test_discounts.py+++ b/tests/test_discounts.py@@ -1,8 +1,7 @@from datetime import date, timedelta-from prices import Money, TaxedMoney-import pytest+from prices import Money, TaxedMoneyfrom saleor.checkout.utils import get_voucher_discount_for_checkoutfrom saleor.discount import DiscountInfo, DiscountValueType, VoucherType@@ -89,8 +88,8 @@ def test_voucher_queryset_active(voucher):[([10], 10, DiscountValueType.FIXED, True, 10),([5], 10, DiscountValueType.FIXED, True, 5),- ([5, 5], 10, DiscountValueType.FIXED, True, 10),- ([2, 3], 10, DiscountValueType.FIXED, True, 5),+ ([5, 5], 10, DiscountValueType.FIXED, True, 5),+ ([2, 3], 10, DiscountValueType.FIXED, True, 2),([10, 10], 5, DiscountValueType.FIXED, False, 10),([5, 2], 5, DiscountValueType.FIXED, False, 7),([10, 10, 10], 5, DiscountValueType.FIXED, False, 15),@@ -244,8 +243,8 @@ def test_get_shipping_voucher_discount("prices, discount_value_type, discount_value, voucher_type, expected_value",[ # noqa([5, 10, 15], DiscountValueType.PERCENTAGE, 10, VoucherType.PRODUCT, 3),- ([5, 10, 15], DiscountValueType.FIXED, 2, VoucherType.PRODUCT, 2),- ([5, 10, 15], DiscountValueType.FIXED, 2, VoucherType.COLLECTION, 2),+ ([5, 10, 15], DiscountValueType.FIXED, 2, VoucherType.PRODUCT, 6),+ ([5, 10, 15], DiscountValueType.FIXED, 2, VoucherType.COLLECTION, 6),],)def test_get_voucher_discount_all_products(@@ -260,7 +259,6 @@ def test_get_voucher_discount_all_products(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)