Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add changes from review
Aleksander Spyra53574032ab30
diff --git a/saleor/giftcard/error_codes.py b/saleor/giftcard/error_codes.pyindex ff1316b6f9..c81ddbe3cd 100644--- a/saleor/giftcard/error_codes.py+++ b/saleor/giftcard/error_codes.py@@ -1,7 +1,7 @@from enum import Enum-class GiftcardErrorCode(Enum):+class GiftCardErrorCode(Enum):ALREADY_EXISTS = "already_exists"GRAPHQL_ERROR = "graphql_error"INVALID = "invalid"diff --git a/saleor/graphql/core/enums.py b/saleor/graphql/core/enums.pyindex e7154ba486..a8a72de429 100644--- a/saleor/graphql/core/enums.py+++ b/saleor/graphql/core/enums.py@@ -75,7 +75,7 @@ CheckoutErrorCode = graphene.Enum.from_enum(checkout_error_codes.CheckoutErrorCoExtensionsErrorCode = graphene.Enum.from_enum(extensions_error_codes.ExtensionsErrorCode)-GiftcardErrorCode = graphene.Enum.from_enum(giftcard_error_codes.GiftcardErrorCode)+GiftCardErrorCode = graphene.Enum.from_enum(giftcard_error_codes.GiftCardErrorCode)MenuErrorCode = graphene.Enum.from_enum(menu_error_codes.MenuErrorCode)OrderErrorCode = graphene.Enum.from_enum(order_error_codes.OrderErrorCode)PaymentErrorCode = graphene.Enum.from_enum(payment_error_codes.PaymentErrorCode)diff --git a/saleor/graphql/core/types/common.py b/saleor/graphql/core/types/common.pyindex 0cde4ebfad..728306f9c0 100644--- a/saleor/graphql/core/types/common.py+++ b/saleor/graphql/core/types/common.py@@ -6,7 +6,7 @@ from ..enums import (AccountErrorCode,CheckoutErrorCode,ExtensionsErrorCode,- GiftcardErrorCode,+ GiftCardErrorCode,MenuErrorCode,OrderErrorCode,PaymentErrorCode,@@ -69,8 +69,8 @@ class PaymentError(Error):code = PaymentErrorCode(description="The error code.")-class GiftcardError(Error):- code = GiftcardErrorCode(description="The error code.")+class GiftCardError(Error):+ code = GiftCardErrorCode(description="The error code.")class ExtensionsError(Error):diff --git a/saleor/graphql/core/utils/error_codes.py b/saleor/graphql/core/utils/error_codes.pyindex a24adf7afa..290a3f320b 100644--- a/saleor/graphql/core/utils/error_codes.py+++ b/saleor/graphql/core/utils/error_codes.py@@ -4,7 +4,7 @@ from ....account.error_codes import AccountErrorCodefrom ....checkout.error_codes import CheckoutErrorCodefrom ....core.error_codes import ShopErrorCodefrom ....extensions.error_codes import ExtensionsErrorCode-from ....giftcard.error_codes import GiftcardErrorCode+from ....giftcard.error_codes import GiftCardErrorCodefrom ....menu.error_codes import MenuErrorCodefrom ....order.error_codes import OrderErrorCodefrom ....payment.error_codes import PaymentErrorCode@@ -43,7 +43,7 @@ SALEOR_ERROR_CODE_ENUMS = [AccountErrorCode,CheckoutErrorCode,ExtensionsErrorCode,- GiftcardErrorCode,+ GiftCardErrorCode,MenuErrorCode,OrderErrorCode,PaymentErrorCode,diff --git a/saleor/graphql/extensions/mutations.py b/saleor/graphql/extensions/mutations.pyindex e65100f499..46ddd7ec30 100644--- a/saleor/graphql/extensions/mutations.py+++ b/saleor/graphql/extensions/mutations.py@@ -6,7 +6,7 @@ from ..core.types.common import ExtensionsErrorfrom .types import Plugin-class ExtensionsErrorMixin:+class ExtensionErrorMixin:extensions_errors = graphene.List(graphene.NonNull(ExtensionsError),description="List of errors that occurred executing the mutation.",@@ -34,7 +34,7 @@ class PluginUpdateInput(graphene.InputObjectType):)-class PluginUpdate(ExtensionsErrorMixin, BaseMutation):+class PluginUpdate(ExtensionErrorMixin, BaseMutation):plugin = graphene.Field(Plugin)class Arguments:diff --git a/saleor/graphql/giftcard/mutations.py b/saleor/graphql/giftcard/mutations.pyindex 2c3f763802..ebba5e4722 100644--- a/saleor/graphql/giftcard/mutations.py+++ b/saleor/graphql/giftcard/mutations.py@@ -8,25 +8,25 @@ from ...core.utils.promo_code import (is_available_promo_code,)from ...giftcard import models-from ...giftcard.error_codes import GiftcardErrorCode+from ...giftcard.error_codes import GiftCardErrorCodefrom ...giftcard.utils import activate_gift_card, deactivate_gift_cardfrom ..core.mutations import BaseMutation, ModelMutationfrom ..core.scalars import Decimal-from ..core.types.common import GiftcardError+from ..core.types.common import GiftCardErrorfrom .types import GiftCard-class GiftcardErrorMixin:+class GiftCardErrorMixin:gift_card_errors = graphene.List(- graphene.NonNull(GiftcardError),+ graphene.NonNull(GiftCardError),description="List of errors that occurred executing the mutation.",)- ERROR_TYPE_CLASS = GiftcardError+ ERROR_TYPE_CLASS = GiftCardErrorERROR_TYPE_FIELD = "gift_card_errors"-class BaseGiftcardMutation(GiftcardErrorMixin, BaseMutation):+class BaseGiftcardMutation(GiftCardErrorMixin, BaseMutation):class Meta:abstract = True@@ -48,7 +48,7 @@ class GiftCardCreateInput(GiftCardUpdateInput):code = graphene.String(required=False, description="Code to use the gift card.")-class GiftCardCreate(GiftcardErrorMixin, ModelMutation):+class GiftCardCreate(GiftCardErrorMixin, ModelMutation):class Arguments:input = GiftCardCreateInput(required=True, description="Fields required to create a gift card."@@ -65,7 +65,7 @@ class GiftCardCreate(GiftcardErrorMixin, ModelMutation):if not code and not instance.pk:data["code"] = generate_promo_code()elif not is_available_promo_code(code):- raise PromoCodeAlreadyExists(code=GiftcardErrorCode.ALREADY_EXISTS)+ raise PromoCodeAlreadyExists(code=GiftCardErrorCode.ALREADY_EXISTS)cleaned_input = super().clean_input(info, instance, data)balance = cleaned_input.get("balance", None)if balance:@@ -80,7 +80,7 @@ class GiftCardCreate(GiftcardErrorMixin, ModelMutation):{"email": ValidationError("Customer with this email doesn't exist.",- code=GiftcardErrorCode.NOT_FOUND,+ code=GiftCardErrorCode.NOT_FOUND,)})diff --git a/saleor/graphql/order/mutations/draft_orders.py b/saleor/graphql/order/mutations/draft_orders.pyindex c304b1383d..285f447fe2 100644--- a/saleor/graphql/order/mutations/draft_orders.py+++ b/saleor/graphql/order/mutations/draft_orders.py@@ -294,7 +294,7 @@ class DraftOrderLinesCreate(BaseOrderMutation):{"id": ValidationError("Only draft orders can be edited.",- code=OrderErrorCode.EDIT_NON_DRAFT_ORDER,+ code=OrderErrorCode.NOT_EDITABLE,)})@@ -356,7 +356,7 @@ class DraftOrderLineDelete(BaseOrderMutation):{"id": ValidationError("Only draft orders can be edited.",- code=OrderErrorCode.EDIT_NON_DRAFT_ORDER,+ code=OrderErrorCode.NOT_EDITABLE,)})@@ -397,7 +397,7 @@ class DraftOrderLineUpdate(OrderErrorMixin, ModelMutation):{"id": ValidationError("Only draft orders can be edited.",- code=OrderErrorCode.EDIT_NON_DRAFT_ORDER,+ code=OrderErrorCode.NOT_EDITABLE,)})diff --git a/saleor/graphql/product/mutations/attributes.py b/saleor/graphql/product/mutations/attributes.pyindex 864e2650ef..9bc1bad315 100644--- a/saleor/graphql/product/mutations/attributes.py+++ b/saleor/graphql/product/mutations/attributes.py@@ -266,7 +266,7 @@ class AttributeUpdate(ProductErrorMixin, AttributeMixin, ModelMutation):raise ValidationError({"remove_values": ValidationError(- msg, code=ProductErrorCode.ATTRIBUTE_BAD_VALUE+ msg, code=ProductErrorCode.INVALID)})@@ -429,7 +429,7 @@ class AttributeAssign(BaseProductMutation):{"operations": ValidationError("Variants are disabled in this product type.",- code=ProductErrorCode.ATTRIBUTE_DISABLED_VARIANTS,+ code=ProductErrorCode.ATTRIBUTE_VARIANTS_DISABLED,)})diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 6ee7988064..b8b0f63d69 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -1630,7 +1630,7 @@ type GiftCard implements Node {type GiftCardActivate {errors: [Error!]- giftCardErrors: [GiftcardError!]+ giftCardErrors: [GiftCardError!]giftCard: GiftCard}@@ -1647,7 +1647,7 @@ type GiftCardCountableEdge {type GiftCardCreate {errors: [Error!]- giftCardErrors: [GiftcardError!]+ giftCardErrors: [GiftCardError!]giftCard: GiftCard}@@ -1661,30 +1661,17 @@ input GiftCardCreateInput {type GiftCardDeactivate {errors: [Error!]- giftCardErrors: [GiftcardError!]+ giftCardErrors: [GiftCardError!]giftCard: GiftCard}-type GiftCardUpdate {- errors: [Error!]- giftCardErrors: [GiftcardError!]- giftCard: GiftCard-}--input GiftCardUpdateInput {- startDate: Date- endDate: Date- balance: Decimal- userEmail: String-}--type GiftcardError {+type GiftCardError {field: Stringmessage: String- code: GiftcardErrorCode+ code: GiftCardErrorCode}-enum GiftcardErrorCode {+enum GiftCardErrorCode {ALREADY_EXISTSGRAPHQL_ERRORINVALID@@ -1693,6 +1680,19 @@ enum GiftcardErrorCode {UNIQUE}+type GiftCardUpdate {+ errors: [Error!]+ giftCardErrors: [GiftCardError!]+ giftCard: GiftCard+}++input GiftCardUpdateInput {+ startDate: Date+ endDate: Date+ balance: Decimal+ userEmail: String+}+type HomepageCollectionUpdate {errors: [Error!]shopErrors: [ShopError!]@@ -2337,7 +2337,7 @@ enum OrderErrorCode {CANNOT_DELETECANNOT_REFUNDCAPTURE_INACTIVE_PAYMENT- EDIT_NON_DRAFT_ORDER+ NOT_EDITABLEFULFILL_ORDER_LINEGRAPHQL_ERRORINVALID@@ -2886,9 +2886,8 @@ type ProductError {enum ProductErrorCode {ALREADY_EXISTSATTRIBUTE_ALREADY_ASSIGNED- ATTRIBUTE_BAD_VALUEATTRIBUTE_CANNOT_BE_ASSIGNED- ATTRIBUTE_DISABLED_VARIANTS+ ATTRIBUTE_VARIANTS_DISABLEDGRAPHQL_ERRORINVALIDNOT_PRODUCTS_IMAGEdiff --git a/saleor/order/error_codes.py b/saleor/order/error_codes.pyindex e380da0bee..2040b5e92b 100644--- a/saleor/order/error_codes.py+++ b/saleor/order/error_codes.py@@ -7,7 +7,7 @@ class OrderErrorCode(Enum):CANNOT_DELETE = "cannot_delete"CANNOT_REFUND = "cannot_refund"CAPTURE_INACTIVE_PAYMENT = "capture_inactive_payment"- EDIT_NON_DRAFT_ORDER = "edit_non_draft_order"+ NOT_EDITABLE = "not_editable"FULFILL_ORDER_LINE = "fulfill_order_line"GRAPHQL_ERROR = "graphql_error"INVALID = "invalid"diff --git a/saleor/product/error_codes.py b/saleor/product/error_codes.pyindex df2a238d15..834303aa6f 100644--- a/saleor/product/error_codes.py+++ b/saleor/product/error_codes.py@@ -4,9 +4,8 @@ from enum import Enumclass ProductErrorCode(Enum):ALREADY_EXISTS = "already_exists"ATTRIBUTE_ALREADY_ASSIGNED = "attribute_already_assigned"- ATTRIBUTE_BAD_VALUE = "attribute_bad_value"ATTRIBUTE_CANNOT_BE_ASSIGNED = "attribute_cannot_be_assigned"- ATTRIBUTE_DISABLED_VARIANTS = "attribute_disabled_variants"+ ATTRIBUTE_VARIANTS_DISABLED = "attribute_variants_disabled"GRAPHQL_ERROR = "graphql_error"INVALID = "invalid"NOT_PRODUCTS_IMAGE = "not_products_image"diff --git a/tests/api/test_attributes.py b/tests/api/test_attributes.pyindex 6d819714af..674ce8797a 100644--- a/tests/api/test_attributes.py+++ b/tests/api/test_attributes.py@@ -695,7 +695,7 @@ def test_update_attribute_and_remove_others_attribute_value(assert errors[0]["message"] == err_msgproduct_errors = content["data"]["attributeUpdate"]["productErrors"]- assert product_errors[0]["code"] == ProductErrorCode.ATTRIBUTE_BAD_VALUE.name+ assert product_errors[0]["code"] == ProductErrorCode.INVALID.namedef test_delete_attribute(diff --git a/tests/api/test_gift_card.py b/tests/api/test_gift_card.pyindex e11dd6cc16..2e6ee6986d 100644--- a/tests/api/test_gift_card.py+++ b/tests/api/test_gift_card.py@@ -2,7 +2,7 @@ from datetime import dateimport graphene-from saleor.giftcard.error_codes import GiftcardErrorCode+from saleor.giftcard.error_codes import GiftCardErrorCodefrom tests.api.utils import get_graphql_contentfrom .utils import assert_no_permission@@ -290,7 +290,7 @@ def test_create_gift_card_with_existing_voucher_code(assert errors[0]["field"] == "promoCode"gift_card_errors = content["data"]["giftCardCreate"]["giftCardErrors"]- assert gift_card_errors[0]["code"] == GiftcardErrorCode.ALREADY_EXISTS.name+ assert gift_card_errors[0]["code"] == GiftCardErrorCode.ALREADY_EXISTS.namedef test_create_gift_card_with_existing_gift_card_code(@@ -308,7 +308,7 @@ def test_create_gift_card_with_existing_gift_card_code(assert errors[0]["field"] == "promoCode"gift_card_errors = content["data"]["giftCardCreate"]["giftCardErrors"]- assert gift_card_errors[0]["code"] == GiftcardErrorCode.ALREADY_EXISTS.name+ assert gift_card_errors[0]["code"] == GiftCardErrorCode.ALREADY_EXISTS.namedef test_create_gift_card_without_user(staff_api_client, permission_manage_gift_card):@@ -361,7 +361,7 @@ def test_create_gift_card_with_incorrect_user_email(assert errors[0]["message"] == "Customer with this email doesn't exist."gift_card_errors = content["data"]["giftCardCreate"]["giftCardErrors"]- assert gift_card_errors[0]["code"] == GiftcardErrorCode.NOT_FOUND.name+ assert gift_card_errors[0]["code"] == GiftCardErrorCode.NOT_FOUND.namedef test_create_gift_card_without_premissions(staff_api_client):