Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Tests
Pacu268fddc002b5b
diff --git a/saleor/dashboard/discount/forms.py b/saleor/dashboard/discount/forms.pyindex e75382b70b..541fe87225 100644--- a/saleor/dashboard/discount/forms.py+++ b/saleor/dashboard/discount/forms.py@@ -178,15 +178,6 @@ class CommonVoucherForm(forms.ModelForm):use_required_attribute = False- def save(self, commit=True):- self.instance.limit = None- # Apply to one with percentage discount is more complicated case.- # On which product we should apply it? On first, last or cheapest?- # Percentage case is limited to the whole order.- if self.instance.discount_value_type == DiscountValueType.PERCENTAGE:- self.instance.apply_once_per_order = True- return super().save(commit)-class ProductVoucherForm(CommonVoucherForm):products = AjaxSelect2MultipleChoiceField(diff --git a/saleor/dashboard/order/utils.py b/saleor/dashboard/order/utils.pyindex 3d376e7055..fd6c9df4ab 100644--- a/saleor/dashboard/order/utils.py+++ b/saleor/dashboard/order/utils.py@@ -4,11 +4,9 @@ from django.template.loader import get_templatefrom ...checkout import AddressTypefrom ...checkout.utils import (- _get_products_voucher_discount,- get_prices_of_products_in_discounted_collections)+ _get_products_voucher_discount)from ...core.utils.taxes import ZERO_MONEYfrom ...discount import VoucherType-from ...discount.models import NotApplicablefrom ...discount.utils import (get_shipping_voucher_discount, get_value_voucher_discount)from ...product.utils import decrease_stockdiff --git a/tests/api/test_discount.py b/tests/api/test_discount.pyindex 9c75ac6056..9f232634e2 100644--- a/tests/api/test_discount.py+++ b/tests/api/test_discount.py@@ -322,7 +322,7 @@ def test_sale_delete_mutation(user_api_client, admin_api_client, sale):sale.refresh_from_db()-def test_validate_voucher(voucher, admin_api_client, product):+def test_validate_voucher(voucher, admin_api_client):query = """mutation voucherUpdate($id: ID!, $type: VoucherTypeEnum) {@@ -335,12 +335,19 @@ def test_validate_voucher(voucher, admin_api_client, product):}}"""- variables = json.dumps({- 'type': VoucherTypeEnum.PRODUCT.name,- 'id': graphene.Node.to_global_id('Voucher', voucher.id)})- response = admin_api_client.post(- reverse('api'), {'query': query, 'variables': variables})- content = get_graphql_content(response)- data = content['data']['voucherUpdate']['errors'][0]- assert data['field'] == 'products'- assert data['message'] == 'This field is required.'+ # apparently can't do so via pytest parametrize+ # as it parses VoucherTypeEnum into str format+ fields = (+ (VoucherTypeEnum.CATEGORY, 'categories'),+ (VoucherTypeEnum.PRODUCT, 'products'),+ (VoucherTypeEnum.COLLECTION, 'collections'))+ for voucher_type, field_name in fields:+ variables = json.dumps({+ 'type': voucher_type.name,+ 'id': graphene.Node.to_global_id('Voucher', voucher.id)})+ response = admin_api_client.post(+ reverse('api'), {'query': query, 'variables': variables})+ content = get_graphql_content(response)+ data = content['data']['voucherUpdate']['errors'][0]+ assert data['field'] == field_name+ assert data['message'] == 'This field is required.'diff --git a/tests/test_checkout.py b/tests/test_checkout.pyindex 0a3b5ceae3..45487779df 100644--- a/tests/test_checkout.py+++ b/tests/test_checkout.py@@ -13,13 +13,15 @@ from saleor.checkout.forms import CartVoucherFormfrom saleor.checkout.utils import (add_variant_to_cart, change_billing_address_in_cart,change_shipping_address_in_cart, create_order, get_cart_data_for_checkout,- get_taxes_for_cart, get_voucher_discount_for_cart, get_voucher_for_cart,+ get_prices_of_products_in_discounted_categories, get_taxes_for_cart,+ get_voucher_discount_for_cart, get_voucher_for_cart,recalculate_cart_discount, remove_voucher_from_cart)from saleor.core.exceptions import InsufficientStockfrom saleor.core.utils.taxes import (ZERO_MONEY, ZERO_TAXED_MONEY, get_taxes_for_country)from saleor.discount import DiscountValueType, VoucherTypefrom saleor.discount.models import NotApplicable, Voucher+from saleor.product.models import Categoryfrom .utils import compare_taxes, get_redirect_location@@ -868,3 +870,21 @@ def test_change_address_in_cart_from_user_address_to_other(assert cart.shipping_address == other_addressassert cart.billing_address == other_addressassert Address.objects.filter(id=address_id).exists()+++def test_get_prices_of_products_in_discounted_categories(cart_with_item):+ lines = cart_with_item.lines.all()+ # There's no discounted categories, therefore all of them are discoutned+ discounted_lines = get_prices_of_products_in_discounted_categories(+ lines, [])+ assert [+ line.variant.get_price()+ for line in lines+ for item in range(line.quantity)] == discounted_lines++ discounted_category = Category.objects.create(+ name='discounted', slug='discounted')+ discounted_lines = get_prices_of_products_in_discounted_categories(+ lines, [discounted_category])+ # None of the lines are belongs to the discounted category+ assert not discounted_lines