Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Unify checkout mutations/resolvers to use id field. (#9862)

Maciej Korycinski3673e7e11f22
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fef390a0c7..fd06ee09c8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,6 +23,9 @@ All notable, unreleased changes to this project will be documented in this file.
- Migrate order discount id from int to UUID - #9729 by @IKarbowiak
- Changed the order discount `id` from `int` to `UUID`, the old ids still can be used
for old order discounts.
+- Unify checkout's ID fields. - #9862 by @korycins
+ - Deprecate `checkoutID` and `token` in all Checkout's mutations. Use `id` instead.
+ - Deprecate `token` in `checkout` query. Use `id` instead.
- Add `unitPrice`, `undiscountedUnitPrice`, `undiscountedTotalPrice` fields to `CheckoutLine` type - #9821 by @fowczarek
diff --git a/saleor/graphql/account/tests/test_account.py b/saleor/graphql/account/tests/test_account.py
index f229ee786d..473491ab69 100644
--- a/saleor/graphql/account/tests/test_account.py
+++ b/saleor/graphql/account/tests/test_account.py
@@ -34,7 +34,7 @@ from ....core.utils.url import prepare_url
from ....order import OrderStatus
from ....order.models import FulfillmentStatus, Order
from ....product.tests.utils import create_image
-from ...core.utils import str_to_enum
+from ...core.utils import str_to_enum, to_global_id_or_none
from ...tests.utils import (
assert_graphql_error_with_message,
assert_no_permission,
@@ -98,6 +98,7 @@ FULL_USER_QUERY = """
isDefaultShippingAddress
isDefaultBillingAddress
}
+ checkoutIds
orders(first: 10) {
totalCount
edges {
@@ -183,6 +184,7 @@ def test_query_customer_user(
permission_manage_orders,
media_root,
settings,
+ checkout,
):
user = customer_user
user.default_shipping_address.country = "US"
@@ -194,6 +196,9 @@ def test_query_customer_user(
user.avatar = avatar_mock
user.save()
+ checkout.user = user
+ checkout.save()
+
Group.objects.create(name="empty group")
query = FULL_USER_QUERY
@@ -264,6 +269,8 @@ def test_query_customer_user(
"GiftCard", gift_card_used.pk
)
+ assert data["checkoutIds"] == [to_global_id_or_none(checkout)]
+
def test_query_customer_user_with_orders(
staff_api_client,
diff --git a/saleor/graphql/account/types.py b/saleor/graphql/account/types.py
index bef916608d..f652987cf3 100644
--- a/saleor/graphql/account/types.py
+++ b/saleor/graphql/account/types.py
@@ -29,7 +29,7 @@ from ..core.federation import federated_entity, resolve_federation_references
from ..core.fields import ConnectionField, PermissionsField
from ..core.scalars import UUID
from ..core.types import CountryDisplay, Image, ModelObjectType, NonNullList, Permission
-from ..core.utils import from_global_id_or_error, str_to_enum
+from ..core.utils import from_global_id_or_error, str_to_enum, to_global_id_or_none
from ..giftcard.dataloaders import GiftCardsByUserLoader
from ..meta.types import ObjectWithMetadata
from ..order.dataloaders import OrderLineByIdLoader, OrdersByUserLoader
@@ -249,6 +249,14 @@ class User(ModelObjectType):
channel=graphene.String(
description="Slug of a channel for which the data should be returned."
),
+ deprecation_reason=(f"{DEPRECATED_IN_3X_FIELD} Use `checkoutIds` instead."),
+ )
+ checkout_ids = NonNullList(
+ graphene.ID,
+ description="Returns the checkout ID's assigned to this user.",
+ channel=graphene.String(
+ description="Slug of a channel for which the data should be returned."
+ ),
)
gift_cards = ConnectionField(
"saleor.graphql.giftcard.types.GiftCardCountableConnection",
@@ -337,6 +345,29 @@ class User(ModelObjectType):
.then(return_checkout_tokens)
)
+ @staticmethod
+ @traced_resolver
+ def resolve_checkout_ids(root: models.User, info, channel=None):
+ def return_checkout_ids(checkouts):
+ if not checkouts:
+ return []
+ checkout_global_ids = []
+ for checkout in checkouts:
+ checkout_global_ids.append(to_global_id_or_none(checkout))
+ return checkout_global_ids
+
+ if not channel:
+ return (
+ CheckoutByUserLoader(info.context)
+ .load(root.id)
+ .then(return_checkout_ids)
+ )
+ return (
+ CheckoutByUserAndChannelLoader(info.context)
+ .load((root.id, channel))
+ .then(return_checkout_ids)
+ )
+
@staticmethod
def resolve_gift_cards(root: models.User, info, **kwargs):
from ..giftcard.types import GiftCardCountableConnection
diff --git a/saleor/graphql/checkout/filters.py b/saleor/graphql/checkout/filters.py
index c0d4e51208..2997da1cf1 100644
--- a/saleor/graphql/checkout/filters.py
+++ b/saleor/graphql/checkout/filters.py
@@ -34,6 +34,13 @@ def get_payment_id_from_query(value):
return None
+def get_checkout_id_from_query(value):
+ try:
+ return from_global_id_or_error(value, only_type="Checkout")[1]
+ except Exception:
+ return None
+
+
def filter_checkout_by_payment(qs, payment_id):
if payment_id:
payments = Payment.objects.filter(pk=payment_id).values("id")
@@ -70,7 +77,9 @@ def filter_checkout_search(qs, _, value):
filter_option = Q(Exists(users.filter(id=OuterRef("user_id"))))
- if checkout_id := get_checkout_token_from_query(value):
+ possible_token = get_checkout_id_from_query(value) or value
+
+ if checkout_id := get_checkout_token_from_query(possible_token):
filter_option |= Q(token=checkout_id)
payments = Payment.objects.filter(psp_reference=value).values("id")
diff --git a/saleor/graphql/checkout/mutations/checkout_add_promo_code.py b/saleor/graphql/checkout/mutations/checkout_add_promo_code.py
index 541fccec10..6cc77b1793 100644
--- a/saleor/graphql/checkout/mutations/checkout_add_promo_code.py
+++ b/saleor/graphql/checkout/mutations/checkout_add_promo_code.py
@@ -9,13 +9,12 @@ from ....checkout.fetch import (
update_delivery_method_lists_for_checkout_info,
)
from ....checkout.utils import add_promo_code_to_checkout
-from ...core.descriptions import DEPRECATED_IN_3X_INPUT
+from ...core.descriptions import ADDED_IN_34, DEPRECATED_IN_3X_INPUT
from ...core.mutations import BaseMutation
from ...core.scalars import UUID
from ...core.types import CheckoutError
-from ...core.validators import validate_one_of_args_is_in_mutation
from ..types import Checkout
-from .utils import get_checkout_by_token, update_checkout_shipping_method_if_invalid
+from .utils import get_checkout, update_checkout_shipping_method_if_invalid
class CheckoutAddPromoCode(BaseMutation):
@@ -24,13 +23,20 @@ class CheckoutAddPromoCode(BaseMutation):
)
class Arguments:
+ id = graphene.ID(
+ description="The checkout's ID." + ADDED_IN_34,
+ required=False,
+ )
checkout_id = graphene.ID(
description=(
- f"The ID of the checkout. {DEPRECATED_IN_3X_INPUT} Use token instead."
+ f"The ID of the checkout.{DEPRECATED_IN_3X_INPUT} Use `id` instead."
),
required=False,
)
- token = UUID(description="Checkout token.", required=False)
+ token = UUID(
+ description=f"Checkout token.{DEPRECATED_IN_3X_INPUT} Use `id` instead.",
+ required=False,
+ )
promo_code = graphene.String(
description="Gift card code or voucher code.", required=True
)
@@ -41,20 +47,18 @@ class CheckoutAddPromoCode(BaseMutation):
error_type_field = "checkout_errors"
@classmethod
- def perform_mutation(cls, _root, info, promo_code, checkout_id=None, token=None):
- # DEPRECATED
- validate_one_of_args_is_in_mutation(
- CheckoutErrorCode, "checkout_id", checkout_id, "token", token
+ def perform_mutation(
+ cls, _root, info, promo_code, checkout_id=None, token=None, id=None
+ ):
+ checkout = get_checkout(
+ cls,
+ info,
+ checkout_id=checkout_id,
+ token=token,
+ id=id,
+ error_class=CheckoutErrorCode,
)
- if token:
- checkout = get_checkout_by_token(token)
- # DEPRECATED
- else:
- checkout = cls.get_node_or_error(
- info, checkout_id or token, only_type=Checkout, field="checkout_id"
- )
-
validate_checkout_email(checkout)
manager = info.context.plugins
diff --git a/saleor/graphql/checkout/mutations/checkout_billing_address_update.py b/saleor/graphql/checkout/mutations/checkout_billing_address_update.py
index bb867c19af..f12c529815 100644
--- a/saleor/graphql/checkout/mutations/checkout_billing_address_update.py
+++ b/saleor/graphql/checkout/mutations/checkout_billing_address_update.py
@@ -5,27 +5,32 @@ from ....checkout.error_codes import CheckoutErrorCode
from ....checkout.utils import change_billing_address_in_checkout
from ....core.tracing import traced_atomic_transaction
from ...account.types import AddressInput
-from ...core.descriptions import DEPRECATED_IN_3X_INPUT
+from ...core.descriptions import ADDED_IN_34, DEPRECATED_IN_3X_INPUT
from ...core.scalars import UUID
from ...core.types import CheckoutError
-from ...core.validators import validate_one_of_args_is_in_mutation
from ..types import Checkout
from .checkout_shipping_address_update import CheckoutShippingAddressUpdate
-from .utils import get_checkout_by_token
+from .utils import get_checkout
class CheckoutBillingAddressUpdate(CheckoutShippingAddressUpdate):
checkout = graphene.Field(Checkout, description="An updated checkout.")
class Arguments:
+ id = graphene.ID(
+ description="The checkout's ID." + ADDED_IN_34,
+ required=False,
+ )
+ token = UUID(
+ description=f"Checkout token.{DEPRECATED_IN_3X_INPUT} Use `id` instead.",
+ required=False,
+ )
checkout_id = graphene.ID(
required=False,
description=(
- f"The ID of the checkout. {DEPRECATED_IN_3X_INPUT} "
- "Use token instead."
+ f"The ID of the checkout. {DEPRECATED_IN_3X_INPUT} Use `id` instead."
),
)
- token = UUID(description="Checkout token.", required=False)
billing_address = AddressInput(
required=True, description="The billing address of the checkout."
)
@@ -37,21 +42,17 @@ class CheckoutBillingAddressUpdate(CheckoutShippingAddressUpdate):
@classmethod
def perform_mutation(
- cls, _root, info, billing_address, checkout_id=None, token=None
+ cls, _root, info, billing_address, checkout_id=None, token=None, id=None
):
- # DEPRECATED
- validate_one_of_args_is_in_mutation(
- CheckoutErrorCode, "checkout_id", checkout_id, "token", token
+ checkout = get_checkout(
+ cls,
+ info,
+ checkout_id=checkout_id,
+ token=token,
+ id=id,
+ error_class=CheckoutErrorCode,
)
- if token:
- checkout = get_checkout_by_token(token)
- # DEPRECATED
- else:
- checkout = cls.get_node_or_error(
- info, checkout_id or token, only_type=Checkout, field="checkout_id"
- )
-
billing_address = cls.validate_address(
billing_address,
address_type=AddressType.BILLING,
diff --git a/saleor/graphql/checkout/mutations/checkout_complete.py b/saleor/graphql/checkout/mutations/checkout_complete.py
index d5d9983494..169c18dac8 100644
--- a/saleor/graphql/checkout/mutations/checkout_complete.py
+++ b/saleor/graphql/checkout/mutations/checkout_complete.py
@@ -10,7 +10,7 @@ from ....core import analytics
from ....core.permissions import AccountPermissions
from ....core.transactions import transaction_with_commit_on_errors
from ....order import models as order_models
-from ...core.descriptions import DEPRECATED_IN_3X_INPUT
+from ...core.descriptions import ADDED_IN_34, DEPRECATED_IN_3X_INPUT
from ...core.fields import JSONString
from ...core.mutations import BaseMutation
from ...core.scalars import UUID
@@ -19,7 +19,7 @@ from ...core.validators import validate_one_of_args_is_in_mutation
from ...order.types import Order
from ...utils import get_user_or_app_from_context
from ..types import Checkout
-from .utils import get_checkout_by_token
+from .utils import get_checkout
class CheckoutComplete(BaseMutation):
@@ -40,13 +40,20 @@ class CheckoutComplete(BaseMutation):
)
class Arguments:
+ id = graphene.ID(
+ description="The checkout's ID." + ADDED_IN_34,
+ required=False,
+ )
+ token = UUID(
+ description=f"Checkout token.{DEPRECATED_IN_3X_INPUT} Use `id` instead.",
+ required=False,
+ )
checkout_id = graphene.ID(
+ required=False,
description=(
- f"The ID of the checkout. {DEPRECATED_IN_3X_INPUT} Use token instead."
+ f"The ID of the checkout. {DEPRECATED_IN_3X_INPUT} Use `id` instead."
),
- required=False,
)
- token = UUID(description="Checkout token.", required=False)
store_source = graphene.Boolean(
default_value=False,
description=(
@@ -82,31 +89,30 @@ class CheckoutComplete(BaseMutation):
@classmethod
def perform_mutation(
- cls, _root, info, store_source, checkout_id=None, token=None, **data
+ cls, _root, info, store_source, checkout_id=None, token=None, id=None, **data
):
# DEPRECATED
validate_one_of_args_is_in_mutation(
- CheckoutErrorCode, "checkout_id", checkout_id, "token", token
+ CheckoutErrorCode, "checkout_id", checkout_id, "token", token, "id", id
)
tracking_code = analytics.get_client_id(info.context)
with transaction_with_commit_on_errors():
try:
- if token:
- checkout = get_checkout_by_token(token)
- # DEPRECATED
- else:
- checkout = cls.get_node_or_error(
- info,
- checkout_id or token,
- only_type=Checkout,
- field="checkout_id",
- )
+ checkout = get_checkout(
+ cls,
+ info,
+ checkout_id=checkout_id,
+ token=token,
+ id=id,
+ error_class=CheckoutErrorCode,
+ )
except ValidationError as e:
# DEPRECATED
- if checkout_id:
+ if id or checkout_id:
+ id = id or checkout_id
token = cls.get_global_id_or_error(
- checkout_id, only_type=Checkout, field="checkout_id"
+ id, only_type=Checkout, field="id" if id else "checkout_id"
)
order = order_models.Order.objects.get_by_checkout_token(token)
diff --git a/saleor/graphql/checkout/mutations/checkout_customer_attach.py b/saleor/graphql/checkout/mutations/checkout_customer_attach.py
index 17a7d17035..274f983171 100644
--- a/saleor/graphql/checkout/mutations/checkout_customer_attach.py
+++ b/saleor/graphql/checkout/mutations/checkout_customer_attach.py
@@ -4,24 +4,31 @@ from django.forms import ValidationError
from ....checkout.error_codes import CheckoutErrorCode
from ....core.exceptions import PermissionDenied
from ....core.permissions import AccountPermissions, AuthorizationFilters
-from ...core.descriptions import DEPRECATED_IN_3X_INPUT
+from ...core.descriptions import ADDED_IN_34, DEPRECATED_IN_3X_INPUT
from ...core.mutations import BaseMutation
from ...core.scalars import UUID
from ...core.types import CheckoutError
-from ...core.validators import validate_one_of_args_is_in_mutation
from ...utils import get_user_or_app_from_context
from ..types import Checkout
-from .utils import get_checkout_by_token
+from .utils import get_checkout
class CheckoutCustomerAttach(BaseMutation):
checkout = graphene.Field(Checkout, description="An updated checkout.")
class Arguments:
+ id = graphene.ID(
+ description="The checkout's ID." + ADDED_IN_34,
+ required=False,
+ )
+ token = UUID(
+ description=f"Checkout token.{DEPRECATED_IN_3X_INPUT} Use `id` instead.",
+ required=False,
+ )
checkout_id = graphene.ID(
required=False,
description=(
- f"The ID of the checkout. {DEPRECATED_IN_3X_INPUT} Use token instead."
+ f"The ID of the checkout. {DEPRECATED_IN_3X_INPUT} Use `id` instead."
),
)
customer_id = graphene.ID(
@@ -31,7 +38,6 @@ class CheckoutCustomerAttach(BaseMutation):
"to checkout by staff or app. Requires IMPERSONATE_USER permission."
),
)
- token = UUID(description="Checkout token.", required=False)
class Meta:
description = "Sets the customer as the owner of the checkout."
@@ -44,21 +50,17 @@ class CheckoutCustomerAttach(BaseMutation):
@classmethod
def perform_mutation(
- cls, _root, info, checkout_id=None, token=None, customer_id=None
+ cls, _root, info, checkout_id=None, token=None, customer_id=None, id=None
):
- # DEPRECATED
- validate_one_of_args_is_in_mutation(
- CheckoutErrorCode, "checkout_id", checkout_id, "token", token
+ checkout = get_checkout(
+ cls,
+ info,
+ checkout_id=checkout_id,
+ token=token,
+ id=id,
+ error_class=CheckoutErrorCode,
)
- if token:
- checkout = get_checkout_by_token(token)
- # DEPRECATED
- else:
- checkout = cls.get_node_or_error(
- info, checkout_id or token, only_type=Checkout, field="checkout_id"
- )
-
# Raise error when trying to attach a user to a checkout
# that is already owned by another user.
if checkout.user_id:
diff --git a/saleor/graphql/checkout/mutations/checkout_customer_detach.py b/saleor/graphql/checkout/mutations/checkout_customer_detach.py
index 1bf4201a45..f6c849bd0b 100644
--- a/saleor/graphql/checkout/mutations/checkout_customer_detach.py
+++ b/saleor/graphql/checkout/mutations/checkout_customer_detach.py
@@ -3,27 +3,33 @@ import graphene
from ....checkout.error_codes import CheckoutErrorCode
from ....core.exceptions import PermissionDenied
from ....core.permissions import AccountPermissions, AuthorizationFilters
-from ...core.descriptions import DEPRECATED_IN_3X_INPUT
+from ...core.descriptions import ADDED_IN_34, DEPRECATED_IN_3X_INPUT
from ...core.mutations import BaseMutation
from ...core.scalars import UUID
from ...core.types import CheckoutError
-from ...core.validators import validate_one_of_args_is_in_mutation
from ...utils import get_user_or_app_from_context
from ..types import Checkout
-from .utils import get_checkout_by_token
+from .utils import get_checkout
class CheckoutCustomerDetach(BaseMutation):
checkout = graphene.Field(Checkout, description="An updated checkout.")
class Arguments:
+ id = graphene.ID(
+ description="The checkout's ID." + ADDED_IN_34,
+ required=False,
+ )
+ token = UUID(
+ description=f"Checkout token.{DEPRECATED_IN_3X_INPUT} Use `id` instead.",
+ required=False,
+ )
checkout_id = graphene.ID(
+ required=False,
description=(
- f"The ID of the checkout. {DEPRECATED_IN_3X_INPUT} Use token instead."
+ f"The ID of the checkout. {DEPRECATED_IN_3X_INPUT} Use `id` instead."
),
- required=False,
)
- token = UUID(description="Checkout token.", required=False)
class Meta:
description = "Removes the user assigned as the owner of the checkout."
@@ -35,20 +41,15 @@ class CheckoutCustomerDetach(BaseMutation):
)
@classmethod
- def perform_mutation(cls, _root, info, checkout_id=None, token=None):
- # DEPRECATED
- validate_one_of_args_is_in_mutation(
- CheckoutErrorCode, "checkout_id", checkout_id, "token", token
+ def perform_mutation(cls, _root, info, checkout_id=None, token=None, id=None):
+ checkout = get_checkout(
+ cls,
+ info,
+ checkout_id=checkout_id,
+ token=token,
+ id=id,
+ error_class=CheckoutErrorCode,
)
-
- if token:
- checkout = get_checkout_by_token(token)
- # DEPRECATED
- else:
- checkout = cls.get_node_or_error(
- info, checkout_id or token, only_type=Checkout, field="checkout_id"
- )
-
requestor = get_user_or_app_from_context(info.context)
if not requestor.has_perm(AccountPermissions.IMPERSONATE_USER):
# Raise error if the current user doesn't own the checkout of the given ID.
diff --git a/saleor/graphql/checkout/mutations/checkout_delivery_method_update.py b/saleor/graphql/checkout/mutations/checkout_delivery_method_update.py
index d6d60945ef..2d949d4059 100644
--- a/saleor/graphql/checkout/mutations/checkout_delivery_method_update.py
+++ b/saleor/graphql/checkout/mutations/checkout_delivery_method_update.py
@@ -16,7 +16,12 @@ from ....shipping import interface as shipping_interface
from ....shipping import models as shipping_models
from ....shipping.utils import convert_to_shipping_method_data
from ....warehouse import models as warehouse_models
-from ...core.descriptions import ADDED_IN_31, PREVIEW_FEATURE
+from ...core.descriptions import (
+ ADDED_IN_31,
+ ADDED_IN_34,
+ DEPRECATED_IN_3X_INPUT,
+ PREVIEW_FEATURE,
+)
from ...core.mutations import BaseMutation
from ...core.scalars import UUID
from ...core.types import CheckoutError
@@ -24,14 +29,22 @@ from ...core.utils import from_global_id_or_error
from ...shipping.types import ShippingMethod
from ...warehouse.types import Warehouse
from ..types import Checkout
-from .utils import ERROR_DOES_NOT_SHIP, clean_delivery_method, get_checkout_by_token
+from .utils import ERROR_DOES_NOT_SHIP, clean_delivery_method, get_checkout
class CheckoutDeliveryMethodUpdate(BaseMutation):
checkout = graphene.Field(Checkout, description="An updated checkout.")
class Arguments:
- token = UUID(description="Checkout token.", required=False)
+ id = graphene.ID(
+ description="The checkout's ID." + ADDED_IN_34,
+ required=False,
+ )
+ token = UUID(
+ description=f"Checkout token.{DEPRECATED_IN_3X_INPUT} Use `id` instead.",
+ required=False,
+ )
+
delivery_method_id = graphene.ID(
description="Delivery Method ID (`Warehouse` ID or `ShippingMethod` ID).",
required=False,
@@ -224,11 +237,18 @@ class CheckoutDeliveryMethodUpdate(BaseMutation):
cls,
_,
info,
- token,
+ token=None,
+ id=None,
delivery_method_id=None,
):
-
- checkout = get_checkout_by_token(token)
+ checkout = get_checkout(
+ cls,
+ info,
+ checkout_id=None,
+ token=token,
+ id=id,
+ error_class=CheckoutErrorCode,
+ )
manager = info.context.plugins
lines, unavailable_variant_pks = fetch_checkout_lines(checkout)
diff --git a/saleor/graphql/checkout/mutations/checkout_email_update.py b/saleor/graphql/checkout/mutations/checkout_email_update.py
index 21ffeb5206..be33397553 100644
--- a/saleor/graphql/checkout/mutations/checkout_email_update.py
+++ b/saleor/graphql/checkout/mutations/checkout_email_update.py
@@ -2,26 +2,32 @@ import graphene
from django.core.exceptions import ValidationError
from ....checkout.error_codes import CheckoutErrorCode
-from ...core.descriptions import DEPRECATED_IN_3X_INPUT
+from ...core.descriptions import ADDED_IN_34, DEPRECATED_IN_3X_INPUT
from ...core.mutations import BaseMutation
from ...core.scalars import UUID
from ...core.types import CheckoutError
-from ...core.validators import validate_one_of_args_is_in_mutation
from ..types import Checkout
-from .utils import get_checkout_by_token
+from .utils import get_checkout
class CheckoutEmailUpdate(BaseMutation):
checkout = graphene.Field(Checkout, description="An updated checkout.")
class Arguments:
+ id = graphene.ID(
+ description="The checkout's ID." + ADDED_IN_34,
+ required=False,
+ )
+ token = UUID(
+ description=f"Checkout token.{DEPRECATED_IN_3X_INPUT} Use `id` instead.",
+ required=False,
+ )
checkout_id = graphene.ID(
+ required=False,
description=(
- f"The ID of the checkout. {DEPRECATED_IN_3X_INPUT} Use token instead."
+ f"The ID of the checkout. {DEPRECATED_IN_3X_INPUT} Use `id` instead."
),
- required=False,
)
- token = UUID(description="Checkout token.", required=False)
email = graphene.String(required=True, description="email.")
class Meta:
@@ -42,21 +48,19 @@ class CheckoutEmailUpdate(BaseMutation):
)
@classmethod
- def perform_mutation(cls, _root, info, email, checkout_id=None, token=None):
- # DEPRECATED
- validate_one_of_args_is_in_mutation(
- CheckoutErrorCode, "checkout_id", checkout_id, "token", token
- )
-
+ def perform_mutation(
+ cls, _root, info, email, checkout_id=None, token=None, id=None
+ ):
cls.clean_email(email)
- if token:
- checkout = get_checkout_by_token(token)
- # DEPRECATED
- else:
- checkout = cls.get_node_or_error(
- info, checkout_id or token, only_type=Checkout, field="checkout_id"
- )
+ checkout = get_checkout(
+ cls,
+ info,
+ checkout_id=checkout_id,
+ token=token,
+ id=id,
+ error_class=CheckoutErrorCode,
+ )
checkout.email = email
cls.clean_instance(info, checkout)
diff --git a/saleor/graphql/checkout/mutations/checkout_language_code_update.py b/saleor/graphql/checkout/mutations/checkout_language_code_update.py
index 91c16fe13b..729fc275c8 100644
--- a/saleor/graphql/checkout/mutations/checkout_language_code_update.py
+++ b/saleor/graphql/checkout/mutations/checkout_language_code_update.py
@@ -1,27 +1,33 @@
import graphene
from ....checkout.error_codes import CheckoutErrorCode
-from ...core.descriptions import DEPRECATED_IN_3X_INPUT
+from ...core.descriptions import ADDED_IN_34, DEPRECATED_IN_3X_INPUT
from ...core.enums import LanguageCodeEnum
from ...core.mutations import BaseMutation
from ...core.scalars import UUID
from ...core.types import CheckoutError
-from ...core.validators import validate_one_of_args_is_in_mutation
from ..types import Checkout
-from .utils import get_checkout_by_token
+from .utils import get_checkout
class CheckoutLanguageCodeUpdate(BaseMutation):
checkout = graphene.Field(Checkout, description="An updated checkout.")
class Arguments:
+ id = graphene.ID(
+ description="The checkout's ID." + ADDED_IN_34,
+ required=False,
+ )
+ token = UUID(
+ description=f"Checkout token.{DEPRECATED_IN_3X_INPUT} Use `id` instead.",
+ required=False,
+ )
checkout_id = graphene.ID(
required=False,
description=(
- f"The ID of the checkout. {DEPRECATED_IN_3X_INPUT} Use token instead."
+ f"The ID of the checkout. {DEPRECATED_IN_3X_INPUT} Use `id` instead."
),
)
- token = UUID(description="Checkout token.", required=False)
language_code = graphene.Argument(
LanguageCodeEnum, required=True, description="New language code."
)
@@ -32,20 +38,18 @@ class CheckoutLanguageCodeUpdate(BaseMutation):
error_type_field = "checkout_errors"
@classmethod
- def perform_mutation(cls, _root, info, language_code, checkout_id=None, token=None):
- # DEPRECATED
- validate_one_of_args_is_in_mutation(
- CheckoutErrorCode, "checkout_id", checkout_id, "token", token
+ def perform_mutation(
+ cls, _root, info, language_code, checkout_id=None, token=None, id=None
+ ):
+ checkout = get_checkout(
+ cls,
+ info,
+ checkout_id=checkout_id,
+ token=token,
+ id=id,
+ error_class=CheckoutErrorCode,
)
- if token:
- checkout = get_checkout_by_token(token)
- # DEPRECATED
- else:
- checkout = cls.get_node_or_error(
- info, checkout_id or token, only_type=Checkout, field="checkout_id"
- )
-
checkout.language_code = language_code
checkout.save(update_fields=["language_code", "last_change"])
info.context.plugins.checkout_updated(checkout)
diff --git a/saleor/graphql/checkout/mutations/checkout_line_delete.py b/saleor/graphql/checkout/mutations/checkout_line_delete.py
index 54589d1f98..23f431e86c 100644
--- a/saleor/graphql/checkout/mutations/checkout_line_delete.py
+++ b/saleor/graphql/checkout/mutations/checkout_line_delete.py
@@ -3,26 +3,32 @@ import graphene
from ....checkout.error_codes import CheckoutErrorCode
from ....checkout.fetch import fetch_checkout_info, fetch_checkout_lines
from ....checkout.utils import recalculate_checkout_discount
-from ...core.descriptions import DEPRECATED_IN_3X_INPUT
+from ...core.descriptions import ADDED_IN_34, DEPRECATED_IN_3X_INPUT
from ...core.mutations import BaseMutation
from ...core.scalars import UUID
from ...core.types import CheckoutError
-from ...core.validators import validate_one_of_args_is_in_mutation
from ..types import Checkout, CheckoutLine
-from .utils import get_checkout_by_token, update_checkout_shipping_method_if_invalid
+from .utils import get_checkout, update_checkout_shipping_method_if_invalid
class CheckoutLineDelete(BaseMutation):
checkout = graphene.Field(Checkout, description="An updated checkout.")
class Arguments:
+ id = graphene.ID(
+ description="The checkout's ID." + ADDED_IN_34,
+ required=False,
+ )
+ token = UUID(
+ description=f"Checkout token.{DEPRECATED_IN_3X_INPUT} Use `id` instead.",
+ required=False,
+ )
checkout_id = graphene.ID(
+ required=False,
description=(
- f"The ID of the checkout. {DEPRECATED_IN_3X_INPUT} Use token instead."
+ f"The ID of the checkout. {DEPRECATED_IN_3X_INPUT} Use `id` instead."
),
- required=False,
)
- token = UUID(description="Checkout token.", required=False)
line_id = graphene.ID(description="ID of the checkout line to delete.")
class Meta:
@@ -31,20 +37,18 @@ class CheckoutLineDelete(BaseMutation):
error_type_field = "checkout_errors"
@classmethod
- def perform_mutation(cls, _root, info, line_id, checkout_id=None, token=None):
- # DEPRECATED
- validate_one_of_args_is_in_mutation(
- CheckoutErrorCode, "checkout_id", checkout_id, "token", token
+ def perform_mutation(
+ cls, _root, info, line_id, checkout_id=None, token=None, id=None
+ ):
+ checkout = get_checkout(
+ cls,
+ info,
+ checkout_id=checkout_id,
+ token=token,
+ id=id,
+ error_class=CheckoutErrorCode,
)
- if token:
- checkout = get_checkout_by_token(token)
- # DEPRECATED
- else:
- checkout = cls.get_node_or_error(
- info, checkout_id or token, only_type=Checkout, field="checkout_id"
- )
-
line = cls.get_node_or_error(
info, line_id, only_type=CheckoutLine, field="line_id"
)
diff --git a/saleor/graphql/checkout/mutations/checkout_lines_add.py b/saleor/graphql/checkout/mutations/checkout_lines_add.py
index 9e19b10967..f7eb3fe9a9 100644
--- a/saleor/graphql/checkout/mutations/checkout_lines_add.py
+++ b/saleor/graphql/checkout/mutations/checkout_lines_add.py
@@ -8,21 +8,18 @@ from ....checkout.fetch import (
)
from ....checkout.utils import add_variants_to_checkout, recalculate_checkout_discount
from ....warehouse.reservations import get_reservation_length, is_reservation_enabled
-from ...core.descriptions import DEPRECATED_IN_3X_INPUT
+from ...core.descriptions import ADDED_IN_34, DEPRECATED_IN_3X_INPUT
from ...core.mutations import BaseMutation
from ...core.scalars import UUID
from ...core.types import CheckoutError, NonNullList
-from ...core.validators import (
- validate_one_of_args_is_in_mutation,
- validate_variants_available_in_channel,
-)
+from ...core.validators import validate_variants_available_in_channel
from ...product.types import ProductVariant
from ..types import Checkout
from .checkout_create import CheckoutLineInput
from .utils import (
check_lines_quantity,
check_permissions_for_custom_prices,
- get_checkout_by_token,
+ get_checkout,
group_quantity_and_custom_prices_by_variants,
update_checkout_shipping_method_if_invalid,
validate_variants_are_published,
@@ -34,13 +31,20 @@ class CheckoutLinesAdd(BaseMutation):
checkout = graphene.Field(Checkout, description="An updated checkout.")
class Arguments:
+ id = graphene.ID(
+ description="The checkout's ID." + ADDED_IN_34,
+ required=False,
+ )
+ token = UUID(
+ description=f"Checkout token.{DEPRECATED_IN_3X_INPUT} Use `id` instead.",
+ required=False,
+ )
checkout_id = graphene.ID(
+ required=False,
description=(
- f"The ID of the checkout. {DEPRECATED_IN_3X_INPUT} Use token instead."
+ f"The ID of the checkout. {DEPRECATED_IN_3X_INPUT} Use `id` instead."
),
- required=False,
)
- token = UUID(description="Checkout token.", required=False)
lines = NonNullList(
CheckoutLineInput,
required=True,
@@ -150,21 +154,18 @@ class CheckoutLinesAdd(BaseMutation):
@classmethod
def perform_mutation(
- cls, _root, info, lines, checkout_id=None, token=None, replace=False
+ cls, _root, info, lines, checkout_id=None, token=None, id=None, replace=False
):
- # DEPRECATED
- validate_one_of_args_is_in_mutation(
- CheckoutErrorCode, "checkout_id", checkout_id, "token", token
- )
check_permissions_for_custom_prices(info.context.app, lines)
- if token:
- checkout = get_checkout_by_token(token)
- # DEPRECATED
- else:
- checkout = cls.get_node_or_error(
- info, checkout_id or token, only_type=Checkout, field="checkout_id"
- )
+ checkout = get_checkout(
+ cls,
+ info,
+ checkout_id=checkout_id,
+ token=token,
+ id=id,
+ error_class=CheckoutErrorCode,
+ )
discounts = info.context.discounts
manager = info.context.plugins
diff --git a/saleor/graphql/checkout/mutations/checkout_lines_delete.py b/saleor/graphql/checkout/mutations/checkout_lines_delete.py
index a69366a93c..f156579929 100644
--- a/saleor/graphql/checkout/mutations/checkout_lines_delete.py
+++ b/saleor/graphql/checkout/mutations/checkout_lines_delete.py
@@ -1,21 +1,30 @@
import graphene
from django.core.exceptions import ValidationError
+from ....checkout.error_codes import CheckoutErrorCode
from ....checkout.fetch import fetch_checkout_info, fetch_checkout_lines
from ....checkout.utils import recalculate_checkout_discount
+from ...core.descriptions import ADDED_IN_34, DEPRECATED_IN_3X_INPUT
from ...core.mutations import BaseMutation
from ...core.scalars import UUID
from ...core.types import CheckoutError, NonNullList
from ...utils import resolve_global_ids_to_primary_keys
from ..types import Checkout
-from .utils import get_checkout_by_token, update_checkout_shipping_method_if_invalid
+from .utils import get_checkout, update_checkout_shipping_method_if_invalid
class CheckoutLinesDelete(BaseMutation):
checkout = graphene.Field(Checkout, description="An updated checkout.")
class Arguments:
- token = UUID(description="Checkout token.", required=True)
+ id = graphene.ID(
+ description="The checkout's ID." + ADDED_IN_34,
+ required=False,
+ )
+ token = UUID(
+ description=f"Checkout token.{DEPRECATED_IN_3X_INPUT} Use `id` instead.",
+ required=False,
+ )
lines_ids = NonNullList(
graphene.ID,
required=True,
@@ -49,8 +58,15 @@ class CheckoutLinesDelete(BaseMutation):
)
@classmethod
- def perform_mutation(cls, _root, info, lines_ids, token=None):
- checkout = get_checkout_by_token(token)
+ def perform_mutation(cls, _root, info, lines_ids, token=None, id=None):
+ checkout = get_checkout(
+ cls,
+ info,
+ checkout_id=None,
+ token=token,
+ id=id,
+ error_class=CheckoutErrorCode,
+ )
_, lines_to_delete = resolve_global_ids_to_primary_keys(
lines_ids, graphene_type="CheckoutLine", raise_error=True
diff --git a/saleor/graphql/checkout/mutations/checkout_lines_update.py b/saleor/graphql/checkout/mutations/checkout_lines_update.py
index fa341e1e70..f9d65da2d8 100644
--- a/saleor/graphql/checkout/mutations/checkout_lines_update.py
+++ b/saleor/graphql/checkout/mutations/checkout_lines_update.py
@@ -3,7 +3,7 @@ from django.forms import ValidationError
from ....checkout.error_codes import CheckoutErrorCode
from ....warehouse.reservations import is_reservation_enabled
-from ...core.descriptions import DEPRECATED_IN_3X_INPUT
+from ...core.descriptions import ADDED_IN_34, DEPRECATED_IN_3X_INPUT
from ...core.scalars import UUID
from ...core.types import CheckoutError, NonNullList
from ..types import Checkout
@@ -26,13 +26,20 @@ class CheckoutLinesUpdate(CheckoutLinesAdd):
checkout = graphene.Field(Checkout, description="An updated checkout.")
class Arguments:
+ id = graphene.ID(
+ description="The checkout's ID." + ADDED_IN_34,
+ required=False,
+ )
+ token = UUID(
+ description=f"Checkout token.{DEPRECATED_IN_3X_INPUT} Use `id` instead.",
+ required=False,
+ )
checkout_id = graphene.ID(
+ required=False,
description=(
- f"The ID of the checkout. {DEPRECATED_IN_3X_INPUT} Use token instead."
+ f"The ID of the checkout. {DEPRECATED_IN_3X_INPUT} Use `id` instead."
),
- required=False,
)
- token = UUID(description="Checkout token.", required=False)
lines = NonNullList(
CheckoutLineUpdateInput,
required=True,
@@ -119,7 +126,7 @@ class CheckoutLinesUpdate(CheckoutLinesAdd):
)
@classmethod
- def perform_mutation(cls, root, info, lines, checkout_id=None, token=None):
+ def perform_mutation(cls, root, info, lines, checkout_id=None, token=None, id=None):
return super().perform_mutation(
- root, info, lines, checkout_id, token, replace=True
+ root, info, lines, checkout_id, token, id, replace=True
)
diff --git a/saleor/graphql/checkout/mutations/checkout_remove_promo_code.py b/saleor/graphql/checkout/mutations/checkout_remove_promo_code.py
index 70a39a8458..68bfe5e75f 100644
--- a/saleor/graphql/checkout/mutations/checkout_remove_promo_code.py
+++ b/saleor/graphql/checkout/mutations/checkout_remove_promo_code.py
@@ -11,7 +11,7 @@ from ....checkout.utils import (
remove_promo_code_from_checkout,
remove_voucher_from_checkout,
)
-from ...core.descriptions import DEPRECATED_IN_3X_INPUT
+from ...core.descriptions import ADDED_IN_34, DEPRECATED_IN_3X_INPUT
from ...core.mutations import BaseMutation
from ...core.scalars import UUID
from ...core.types import CheckoutError
@@ -20,7 +20,7 @@ from ...core.validators import validate_one_of_args_is_in_mutation
from ...discount.types import Voucher
from ...giftcard.types import GiftCard
from ..types import Checkout
-from .utils import get_checkout_by_token
+from .utils import get_checkout
class CheckoutRemovePromoCode(BaseMutation):
@@ -29,13 +29,20 @@ class CheckoutRemovePromoCode(BaseMutation):
)
class Arguments:
+ id = graphene.ID(
+ description="The checkout's ID." + ADDED_IN_34,
+ required=False,
+ )
+ token = UUID(
+ description=f"Checkout token.{DEPRECATED_IN_3X_INPUT} Use `id` instead.",
+ required=False,
+ )
checkout_id = graphene.ID(
+ required=False,
description=(
- f"The ID of the checkout. {DEPRECATED_IN_3X_INPUT} Use token instead."
+ f"The ID of the checkout. {DEPRECATED_IN_3X_INPUT} Use `id` instead."
),
- required=False,
)
- token = UUID(description="Checkout token.", required=False)
promo_code = graphene.String(
description="Gift card code or voucher code.", required=False
)
@@ -56,26 +63,24 @@ class CheckoutRemovePromoCode(BaseMutation):
info,
checkout_id=None,
token=None,
+ id=None,
promo_code=None,
promo_code_id=None,
):
- # DEPRECATED
- validate_one_of_args_is_in_mutation(
- CheckoutErrorCode, "checkout_id", checkout_id, "token", token
- )
validate_one_of_args_is_in_mutation(
CheckoutErrorCode, "promo_code", promo_code, "promo_code_id", promo_code_id
)
object_type, promo_code_pk = cls.clean_promo_code_id(promo_code_id)
- if token:
- checkout = get_checkout_by_token(token)
- # DEPRECATED
- else:
- checkout = cls.get_node_or_error(
- info, checkout_id or token, only_type=Checkout, field="checkout_id"
- )
+ checkout = get_checkout(
+ cls,
+ info,
+ checkout_id=checkout_id,
+ token=token,
+ id=id,
+ error_class=CheckoutErrorCode,
+ )
manager = info.context.plugins
checkout_info = fetch_checkout_info(
diff --git a/saleor/graphql/checkout/mutations/checkout_shipping_address_update.py b/saleor/graphql/checkout/mutations/checkout_shipping_address_update.py
index 31f67033ea..2e0c168034 100644
--- a/saleor/graphql/checkout/mutations/checkout_shipping_address_update.py
+++ b/saleor/graphql/checkout/mutations/checkout_shipping_address_update.py
@@ -1,7 +1,7 @@
from typing import Iterable
import graphene
-from django.core.exceptions import ObjectDoesNotExist, ValidationError
+from django.core.exceptions import ValidationError
from ....checkout import AddressType, models
from ....checkout.error_codes import CheckoutErrorCode
@@ -20,16 +20,15 @@ from ....product import models as product_models
from ....warehouse.reservations import is_reservation_enabled
from ...account.i18n import I18nMixin
from ...account.types import AddressInput
-from ...core.descriptions import DEPRECATED_IN_3X_INPUT
+from ...core.descriptions import ADDED_IN_34, DEPRECATED_IN_3X_INPUT
from ...core.mutations import BaseMutation
from ...core.scalars import UUID
from ...core.types import CheckoutError
-from ...core.validators import validate_one_of_args_is_in_mutation
from ..types import Checkout
from .utils import (
ERROR_DOES_NOT_SHIP,
check_lines_quantity,
- get_checkout_by_token,
+ get_checkout,
update_checkout_shipping_method_if_invalid,
)
@@ -38,13 +37,20 @@ class CheckoutShippingAddressUpdate(BaseMutation, I18nMixin):
checkout = graphene.Field(Checkout, description="An updated checkout.")
class Arguments:
+ id = graphene.ID(
+ description="The checkout's ID." + ADDED_IN_34,
+ required=False,
+ )
+ token = UUID(
+ description=f"Checkout token.{DEPRECATED_IN_3X_INPUT} Use `id` instead.",
+ required=False,
+ )
checkout_id = graphene.ID(
required=False,
description=(
- f"The ID of the checkout. {DEPRECATED_IN_3X_INPUT} Use token instead."
+ f"The ID of the checkout. {DEPRECATED_IN_3X_INPUT} Use `id` instead."
),
)
- token = UUID(description="Checkout token.", required=False)
shipping_address = AddressInput(
required=True,
description="The mailing address to where the checkout will be shipped.",
@@ -85,39 +91,20 @@ class CheckoutShippingAddressUpdate(BaseMutation, I18nMixin):
@classmethod
def perform_mutation(
- cls, _root, info, shipping_address, checkout_id=None, token=None
+ cls, _root, info, shipping_address, checkout_id=None, token=None, id=None
):
- # DEPRECATED
- validate_one_of_args_is_in_mutation(
- CheckoutErrorCode, "checkout_id", checkout_id, "token", token
+ checkout = get_checkout(
+ cls,
+ info,
+ checkout_id=checkout_id,
+ token=token,
+ id=id,
+ error_class=CheckoutErrorCode,
+ qs=models.Checkout.objects.prefetch_related(
+ "lines__variant__product__product_type"
+ ),
)
- if token:
- checkout = get_checkout_by_token(
- token,
- qs=models.Checkout.objects.prefetch_related(
- "lines__variant__product__product_type"
- ),
- )
- # DEPRECATED
- if checkout_id:
- pk = cls.get_global_id_or_error(
- checkout_id, only_type=Checkout, field="checkout_id"
- )
- try:
- checkout = models.Checkout.objects.prefetch_related(
- "lines__variant__product__product_type"
- ).get(pk=pk)
- except ObjectDoesNotExist:
- raise ValidationError(
- {
- "checkout_id": ValidationError(
- f"Couldn't resolve to a node: {checkout_id}",
- code=CheckoutErrorCode.NOT_FOUND,
- )
- }
- )
-
lines, _ = fetch_checkout_lines(checkout)
if not is_shipping_required(lines):
raise ValidationError(
diff --git a/saleor/graphql/checkout/mutations/checkout_shipping_method_update.py b/saleor/graphql/checkout/mutations/checkout_shipping_method_update.py
index b6f64ceb0b..a8b54b3793 100644
--- a/saleor/graphql/checkout/mutations/checkout_shipping_method_update.py
+++ b/saleor/graphql/checkout/mutations/checkout_shipping_method_update.py
@@ -15,28 +15,34 @@ from ....plugins.webhook.utils import APP_ID_PREFIX
from ....shipping import interface as shipping_interface
from ....shipping import models as shipping_models
from ....shipping.utils import convert_to_shipping_method_data
-from ...core.descriptions import DEPRECATED_IN_3X_INPUT
+from ...core.descriptions import ADDED_IN_34, DEPRECATED_IN_3X_INPUT
from ...core.mutations import BaseMutation
from ...core.scalars import UUID
from ...core.types import CheckoutError
from ...core.utils import from_global_id_or_error
-from ...core.validators import validate_one_of_args_is_in_mutation
from ...shipping.types import ShippingMethod
from ..types import Checkout
-from .utils import ERROR_DOES_NOT_SHIP, clean_delivery_method, get_checkout_by_token
+from .utils import ERROR_DOES_NOT_SHIP, clean_delivery_method, get_checkout
class CheckoutShippingMethodUpdate(BaseMutation):
checkout = graphene.Field(Checkout, description="An updated checkout.")
class Arguments:
+ id = graphene.ID(
+ description="The checkout's ID." + ADDED_IN_34,
+ required=False,
+ )
+ token = UUID(
+ description=f"Checkout token.{DEPRECATED_IN_3X_INPUT} Use `id` instead.",
+ required=False,
+ )
checkout_id = graphene.ID(
+ required=False,
description=(
- f"The ID of the checkout. {DEPRECATED_IN_3X_INPUT} Use token instead."
+ f"The ID of the checkout. {DEPRECATED_IN_3X_INPUT} Use `id` instead."
),
- required=False,
)
- token = UUID(description="Checkout token.", required=False)
shipping_method_id = graphene.ID(required=True, description="Shipping method.")
class Meta:
@@ -67,21 +73,17 @@ class CheckoutShippingMethodUpdate(BaseMutation):
@classmethod
def perform_mutation(
- cls, _root, info, shipping_method_id, checkout_id=None, token=None
+ cls, _root, info, shipping_method_id, checkout_id=None, token=None, id=None
):
- # DEPRECATED
- validate_one_of_args_is_in_mutation(
- CheckoutErrorCode, "checkout_id", checkout_id, "token", token
+ checkout = get_checkout(
+ cls,
+ info,
+ checkout_id=checkout_id,
+ token=token,
+ id=id,
+ error_class=CheckoutErrorCode,
)
- if token:
- checkout = get_checkout_by_token(token)
- # DEPRECATED
- else:
- checkout = cls.get_node_or_error(
- info, checkout_id or token, only_type=Checkout, field="checkout_id"
- )
-
manager = info.context.plugins
lines, unavailable_variant_pks = fetch_checkout_lines(checkout)
diff --git a/saleor/graphql/checkout/mutations/utils.py b/saleor/graphql/checkout/mutations/utils.py
index fdcd5ec512..12a56b4c82 100644
--- a/saleor/graphql/checkout/mutations/utils.py
+++ b/saleor/graphql/checkout/mutations/utils.py
@@ -3,12 +3,13 @@ import uuid
from collections import defaultdict
from dataclasses import dataclass
from decimal import Decimal
-from typing import Any, Dict, Iterable, List, Optional, Union, cast
+from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Type, Union, cast
import graphene
import pytz
from django.core.exceptions import ObjectDoesNotExist, ValidationError
-from django.db.models import Q
+from django.db.models import Q, QuerySet
+from graphql import ResolveInfo
from ....checkout import models
from ....checkout.error_codes import CheckoutErrorCode
@@ -25,6 +26,12 @@ from ....product.models import ProductChannelListing
from ....shipping import interface as shipping_interface
from ....warehouse import models as warehouse_models
from ....warehouse.availability import check_stock_and_preorder_quantity_bulk
+from ...core.validators import validate_one_of_args_is_in_mutation
+from ..types import Checkout
+
+if TYPE_CHECKING:
+ from ...core.mutations import BaseMutation
+
ERROR_DOES_NOT_SHIP = "This checkout doesn't need shipping"
@@ -225,6 +232,48 @@ def get_checkout_by_token(token: uuid.UUID, qs=None):
return checkout
+def get_checkout(
+ mutation_class: Type["BaseMutation"],
+ info: ResolveInfo,
+ checkout_id: str = None,
+ token: uuid.UUID = None,
+ id: str = None,
+ error_class=CheckoutErrorCode,
+ qs: QuerySet = None,
+):
+ """Return checkout by using the current id field or the deprecated one.
+
+ It is helper logic to return a checkout for mutations that takes into account the
+ current `id` field and the deprecated one (`checkout_id`, `token`). If checkout is
+ not found, it will raise an exception.
+ """
+
+ validate_one_of_args_is_in_mutation(
+ error_class, "checkout_id", checkout_id, "token", token, "id", id
+ )
+ if qs is None:
+ qs = models.Checkout.objects.select_related(
+ "channel",
+ "shipping_method",
+ "collection_point",
+ "billing_address",
+ "shipping_address",
+ )
+
+ if id:
+ checkout = mutation_class.get_node_or_error(
+ info, id, only_type=Checkout, field="id", qs=qs
+ )
+ else: # DEPRECATED
+ if token:
+ checkout = get_checkout_by_token(token, qs=qs)
+ else:
+ checkout = mutation_class.get_node_or_error(
+ info, checkout_id, only_type=Checkout, field="checkout_id", qs=qs
+ )
+ return checkout
+
+
def group_quantity_and_custom_prices_by_variants(
lines: List[Dict[str, Any]]
) -> List[CheckoutLineData]:
diff --git a/saleor/graphql/checkout/resolvers.py b/saleor/graphql/checkout/resolvers.py
index ae33c6878a..5437d8899a 100644
--- a/saleor/graphql/checkout/resolvers.py
+++ b/saleor/graphql/checkout/resolvers.py
@@ -1,6 +1,8 @@
from ...checkout import models
from ...core.permissions import AccountPermissions, CheckoutPermissions
from ...core.tracing import traced_resolver
+from ..core.utils import from_global_id_or_error
+from ..core.validators import validate_one_of_args_is_in_query
from ..utils import get_user_or_app_from_context
@@ -17,7 +19,11 @@ def resolve_checkouts(channel_slug):
@traced_resolver
-def resolve_checkout(info, token):
+def resolve_checkout(info, token, id):
+ validate_one_of_args_is_in_query("id", id, "token", token)
+
+ if id:
+ _, token = from_global_id_or_error(id, only_type="Checkout")
checkout = models.Checkout.objects.filter(token=token).first()
if checkout is None:
diff --git a/saleor/graphql/checkout/schema.py b/saleor/graphql/checkout/schema.py
index 97ee6399e7..6723069a76 100644
--- a/saleor/graphql/checkout/schema.py
+++ b/saleor/graphql/checkout/schema.py
@@ -2,7 +2,12 @@ import graphene
from ...core.permissions import CheckoutPermissions
from ..core.connection import create_connection_slice, filter_connection_queryset
-from ..core.descriptions import ADDED_IN_31, DEPRECATED_IN_3X_FIELD
+from ..core.descriptions import (
+ ADDED_IN_31,
+ ADDED_IN_34,
+ DEPRECATED_IN_3X_FIELD,
+ DEPRECATED_IN_3X_INPUT,
+)
from ..core.fields import ConnectionField, FilterConnectionField
from ..core.scalars import UUID
from ..payment.mutations import CheckoutPaymentCreate
@@ -39,7 +44,15 @@ class CheckoutQueries(graphene.ObjectType):
checkout = graphene.Field(
Checkout,
description="Look up a checkout by token and slug of channel.",
- token=graphene.Argument(UUID, description="The checkout's token."),
+ id=graphene.Argument(
+ graphene.ID, description="The checkout's ID." + ADDED_IN_34
+ ),
+ token=graphene.Argument(
+ UUID,
+ description=(
+ f"The checkout's token.{DEPRECATED_IN_3X_INPUT} Use `id` instead."
+ ),
+ ),
)
# FIXME we could optimize the below field
checkouts = FilterConnectionField(
@@ -65,8 +78,8 @@ class CheckoutQueries(graphene.ObjectType):
)
@staticmethod
- def resolve_checkout(_root, info, *, token):
- return resolve_checkout(info, token)
+ def resolve_checkout(_root, info, *, token=None, id=None):
+ return resolve_checkout(info, token, id)
@staticmethod
def resolve_checkouts(_root, info, *, channel=None, **kwargs):
diff --git a/saleor/graphql/checkout/tests/benchmark/test_checkout_mutations.py b/saleor/graphql/checkout/tests/benchmark/test_checkout_mutations.py
index 174b7245c3..668b5aaead 100644
--- a/saleor/graphql/checkout/tests/benchmark/test_checkout_mutations.py
+++ b/saleor/graphql/checkout/tests/benchmark/test_checkout_mutations.py
@@ -12,6 +12,7 @@ from .....checkout.utils import add_variants_to_checkout, set_external_shipping_
from .....plugins.manager import get_plugins_manager
from .....product.models import ProductVariant, ProductVariantChannelListing
from .....warehouse.models import Stock
+from ....core.utils import to_global_id_or_none
from ....tests.utils import get_graphql_content
from ...mutations.utils import CheckoutLineData
@@ -484,10 +485,10 @@ def test_add_shipping_to_checkout(
FRAGMENT_CHECKOUT
+ """
mutation updateCheckoutShippingOptions(
- $token: UUID, $shippingMethodId: ID!
+ $id: ID, $shippingMethodId: ID!
) {
checkoutShippingMethodUpdate(
- token: $token, shippingMethodId: $shippingMethodId
+ id: $id, shippingMethodId: $shippingMethodId
) {
errors {
field
@@ -501,7 +502,7 @@ def test_add_shipping_to_checkout(
"""
)
variables = {
- "token": checkout_with_shipping_address.token,
+ "id": to_global_id_or_none(checkout_with_shipping_address),
"shippingMethodId": Node.to_global_id("ShippingMethod", shipping_method.pk),
}
response = get_graphql_content(api_client.post_graphql(query, variables))
@@ -520,10 +521,10 @@ def test_add_delivery_to_checkout(
FRAGMENT_CHECKOUT
+ """
mutation updateCheckoutDeliveryOptions(
- $token: UUID, $deliveryMethodId: ID
+ $id: ID, $deliveryMethodId: ID
) {
checkoutDeliveryMethodUpdate(
- token: $token, deliveryMethodId: $deliveryMethodId
+ id: $id, deliveryMethodId: $deliveryMethodId
) {
errors {
field
@@ -537,7 +538,7 @@ def test_add_delivery_to_checkout(
"""
)
variables = {
- "token": checkout_with_shipping_address_for_cc.token,
+ "id": to_global_id_or_none(checkout_with_shipping_address_for_cc),
"deliveryMethodId": Node.to_global_id("Warehouse", warehouses_for_cc[1].pk),
}
response = get_graphql_content(api_client.post_graphql(query, variables))
@@ -553,10 +554,10 @@ def test_add_billing_address_to_checkout(
FRAGMENT_CHECKOUT
+ """
mutation UpdateCheckoutBillingAddress(
- $token: UUID, $billingAddress: AddressInput!
+ $id: ID, $billingAddress: AddressInput!
) {
checkoutBillingAddressUpdate(
- token: $token, billingAddress: $billingAddress
+ id: $id, billingAddress: $billingAddress
) {
errors {
field
@@ -570,7 +571,7 @@ def test_add_billing_address_to_checkout(
"""
)
variables = {
- "token": checkout_with_shipping_method.token,
+ "id": to_global_id_or_none(checkout_with_shipping_method),
"billingAddress": graphql_address_data,
}
response = get_graphql_content(api_client.post_graphql(query, variables))
@@ -580,8 +581,8 @@ def test_add_billing_address_to_checkout(
MUTATION_CHECKOUT_LINES_UPDATE = (
FRAGMENT_CHECKOUT_LINE
+ """
- mutation updateCheckoutLine($token: UUID, $lines: [CheckoutLineUpdateInput!]!){
- checkoutLinesUpdate(token: $token, lines: $lines) {
+ mutation updateCheckoutLine($id: ID, $lines: [CheckoutLineUpdateInput!]!){
+ checkoutLinesUpdate(id: $id, lines: $lines) {
checkout {
id
lines {
@@ -617,7 +618,7 @@ def test_update_checkout_lines(
count_queries,
):
variables = {
- "token": checkout_with_items.token,
+ "id": to_global_id_or_none(checkout_with_items),
"lines": [
{
"quantity": 1,
@@ -718,7 +719,7 @@ def test_update_checkout_lines_with_reservations(
with django_assert_num_queries(56):
variant_id = graphene.Node.to_global_id("ProductVariant", variants[0].pk)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"quantity": 3, "variantId": variant_id}],
}
response = user_api_client.post_graphql(
@@ -731,7 +732,7 @@ def test_update_checkout_lines_with_reservations(
# Updating multiple lines in checkout has same query count as updating one
with django_assert_num_queries(56):
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [],
}
@@ -750,8 +751,8 @@ def test_update_checkout_lines_with_reservations(
MUTATION_CHECKOUT_LINES_ADD = (
FRAGMENT_CHECKOUT_LINE
+ """
- mutation addCheckoutLines($checkoutId: ID!, $lines: [CheckoutLineInput!]!){
- checkoutLinesAdd(checkoutId: $checkoutId, lines: $lines) {
+ mutation addCheckoutLines($id: ID, $lines: [CheckoutLineInput!]!){
+ checkoutLinesAdd(id: $id, lines: $lines) {
checkout {
id
lines {
@@ -796,7 +797,7 @@ def test_add_checkout_lines(
mock_send_request.return_value = mock_json_response
variables = {
- "checkoutId": Node.to_global_id("Checkout", checkout_with_single_item.pk),
+ "id": Node.to_global_id("Checkout", checkout_with_single_item.pk),
"lines": [
{
"quantity": 1,
@@ -879,7 +880,7 @@ def test_add_checkout_lines_with_external_shipping(
checkout_with_single_item.save()
variables = {
- "checkoutId": Node.to_global_id("Checkout", checkout_with_single_item.pk),
+ "id": Node.to_global_id("Checkout", checkout_with_single_item.pk),
"lines": [
{
"quantity": 1,
@@ -970,9 +971,9 @@ def test_add_checkout_lines_with_reservations(
new_lines.append({"quantity": 2, "variantId": variant_id})
# Adding multiple lines to checkout has same query count as adding one
- with django_assert_num_queries(56):
+ with django_assert_num_queries(55):
variables = {
- "checkoutId": Node.to_global_id("Checkout", checkout.pk),
+ "id": Node.to_global_id("Checkout", checkout.pk),
"lines": [new_lines[0]],
"channelSlug": checkout.channel.slug,
}
@@ -983,9 +984,9 @@ def test_add_checkout_lines_with_reservations(
checkout.lines.exclude(id=line.id).delete()
- with django_assert_num_queries(56):
+ with django_assert_num_queries(55):
variables = {
- "checkoutId": Node.to_global_id("Checkout", checkout.pk),
+ "id": Node.to_global_id("Checkout", checkout.pk),
"lines": new_lines,
"channelSlug": checkout.channel.slug,
}
@@ -1004,10 +1005,10 @@ def test_checkout_shipping_address_update(
FRAGMENT_CHECKOUT
+ """
mutation UpdateCheckoutShippingAddress(
- $token: UUID, $shippingAddress: AddressInput!
+ $id: ID, $shippingAddress: AddressInput!
) {
checkoutShippingAddressUpdate(
- token: $token, shippingAddress: $shippingAddress
+ id: $id, shippingAddress: $shippingAddress
) {
errors {
field
@@ -1021,7 +1022,7 @@ def test_checkout_shipping_address_update(
"""
)
variables = {
- "token": checkout_with_variants.pk,
+ "id": to_global_id_or_none(checkout_with_variants),
"shippingAddress": graphql_address_data,
}
response = get_graphql_content(api_client.post_graphql(query, variables))
@@ -1035,9 +1036,9 @@ def test_checkout_email_update(api_client, checkout_with_variants, count_queries
FRAGMENT_CHECKOUT
+ """
mutation UpdateCheckoutEmail(
- $token: UUID, $email: String!
+ $id: ID, $email: String!
) {
- checkoutEmailUpdate(token: $token, email: $email) {
+ checkoutEmailUpdate(id: $id, email: $email) {
checkout {
...Checkout
}
@@ -1050,7 +1051,7 @@ def test_checkout_email_update(api_client, checkout_with_variants, count_queries
"""
)
variables = {
- "token": checkout_with_variants.token,
+ "id": to_global_id_or_none(checkout_with_variants),
"email": "[email protected]",
}
response = get_graphql_content(api_client.post_graphql(query, variables))
@@ -1065,8 +1066,8 @@ def test_checkout_voucher_code(
query = (
FRAGMENT_CHECKOUT
+ """
- mutation AddCheckoutPromoCode($token: UUID, $promoCode: String!) {
- checkoutAddPromoCode(token: $token, promoCode: $promoCode) {
+ mutation AddCheckoutPromoCode($id: ID, $promoCode: String!) {
+ checkoutAddPromoCode(id: $id, promoCode: $promoCode) {
checkout {
...Checkout
}
@@ -1084,7 +1085,7 @@ def test_checkout_voucher_code(
"""
)
variables = {
- "token": checkout_with_billing_address.token,
+ "id": to_global_id_or_none(checkout_with_billing_address),
"promoCode": voucher.code,
}
response = get_graphql_content(api_client.post_graphql(query, variables))
@@ -1097,8 +1098,8 @@ def test_checkout_payment_charge(
api_client, checkout_with_billing_address, count_queries
):
query = """
- mutation createPayment($input: PaymentInput!, $token: UUID) {
- checkoutPaymentCreate(input: $input, token: $token) {
+ mutation createPayment($input: PaymentInput!, $id: ID) {
+ checkoutPaymentCreate(input: $input, id: $id) {
errors {
field
message
@@ -1121,7 +1122,7 @@ def test_checkout_payment_charge(
)
variables = {
- "token": checkout_with_billing_address.token,
+ "id": to_global_id_or_none(checkout_with_billing_address),
"input": {
"amount": total.gross.amount,
"gateway": "mirumee.payments.dummy",
@@ -1269,8 +1270,8 @@ FRAGMENT_ORDER_DETAIL_FOR_CC = (
)
COMPLETE_CHECKOUT_MUTATION_PART = """
- mutation completeCheckout($token: UUID) {
- checkoutComplete(token: $token) {
+ mutation completeCheckout($id: ID) {
+ checkoutComplete(id: $id) {
errors {
code
field
@@ -1300,7 +1301,7 @@ def test_complete_checkout(api_client, checkout_with_charged_payment, count_quer
query = COMPLETE_CHECKOUT_MUTATION
variables = {
- "token": checkout_with_charged_payment.token,
+ "id": to_global_id_or_none(checkout_with_charged_payment),
}
response = get_graphql_content(api_client.post_graphql(query, variables))
@@ -1319,7 +1320,7 @@ def test_complete_checkout_with_out_of_stock_webhook(
query = COMPLETE_CHECKOUT_MUTATION
Stock.objects.update(quantity=10)
variables = {
- "token": checkout_with_charged_payment.token,
+ "id": to_global_id_or_none(checkout_with_charged_payment),
}
response = get_graphql_content(api_client.post_graphql(query, variables))
@@ -1340,7 +1341,7 @@ def test_complete_checkout_with_single_line(
)
variables = {
- "token": checkout_with_charged_payment.token,
+ "id": to_global_id_or_none(checkout_with_charged_payment),
}
response = get_graphql_content(api_client.post_graphql(query, variables))
@@ -1355,7 +1356,7 @@ def test_complete_checkout_with_digital_line(
query = COMPLETE_CHECKOUT_MUTATION
variables = {
- "token": checkout_with_digital_line_with_charged_payment.token,
+ "id": to_global_id_or_none(checkout_with_digital_line_with_charged_payment),
}
response = get_graphql_content(api_client.post_graphql(query, variables))
@@ -1372,7 +1373,7 @@ def test_customer_complete_checkout(
checkout.user = customer_user
checkout.save()
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
}
response = get_graphql_content(api_client.post_graphql(query, variables))
@@ -1389,7 +1390,7 @@ def test_customer_complete_checkout_for_cc(
checkout.user = customer_user
checkout.save()
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
}
response = get_graphql_content(api_client.post_graphql(query, variables))
@@ -1404,7 +1405,7 @@ def test_complete_checkout_preorder(
query = COMPLETE_CHECKOUT_MUTATION
variables = {
- "token": checkout_preorder_with_charged_payment.token,
+ "id": to_global_id_or_none(checkout_preorder_with_charged_payment),
}
response = get_graphql_content(api_client.post_graphql(query, variables))
diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout.py b/saleor/graphql/checkout/tests/deprecated/test_checkout.py
new file mode 100644
index 0000000000..67d6ea356d
--- /dev/null
+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout.py
@@ -0,0 +1,25 @@
+from saleor.graphql.core.utils import to_global_id_or_none
+from saleor.graphql.tests.utils import get_graphql_content
+
+CHECKOUT_QUERY = """
+query getCheckout($token: UUID) {
+ checkout(token: $token) {
+ id
+ }
+}
+"""
+
+
+def test_checkout_by_token(checkout, user_api_client, customer_user):
+ # given
+ checkout.user = customer_user
+ checkout.save()
+ variables = {"token": checkout.token}
+
+ # when
+ response = user_api_client.post_graphql(CHECKOUT_QUERY, variables)
+
+ # then
+ content = get_graphql_content(response)
+ data = content["data"]["checkout"]
+ assert data["id"] == to_global_id_or_none(checkout)
diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_billing_address_update_deprecated.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_billing_address_update.py
similarity index 64%
rename from saleor/graphql/checkout/tests/deprecated/test_checkout_billing_address_update_deprecated.py
rename to saleor/graphql/checkout/tests/deprecated/test_checkout_billing_address_update.py
index e8aa26809f..67698181bc 100644
--- a/saleor/graphql/checkout/tests/deprecated/test_checkout_billing_address_update_deprecated.py
+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout_billing_address_update.py
@@ -5,10 +5,11 @@ from ....tests.utils import get_graphql_content
MUTATION_CHECKOUT_BILLING_ADDRESS_UPDATE = """
mutation checkoutBillingAddressUpdate(
- $checkoutId: ID, $token: UUID, $billingAddress: AddressInput!) {
+ $checkoutId: ID, $token: UUID, $id: ID, $billingAddress: AddressInput!) {
checkoutBillingAddressUpdate(
checkoutId: $checkoutId,
token: $token,
+ id: $id
billingAddress: $billingAddress
){
checkout {
@@ -129,3 +130,72 @@ def test_checkout_billing_address_update_both_token_and_id_given(
assert len(data["errors"]) == 1
assert not data["checkout"]
assert data["errors"][0]["code"] == CheckoutErrorCode.GRAPHQL_ERROR.name
+
+
+def test_checkout_billing_address_update_by_token_without_required_fields(
+ user_api_client, checkout_with_item, graphql_address_data
+):
+ checkout = checkout_with_item
+ assert checkout.shipping_address is None
+
+ query = MUTATION_CHECKOUT_BILLING_ADDRESS_UPDATE
+
+ graphql_address_data["streetAddress1"] = ""
+ graphql_address_data["streetAddress2"] = ""
+ graphql_address_data["postalCode"] = ""
+
+ billing_address = graphql_address_data
+
+ variables = {"token": checkout_with_item.token, "billingAddress": billing_address}
+
+ response = user_api_client.post_graphql(query, variables)
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutBillingAddressUpdate"]
+ assert data["errors"]
+ assert data["errors"] == [
+ {
+ "code": "REQUIRED",
+ "field": "postalCode",
+ "message": "This field is required.",
+ },
+ {
+ "code": "REQUIRED",
+ "field": "streetAddress1",
+ "message": "This field is required.",
+ },
+ ]
+
+
+def test_checkout_billing_address_update_by_token_without_street_address_2(
+ user_api_client, checkout_with_item, graphql_address_data
+):
+ checkout = checkout_with_item
+ assert checkout.shipping_address is None
+
+ query = MUTATION_CHECKOUT_BILLING_ADDRESS_UPDATE
+
+ graphql_address_data["streetAddress2"] = ""
+
+ billing_address = graphql_address_data
+
+ variables = {"token": checkout_with_item.token, "billingAddress": billing_address}
+
+ response = user_api_client.post_graphql(query, variables)
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutBillingAddressUpdate"]
+ assert not data["errors"]
+ checkout.refresh_from_db()
+ assert checkout.billing_address is not None
+ assert checkout.billing_address.first_name == billing_address["firstName"]
+ assert checkout.billing_address.last_name == billing_address["lastName"]
+ assert (
+ checkout.billing_address.street_address_1 == billing_address["streetAddress1"]
+ )
+ assert (
+ checkout.billing_address.street_address_2
+ == billing_address["streetAddress2"]
+ == ""
+ )
+ assert checkout.billing_address.postal_code == billing_address["postalCode"]
+ assert checkout.billing_address.country == billing_address["country"]
+ assert checkout.billing_address.city == billing_address["city"].upper()
diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_complete.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_complete.py
index 3a013fb40e..5b79eb08d4 100644
--- a/saleor/graphql/checkout/tests/deprecated/test_checkout_complete.py
+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout_complete.py
@@ -189,3 +189,120 @@ def test_checkout_complete_order_already_exists_both_token_and_id_given(
assert len(data["errors"]) == 1
assert not data["order"]
assert data["errors"][0]["code"] == CheckoutErrorCode.GRAPHQL_ERROR.name
+
+
+def test_checkout_complete_order_already_exists_for_token_as_input(
+ user_api_client,
+ order_with_lines,
+ checkout_with_gift_card,
+):
+ # given
+ checkout = checkout_with_gift_card
+ orders_count = Order.objects.count()
+ order_with_lines.checkout_token = checkout.pk
+ order_with_lines.save()
+
+ variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
+ checkout.delete()
+
+ # when
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
+
+ # then
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutComplete"]
+ assert not data["errors"]
+
+ order_data = data["order"]
+ assert Order.objects.count() == orders_count
+ assert str(order_with_lines.id) == order_data["token"]
+ assert order_data["origin"] == order_with_lines.origin.upper()
+ assert not order_data["original"]
+
+
+@patch("saleor.plugins.manager.PluginsManager.order_confirmed")
+def test_checkout_complete_for_token_as_input(
+ order_confirmed_mock,
+ site_settings,
+ user_api_client,
+ checkout_with_gift_card,
+ gift_card,
+ payment_dummy,
+ address,
+ shipping_method,
+):
+ # given
+ assert not gift_card.last_used_on
+
+ checkout = checkout_with_gift_card
+ checkout.shipping_address = address
+ checkout.shipping_method = shipping_method
+ checkout.billing_address = address
+ checkout.store_value_in_metadata(items={"accepted": "true"})
+ checkout.store_value_in_private_metadata(items={"accepted": "false"})
+ checkout.save()
+
+ checkout_line = checkout.lines.first()
+ checkout_line_quantity = checkout_line.quantity
+ checkout_line_variant = checkout_line.variant
+
+ manager = get_plugins_manager()
+ lines, _ = fetch_checkout_lines(checkout)
+ checkout_info = fetch_checkout_info(checkout, lines, [], manager)
+ total = calculations.calculate_checkout_total_with_gift_cards(
+ manager, checkout_info, lines, address
+ )
+ site_settings.automatically_confirm_all_new_orders = True
+ site_settings.save()
+ payment = payment_dummy
+ payment.is_active = True
+ payment.order = None
+ payment.total = total.gross.amount
+ payment.currency = total.gross.currency
+ payment.checkout = checkout
+ payment.save()
+ assert not payment.transactions.exists()
+
+ orders_count = Order.objects.count()
+ redirect_url = "https://www.example.com"
+ variables = {"token": checkout.token, "redirectUrl": redirect_url}
+
+ # when
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
+
+ # then
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutComplete"]
+ assert not data["errors"]
+
+ order_token = data["order"]["token"]
+ assert Order.objects.count() == orders_count + 1
+ order = Order.objects.first()
+ assert order.status == OrderStatus.UNFULFILLED
+ assert order.origin == OrderOrigin.CHECKOUT
+ assert not order.original
+ assert str(order.id) == order_token
+ assert order.redirect_url == redirect_url
+ assert order.total.gross == total.gross
+ assert order.metadata == checkout.metadata
+ assert order.private_metadata == checkout.private_metadata
+
+ order_line = order.lines.first()
+ assert checkout_line_quantity == order_line.quantity
+ assert checkout_line_variant == order_line.variant
+ assert order.shipping_address == address
+ assert order.shipping_method == checkout.shipping_method
+ assert order.payments.exists()
+ order_payment = order.payments.first()
+ assert order_payment == payment
+ assert payment.transactions.count() == 1
+
+ gift_card.refresh_from_db()
+ assert gift_card.current_balance == zero_money(gift_card.currency)
+ assert gift_card.last_used_on
+
+ assert not Checkout.objects.filter(
+ pk=checkout.pk
+ ).exists(), "Checkout should have been deleted"
+ order_confirmed_mock.assert_called_once_with(order)
diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_customer_attach.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_customer_attach.py
index 54814b0d81..771f618037 100644
--- a/saleor/graphql/checkout/tests/deprecated/test_checkout_customer_attach.py
+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout_customer_attach.py
@@ -46,6 +46,32 @@ def test_checkout_customer_attach_by_id(
assert checkout.email == customer_user.email
+def test_checkout_customer_attach_by_token(
+ api_client, user_api_client, checkout_with_item, customer_user
+):
+ checkout = checkout_with_item
+ checkout.email = "[email protected]"
+ checkout.save()
+ assert checkout.user is None
+
+ query = CHECKOUT_CUSTOMER_ATTACH_MUTATION
+ customer_id = graphene.Node.to_global_id("User", customer_user.pk)
+ variables = {"token": checkout.token, "customerId": customer_id}
+
+ # Mutation should fail for unauthenticated customers
+ response = api_client.post_graphql(query, variables)
+ assert_no_permission(response)
+
+ # Mutation should succeed for authenticated customer
+ response = user_api_client.post_graphql(query, variables)
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutCustomerAttach"]
+ assert not data["errors"]
+ checkout.refresh_from_db()
+ assert checkout.user == customer_user
+ assert checkout.email == customer_user.email
+
+
def test_checkout_customer_attach_neither_token_and_id_given(
user_api_client, checkout_with_item, customer_user
):
diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_email_update.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_email_update.py
index 7bcf437a4d..4245300246 100644
--- a/saleor/graphql/checkout/tests/deprecated/test_checkout_email_update.py
+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout_email_update.py
@@ -41,6 +41,22 @@ def test_checkout_email_update_by_id(user_api_client, checkout_with_item):
assert checkout.email == email
+def test_checkout_email_update_by_token(user_api_client, checkout_with_item):
+ checkout = checkout_with_item
+ checkout.email = None
+ checkout.save(update_fields=["email"])
+
+ email = "[email protected]"
+ variables = {"token": checkout.token, "email": email}
+
+ response = user_api_client.post_graphql(CHECKOUT_EMAIL_UPDATE_MUTATION, variables)
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutEmailUpdate"]
+ assert not data["errors"]
+ checkout.refresh_from_db()
+ assert checkout.email == email
+
+
def test_checkout_email_update_neither_token_and_id_given(
user_api_client, checkout_with_item
):
diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_language_code_update.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_language_code_update.py
index 8d0d743624..91ba770106 100644
--- a/saleor/graphql/checkout/tests/deprecated/test_checkout_language_code_update.py
+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout_language_code_update.py
@@ -46,6 +46,28 @@ def test_checkout_update_language_code_by_id(
assert checkout.language_code == language_code.lower()
+def test_checkout_update_language_code_by_token(
+ user_api_client,
+ checkout_with_gift_card,
+):
+ language_code = "PL"
+ checkout = checkout_with_gift_card
+
+ variables = {"token": checkout.token, "languageCode": language_code}
+
+ response = user_api_client.post_graphql(
+ MUTATION_CHECKOUT_UPDATE_LANGUAGE_CODE, variables
+ )
+
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutLanguageCodeUpdate"]
+ assert not data["errors"]
+
+ assert data["checkout"]["languageCode"] == language_code
+ checkout.refresh_from_db()
+ assert checkout.language_code == language_code.lower()
+
+
def test_checkout_update_language_code_neither_token_and_id_given(
user_api_client,
checkout_with_gift_card,
diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_line_delete.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_line_delete.py
index 1a95c4baf5..f783cb3a0c 100644
--- a/saleor/graphql/checkout/tests/deprecated/test_checkout_line_delete.py
+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout_line_delete.py
@@ -64,6 +64,38 @@ def test_checkout_line_delete_by_id(
mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)
+ "saleor.graphql.checkout.mutations.checkout_line_delete."
+ "update_checkout_shipping_method_if_invalid",
+ wraps=update_checkout_shipping_method_if_invalid,
+)
+def test_checkout_line_delete_by_token(
+ mocked_update_shipping_method, user_api_client, checkout_with_item
+):
+ checkout = checkout_with_item
+ lines, _ = fetch_checkout_lines(checkout)
+ assert calculate_checkout_quantity(lines) == 3
+ assert checkout.lines.count() == 1
+ line = checkout.lines.first()
+ assert line.quantity == 3
+
+ line_id = graphene.Node.to_global_id("CheckoutLine", line.pk)
+
+ variables = {"token": checkout.token, "lineId": line_id}
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_DELETE, variables)
+ content = get_graphql_content(response)
+
+ data = content["data"]["checkoutLineDelete"]
+ assert not data["errors"]
+ checkout.refresh_from_db()
+ lines, _ = fetch_checkout_lines(checkout)
+ assert checkout.lines.count() == 0
+ assert calculate_checkout_quantity(lines) == 0
+ manager = get_plugins_manager()
+ checkout_info = fetch_checkout_info(checkout, lines, [], manager)
+ mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)
+
+
def test_checkout_line_delete_neither_token_and_id_given(
user_api_client, checkout_with_item
):
diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_lines_add.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_lines_add.py
index 3ad48162f2..db9a4fc7f0 100644
--- a/saleor/graphql/checkout/tests/deprecated/test_checkout_lines_add.py
+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout_lines_add.py
@@ -71,6 +71,47 @@ def test_checkout_lines_add_by_checkout_id(
mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)
+ "saleor.graphql.checkout.mutations.checkout_lines_add."
+ "update_checkout_shipping_method_if_invalid",
+ wraps=update_checkout_shipping_method_if_invalid,
+)
+def test_checkout_lines_add_by_checkout_token(
+ mocked_update_shipping_method, user_api_client, checkout_with_item, stock
+):
+ # given
+ variant = stock.product_variant
+ checkout = checkout_with_item
+ lines, _ = fetch_checkout_lines(checkout)
+ assert calculate_checkout_quantity(lines) == 3
+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
+
+ variables = {
+ "token": checkout.token,
+ "lines": [{"variantId": variant_id, "quantity": 1}],
+ "channelSlug": checkout.channel.slug,
+ }
+
+ # when
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
+
+ # then
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutLinesAdd"]
+ assert not data["errors"]
+ checkout.refresh_from_db()
+ lines, _ = fetch_checkout_lines(checkout)
+ line = checkout.lines.last()
+ assert line.variant == variant
+ assert line.quantity == 1
+ assert calculate_checkout_quantity(lines) == 4
+
+ manager = get_plugins_manager()
+ lines, _ = fetch_checkout_lines(checkout)
+ checkout_info = fetch_checkout_info(checkout, lines, [], manager)
+ mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)
+
+
def test_checkout_lines_add_neither_token_and_id_given(
user_api_client, checkout_with_item, stock
):
diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_lines_update.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_lines_update.py
index 849421fe92..28a5ff6e07 100644
--- a/saleor/graphql/checkout/tests/deprecated/test_checkout_lines_update.py
+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout_lines_update.py
@@ -76,6 +76,47 @@ def test_checkout_lines_update(
mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)
+ "saleor.graphql.checkout.mutations.checkout_lines_add."
+ "update_checkout_shipping_method_if_invalid",
+ wraps=update_checkout_shipping_method_if_invalid,
+)
+def test_checkout_lines_update_with_token(
+ mocked_update_shipping_method, user_api_client, checkout_with_item
+):
+ checkout = checkout_with_item
+ lines, _ = fetch_checkout_lines(checkout)
+ assert checkout.lines.count() == 1
+ assert calculate_checkout_quantity(lines) == 3
+ line = checkout.lines.first()
+ variant = line.variant
+ assert line.quantity == 3
+
+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
+
+ variables = {
+ "token": checkout.token,
+ "lines": [{"variantId": variant_id, "quantity": 1}],
+ }
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
+ content = get_graphql_content(response)
+
+ data = content["data"]["checkoutLinesUpdate"]
+ assert not data["errors"]
+ checkout.refresh_from_db()
+ lines, _ = fetch_checkout_lines(checkout)
+ assert checkout.lines.count() == 1
+ line = checkout.lines.first()
+ assert line.variant == variant
+ assert line.quantity == 1
+ assert calculate_checkout_quantity(lines) == 1
+
+ manager = get_plugins_manager()
+ lines, _ = fetch_checkout_lines(checkout)
+ checkout_info = fetch_checkout_info(checkout, lines, [], manager)
+ mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)
+
+
def test_checkout_lines_update_neither_token_and_id_given(
user_api_client, checkout_with_item
):
diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_promo_codes.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_promo_codes.py
index cafb00d197..79b2668208 100644
--- a/saleor/graphql/checkout/tests/deprecated/test_checkout_promo_codes.py
+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout_promo_codes.py
@@ -50,6 +50,16 @@ def test_checkout_add_voucher_code_by_id(api_client, checkout_with_item, voucher
assert data["checkout"]["voucherCode"] == voucher.code
+def test_checkout_add_voucher_code_by_token(api_client, checkout_with_item, voucher):
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
+ variables = {"token": checkout_with_item.token, "promoCode": voucher.code}
+ data = _mutate_checkout_add_promo_code(api_client, variables)
+
+ assert not data["errors"]
+ assert data["checkout"]["id"] == checkout_id
+ assert data["checkout"]["voucherCode"] == voucher.code
+
+
def test_checkout_add_voucher_code_neither_token_and_id_given(
api_client, checkout_with_item, voucher
):
diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_shipping_address_update.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_shipping_address_update.py
index ea6f65c856..22a1ed2304 100644
--- a/saleor/graphql/checkout/tests/deprecated/test_checkout_shipping_address_update.py
+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout_shipping_address_update.py
@@ -72,6 +72,52 @@ def test_checkout_shipping_address_update_by_id(
mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)
+ "saleor.graphql.checkout.mutations.checkout_shipping_address_update."
+ "update_checkout_shipping_method_if_invalid",
+ wraps=update_checkout_shipping_method_if_invalid,
+)
+def test_checkout_shipping_address_update_by_token(
+ mocked_update_shipping_method,
+ user_api_client,
+ checkout_with_item,
+ graphql_address_data,
+):
+ # given
+ checkout = checkout_with_item
+ assert checkout.shipping_address is None
+
+ shipping_address = graphql_address_data
+ variables = {"token": checkout.token, "shippingAddress": shipping_address}
+
+ # when
+ response = user_api_client.post_graphql(
+ MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE, variables
+ )
+
+ # then
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutShippingAddressUpdate"]
+ assert not data["errors"]
+ checkout.refresh_from_db()
+ assert checkout.shipping_address is not None
+ assert checkout.shipping_address.first_name == shipping_address["firstName"]
+ assert checkout.shipping_address.last_name == shipping_address["lastName"]
+ assert (
+ checkout.shipping_address.street_address_1 == shipping_address["streetAddress1"]
+ )
+ assert (
+ checkout.shipping_address.street_address_2 == shipping_address["streetAddress2"]
+ )
+ assert checkout.shipping_address.postal_code == shipping_address["postalCode"]
+ assert checkout.shipping_address.country == shipping_address["country"]
+ assert checkout.shipping_address.city == shipping_address["city"].upper()
+ manager = get_plugins_manager()
+ lines, _ = fetch_checkout_lines(checkout)
+ checkout_info = fetch_checkout_info(checkout, lines, [], manager)
+ mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)
+
+
def test_checkout_shipping_address_update_neither_token_and_id_given(
user_api_client,
checkout_with_item,
diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_shipping_method_update.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_shipping_method_update.py
index a89e8a472d..5726b530c0 100644
--- a/saleor/graphql/checkout/tests/deprecated/test_checkout_shipping_method_update.py
+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout_shipping_method_update.py
@@ -101,7 +101,7 @@ def test_checkout_shipping_method_update_by_token(
method_id = graphene.Node.to_global_id("ShippingMethod", shipping_method.id)
response = staff_api_client.post_graphql(
- query, {"checkoutId": checkout_id, "shippingMethodId": method_id}
+ query, {"token": checkout.token, "shippingMethodId": method_id}
)
data = get_graphql_content(response)["data"]["checkoutShippingMethodUpdate"]
diff --git a/saleor/graphql/checkout/tests/deprecated/test_customer_detach_mutation.py b/saleor/graphql/checkout/tests/deprecated/test_customer_detach_mutation.py
index fd214cb2e8..18e1e0ea7f 100644
--- a/saleor/graphql/checkout/tests/deprecated/test_customer_detach_mutation.py
+++ b/saleor/graphql/checkout/tests/deprecated/test_customer_detach_mutation.py
@@ -40,6 +40,26 @@ def test_checkout_customer_detach_by_id(
assert checkout.user is None
+def test_checkout_customer_detach_by_token(
+ user_api_client, checkout_with_item, customer_user
+):
+ checkout = checkout_with_item
+ checkout.user = customer_user
+ checkout.save(update_fields=["user"])
+
+ variables = {"token": checkout.token}
+
+ # Mutation should succeed if the user owns this checkout.
+ response = user_api_client.post_graphql(
+ MUTATION_CHECKOUT_CUSTOMER_DETACH, variables
+ )
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutCustomerDetach"]
+ assert not data["errors"]
+ checkout.refresh_from_db()
+ assert checkout.user is None
+
+
def test_checkout_customer_detach_neither_token_and_id_given(
user_api_client, checkout_with_item, customer_user
):
diff --git a/saleor/graphql/checkout/tests/test_checkout.py b/saleor/graphql/checkout/tests/test_checkout.py
index 9600732cc8..788d234a72 100644
--- a/saleor/graphql/checkout/tests/test_checkout.py
+++ b/saleor/graphql/checkout/tests/test_checkout.py
@@ -1,5 +1,4 @@
import datetime
-import uuid
import warnings
from decimal import Decimal
from unittest import mock
@@ -50,6 +49,7 @@ from ....shipping.utils import convert_to_shipping_method_data
from ....tests.utils import dummy_editorjs
from ....warehouse import WarehouseClickAndCollectOption
from ....warehouse.models import PreorderReservation, Reservation, Stock, Warehouse
+from ...core.utils import to_global_id_or_none
from ...tests.utils import assert_no_permission, get_graphql_content
from ..mutations.utils import (
clean_delivery_method,
@@ -1686,8 +1686,8 @@ def expected_dummy_gateway():
GET_CHECKOUT_PAYMENTS_QUERY = """
-query getCheckoutPayments($token: UUID!) {
- checkout(token: $token) {
+query getCheckoutPayments($id: ID) {
+ checkout(id: $id) {
availablePaymentGateways {
id
name
@@ -1708,7 +1708,7 @@ def test_checkout_available_payment_gateways(
expected_dummy_gateway,
):
query = GET_CHECKOUT_PAYMENTS_QUERY
- variables = {"token": str(checkout_with_item.token)}
+ variables = {"id": to_global_id_or_none(checkout_with_item)}
response = api_client.post_graphql(query, variables)
content = get_graphql_content(response)
@@ -1729,7 +1729,7 @@ def test_checkout_available_payment_gateways_currency_specified_USD(
query = GET_CHECKOUT_PAYMENTS_QUERY
- variables = {"token": str(checkout_with_item.token)}
+ variables = {"id": to_global_id_or_none(checkout_with_item)}
response = api_client.post_graphql(query, variables)
content = get_graphql_content(response)
@@ -1748,7 +1748,7 @@ def test_checkout_available_payment_gateways_currency_specified_EUR(
query = GET_CHECKOUT_PAYMENTS_QUERY
- variables = {"token": str(checkout_with_item.token)}
+ variables = {"id": to_global_id_or_none(checkout_with_item)}
response = api_client.post_graphql(query, variables)
content = get_graphql_content(response)
@@ -1759,8 +1759,8 @@ def test_checkout_available_payment_gateways_currency_specified_EUR(
GET_CHECKOUT_SELECTED_SHIPPING_METHOD = """
-query getCheckout($token: UUID!) {
- checkout(token: $token) {
+query getCheckout($id: ID) {
+ checkout(id: $id) {
shippingMethod {
id
name
@@ -1831,7 +1831,7 @@ def test_checkout_selected_shipping_method(
# when
query = GET_CHECKOUT_SELECTED_SHIPPING_METHOD
- variables = {"token": checkout_with_item.token}
+ variables = {"id": to_global_id_or_none(checkout_with_item)}
response = api_client.post_graphql(query, variables)
content = get_graphql_content(response)
data = content["data"]["checkout"]
@@ -1863,8 +1863,8 @@ def test_checkout_selected_shipping_method(
GET_CHECKOUT_SELECTED_SHIPPING_METHOD_PRIVATE_FIELDS = """
-query getCheckout($token: UUID!) {
- checkout(token: $token) {
+query getCheckout($id: ID) {
+ checkout(id: $id) {
shippingMethod {
id
privateMetadata {
@@ -1892,7 +1892,7 @@ def test_checkout_selected_shipping_method_as_staff(
# when
query = GET_CHECKOUT_SELECTED_SHIPPING_METHOD_PRIVATE_FIELDS
- variables = {"token": checkout_with_item.token}
+ variables = {"id": to_global_id_or_none(checkout_with_item)}
response = staff_api_client.post_graphql(query, variables)
content = get_graphql_content(response)
data = content["data"]["checkout"]
@@ -1903,8 +1903,8 @@ def test_checkout_selected_shipping_method_as_staff(
GET_CHECKOUT_AVAILABLE_SHIPPING_METHODS_TEMPLATE = """
-query getCheckout($token: UUID!) {
- checkout(token: $token) {
+query getCheckout($id: ID) {
+ checkout(id: $id) {
%s {
id
type
@@ -1975,7 +1975,7 @@ def test_checkout_available_shipping_methods(
# when
query = GET_CHECKOUT_AVAILABLE_SHIPPING_METHODS_TEMPLATE % field
- variables = {"token": checkout_with_item.token}
+ variables = {"id": to_global_id_or_none(checkout_with_item)}
response = api_client.post_graphql(query, variables)
content = get_graphql_content(response)
data = content["data"]["checkout"]
@@ -2028,7 +2028,7 @@ def test_checkout_available_shipping_methods_with_weight_based_shipping_method(
shipping_method.save(update_fields=["minimum_order_weight"])
query = GET_CHECKOUT_AVAILABLE_SHIPPING_METHODS
- variables = {"token": checkout_with_item.token}
+ variables = {"id": to_global_id_or_none(checkout_with_item)}
response = api_client.post_graphql(query, variables)
content = get_graphql_content(response)
data = content["data"]["checkout"]
@@ -2056,7 +2056,7 @@ def test_checkout_available_shipping_methods_weight_method_with_higher_minimal_w
ProductVariant.objects.bulk_update(variants, ["weight"])
query = GET_CHECKOUT_AVAILABLE_SHIPPING_METHODS
- variables = {"token": checkout_with_item.token}
+ variables = {"id": to_global_id_or_none(checkout_with_item)}
response = api_client.post_graphql(query, variables)
content = get_graphql_content(response)
data = content["data"]["checkout"]
@@ -2098,7 +2098,7 @@ def test_checkout_shipping_methods_with_price_based_shipping_method_and_discount
shipping_channel_listing.save(update_fields=["minimum_order_price_amount"])
query = GET_CHECKOUT_AVAILABLE_SHIPPING_METHODS
- variables = {"token": checkout_with_item.token}
+ variables = {"id": to_global_id_or_none(checkout_with_item)}
response = api_client.post_graphql(query, variables)
content = get_graphql_content(response)
data = content["data"]["checkout"]
@@ -2144,7 +2144,7 @@ def test_checkout_shipping_methods_with_price_based_shipping_and_shipping_discou
shipping_channel_listing.save(update_fields=["minimum_order_price_amount"])
query = GET_CHECKOUT_AVAILABLE_SHIPPING_METHODS
- variables = {"token": checkout_with_item.token}
+ variables = {"id": to_global_id_or_none(checkout_with_item)}
response = api_client.post_graphql(query, variables)
content = get_graphql_content(response)
data = content["data"]["checkout"]
@@ -2161,7 +2161,7 @@ def test_checkout_available_shipping_methods_shipping_zone_without_channels(
checkout_with_item.save()
query = GET_CHECKOUT_AVAILABLE_SHIPPING_METHODS
- variables = {"token": checkout_with_item.token}
+ variables = {"id": to_global_id_or_none(checkout_with_item)}
response = api_client.post_graphql(query, variables)
content = get_graphql_content(response)
data = content["data"]["checkout"]
@@ -2181,7 +2181,7 @@ def test_checkout_available_shipping_methods_excluded_postal_codes(
shipping_method.postal_code_rules.create(start="BH16 7HA", end="BH16 7HG")
query = GET_CHECKOUT_AVAILABLE_SHIPPING_METHODS
- variables = {"token": checkout_with_item.token}
+ variables = {"id": to_global_id_or_none(checkout_with_item)}
response = api_client.post_graphql(query, variables)
content = get_graphql_content(response)
data = content["data"]["checkout"]
@@ -2217,7 +2217,7 @@ def test_checkout_available_shipping_methods_with_price_displayed(
query = GET_CHECKOUT_AVAILABLE_SHIPPING_METHODS
- variables = {"token": checkout_with_item.token}
+ variables = {"id": to_global_id_or_none(checkout_with_item)}
response = api_client.post_graphql(query, variables)
content = get_graphql_content(response)
data = content["data"]["checkout"]
@@ -2243,7 +2243,7 @@ def test_checkout_no_available_shipping_methods_without_address(
api_client, checkout_with_item
):
query = GET_CHECKOUT_AVAILABLE_SHIPPING_METHODS
- variables = {"token": checkout_with_item.token}
+ variables = {"id": to_global_id_or_none(checkout_with_item)}
response = api_client.post_graphql(query, variables)
content = get_graphql_content(response)
data = content["data"]["checkout"]
@@ -2254,7 +2254,7 @@ def test_checkout_no_available_shipping_methods_without_address(
def test_checkout_no_available_shipping_methods_without_lines(api_client, checkout):
query = GET_CHECKOUT_AVAILABLE_SHIPPING_METHODS
- variables = {"token": checkout.token}
+ variables = {"id": to_global_id_or_none(checkout)}
response = api_client.post_graphql(query, variables)
content = get_graphql_content(response)
data = content["data"]["checkout"]
@@ -2263,8 +2263,8 @@ def test_checkout_no_available_shipping_methods_without_lines(api_client, checko
GET_CHECKOUT_AVAILABLE_COLLECTION_POINTS = """
-query getCheckout($token: UUID!) {
- checkout(token: $token) {
+query getCheckout($id: ID) {
+ checkout(id: $id) {
availableCollectionPoints {
name
address {
@@ -2276,8 +2276,8 @@ query getCheckout($token: UUID!) {
"""
QUERY_GET_ALL_COLLECTION_POINTS_FROM_CHECKOUT = """
-query AvailableCollectionPoints($token: UUID!) {
- checkout(token: $token) {
+query AvailableCollectionPoints($id: ID) {
+ checkout(id: $id) {
availableCollectionPoints {
name
}
@@ -2298,7 +2298,7 @@ def test_available_collection_points_for_preorders_variants_in_checkout(
)
response = staff_api_client.post_graphql(
QUERY_GET_ALL_COLLECTION_POINTS_FROM_CHECKOUT,
- variables={"token": checkout_with_preorders_only.token},
+ variables={"id": to_global_id_or_none(checkout_with_preorders_only)},
)
response_content = get_graphql_content(response)
assert (
@@ -2316,7 +2316,9 @@ def test_available_collection_points_for_preorders_and_regular_variants_in_check
expected_collection_points = [{"name": warehouses_for_cc[1].name}]
response = staff_api_client.post_graphql(
QUERY_GET_ALL_COLLECTION_POINTS_FROM_CHECKOUT,
- variables={"token": checkout_with_preorders_and_regular_variant.token},
+ variables={
+ "id": to_global_id_or_none(checkout_with_preorders_and_regular_variant)
+ },
)
response_content = get_graphql_content(response)
assert (
@@ -2334,7 +2336,7 @@ def test_checkout_available_collection_points_with_lines_avail_in_1_local_and_1_
]
query = GET_CHECKOUT_AVAILABLE_COLLECTION_POINTS
- variables = {"token": checkout_with_items_for_cc.token}
+ variables = {"id": to_global_id_or_none(checkout_with_items_for_cc)}
response = api_client.post_graphql(query, variables)
content = get_graphql_content(response)
received_collection_points = content["data"]["checkout"][
@@ -2355,7 +2357,7 @@ def test_checkout_available_collection_points_with_line_avail_in_2_local_and_1_a
]
query = GET_CHECKOUT_AVAILABLE_COLLECTION_POINTS
- variables = {"token": checkout_with_item_for_cc.token}
+ variables = {"id": to_global_id_or_none(checkout_with_item_for_cc)}
response = api_client.post_graphql(query, variables)
content = get_graphql_content(response)
received_collection_points = content["data"]["checkout"][
@@ -2380,7 +2382,7 @@ def test_checkout_avail_collect_points_exceeded_quantity_shows_only_all_warehous
line.save(update_fields=["quantity"])
checkout_with_items_for_cc.refresh_from_db()
- variables = {"token": checkout_with_items_for_cc.token}
+ variables = {"id": to_global_id_or_none(checkout_with_items_for_cc)}
response = api_client.post_graphql(query, variables)
content = get_graphql_content(response)
data = content["data"]["checkout"]
@@ -2396,7 +2398,7 @@ def test_checkout_avail_collect_points_returns_empty_list_when_not_in_shipping_z
query = GET_CHECKOUT_AVAILABLE_COLLECTION_POINTS
warehouse_for_cc.shipping_zones.filter(name="Poland").delete()
- variables = {"token": checkout_with_items_for_cc.token}
+ variables = {"id": to_global_id_or_none(checkout_with_items_for_cc)}
response = api_client.post_graphql(query, variables)
content = get_graphql_content(response)
data = content["data"]["checkout"]
@@ -2411,7 +2413,7 @@ def test_checkout_avail_collect_fallbacks_to_channel_country_when_no_shipping_ad
checkout_with_items_for_cc.shipping_address = None
checkout_with_items_for_cc.save()
- variables = {"token": checkout_with_items_for_cc.token}
+ variables = {"id": to_global_id_or_none(checkout_with_items_for_cc)}
response = api_client.post_graphql(query, variables)
content = get_graphql_content(response)
data = content["data"]["checkout"]
@@ -2460,8 +2462,8 @@ def test_create_checkout_with_unpublished_product(
MUTATION_CHECKOUT_CUSTOMER_ATTACH = """
- mutation checkoutCustomerAttach($token: UUID, $customerId: ID) {
- checkoutCustomerAttach(token: $token, customerId: $customerId) {
+ mutation checkoutCustomerAttach($id: ID, $customerId: ID) {
+ checkoutCustomerAttach(id: $id, customerId: $customerId) {
checkout {
token
}
@@ -2486,7 +2488,7 @@ def test_checkout_customer_attach(
query = MUTATION_CHECKOUT_CUSTOMER_ATTACH
customer_id = graphene.Node.to_global_id("User", customer_user.pk)
- variables = {"token": checkout.token, "customerId": customer_id}
+ variables = {"id": to_global_id_or_none(checkout), "customerId": customer_id}
response = user_api_client.post_graphql(
query, variables, permissions=[permission_impersonate_user]
@@ -2511,7 +2513,7 @@ def test_checkout_customer_attach_no_customer_id(
previous_last_change = checkout.last_change
query = MUTATION_CHECKOUT_CUSTOMER_ATTACH
- variables = {"token": checkout.token}
+ variables = {"id": to_global_id_or_none(checkout)}
# Mutation should fail for unauthenticated customers
response = api_client.post_graphql(query, variables)
@@ -2539,7 +2541,7 @@ def test_checkout_customer_attach_by_app(
query = MUTATION_CHECKOUT_CUSTOMER_ATTACH
customer_id = graphene.Node.to_global_id("User", customer_user.pk)
- variables = {"token": checkout.token, "customerId": customer_id}
+ variables = {"id": to_global_id_or_none(checkout), "customerId": customer_id}
# Mutation should succeed for authenticated customer
response = app_api_client.post_graphql(
@@ -2563,7 +2565,7 @@ def test_checkout_customer_attach_by_app_no_customer_id(
assert checkout.user is None
query = MUTATION_CHECKOUT_CUSTOMER_ATTACH
- variables = {"token": checkout.token}
+ variables = {"id": to_global_id_or_none(checkout)}
# Mutation should succeed for authenticated customer
response = app_api_client.post_graphql(
@@ -2589,7 +2591,7 @@ def test_checkout_customer_attach_by_app_without_permission(
query = MUTATION_CHECKOUT_CUSTOMER_ATTACH
customer_id = graphene.Node.to_global_id("User", customer_user.pk)
- variables = {"token": checkout.token, "customerId": customer_id}
+ variables = {"id": to_global_id_or_none(checkout), "customerId": customer_id}
# Mutation should succeed for authenticated customer
response = app_api_client.post_graphql(
@@ -2606,8 +2608,8 @@ def test_checkout_customer_attach_user_to_checkout_with_user(
checkout = user_checkout
query = """
- mutation checkoutCustomerAttach($checkoutId: ID, $token: UUID) {
- checkoutCustomerAttach(checkoutId: $checkoutId, token: $token) {
+ mutation checkoutCustomerAttach($id: ID) {
+ checkoutCustomerAttach(id: $id) {
checkout {
token
}
@@ -2632,14 +2634,14 @@ def test_checkout_customer_attach_user_to_checkout_with_user(
checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
customer_id = graphene.Node.to_global_id("User", second_user.pk)
- variables = {"checkoutId": checkout_id, "customerId": customer_id}
+ variables = {"id": checkout_id, "customerId": customer_id}
response = user_api_client.post_graphql(query, variables)
assert_no_permission(response)
GET_CHECKOUT_STOCK_RESERVATION_EXPIRES_QUERY = """
-query getCheckoutStockReservationExpiration($token: UUID!) {
- checkout(token: $token) {
+query getCheckoutStockReservationExpiration($id: ID) {
+ checkout(id: $id) {
stockReservationExpires
}
}
@@ -2654,7 +2656,9 @@ def test_checkout_reservation_date_for_stock_reservation(
):
reservation = Reservation.objects.order_by("reserved_until").first()
query = GET_CHECKOUT_STOCK_RESERVATION_EXPIRES_QUERY
- variables = {"token": checkout_line_with_one_reservation.checkout.token}
+ variables = {
+ "id": to_global_id_or_none(checkout_line_with_one_reservation.checkout)
+ }
response = api_client.post_graphql(query, variables)
data = get_graphql_content(response)["data"]["checkout"]["stockReservationExpires"]
assert parse_datetime(data) == reservation.reserved_until
@@ -2668,7 +2672,9 @@ def test_checkout_reservation_date_for_preorder_reservation(
):
reservation = PreorderReservation.objects.order_by("reserved_until").first()
query = GET_CHECKOUT_STOCK_RESERVATION_EXPIRES_QUERY
- variables = {"token": checkout_line_with_reserved_preorder_item.checkout.token}
+ variables = {
+ "id": to_global_id_or_none(checkout_line_with_reserved_preorder_item.checkout)
+ }
response = api_client.post_graphql(query, variables)
data = get_graphql_content(response)["data"]["checkout"]["stockReservationExpires"]
assert parse_datetime(data) == reservation.reserved_until
@@ -2683,7 +2689,9 @@ def test_checkout_reservation_date_for_multiple_reservations(
):
reservation = Reservation.objects.order_by("reserved_until").first()
query = GET_CHECKOUT_STOCK_RESERVATION_EXPIRES_QUERY
- variables = {"token": checkout_line_with_one_reservation.checkout.token}
+ variables = {
+ "id": to_global_id_or_none(checkout_line_with_one_reservation.checkout)
+ }
response = api_client.post_graphql(query, variables)
data = get_graphql_content(response)["data"]["checkout"]["stockReservationExpires"]
assert parse_datetime(data) == reservation.reserved_until
@@ -2705,7 +2713,9 @@ def test_checkout_reservation_date_for_multiple_reservations_types(
reservation = PreorderReservation.objects.order_by("reserved_until").first()
query = GET_CHECKOUT_STOCK_RESERVATION_EXPIRES_QUERY
- variables = {"token": checkout_line_with_one_reservation.checkout.token}
+ variables = {
+ "id": to_global_id_or_none(checkout_line_with_one_reservation.checkout)
+ }
response = api_client.post_graphql(query, variables)
data = get_graphql_content(response)["data"]["checkout"]["stockReservationExpires"]
assert parse_datetime(data) == reservation.reserved_until
@@ -2726,7 +2736,9 @@ def test_checkout_reservation_date_for_expired_reservations(
)
query = GET_CHECKOUT_STOCK_RESERVATION_EXPIRES_QUERY
- variables = {"token": checkout_line_with_one_reservation.checkout.token}
+ variables = {
+ "id": to_global_id_or_none(checkout_line_with_one_reservation.checkout)
+ }
response = api_client.post_graphql(query, variables)
content = get_graphql_content(response)
assert content["data"]["checkout"]["stockReservationExpires"] is None
@@ -2743,7 +2755,9 @@ def test_checkout_reservation_date_for_no_reservations(
PreorderReservation.objects.all().delete()
query = GET_CHECKOUT_STOCK_RESERVATION_EXPIRES_QUERY
- variables = {"token": checkout_line_with_one_reservation.checkout.token}
+ variables = {
+ "id": to_global_id_or_none(checkout_line_with_one_reservation.checkout)
+ }
response = api_client.post_graphql(query, variables)
content = get_graphql_content(response)
assert content["data"]["checkout"]["stockReservationExpires"] is None
@@ -2756,15 +2770,17 @@ def test_checkout_reservation_date_for_disabled_reservations(
address,
):
query = GET_CHECKOUT_STOCK_RESERVATION_EXPIRES_QUERY
- variables = {"token": checkout_line_with_one_reservation.checkout.token}
+ variables = {
+ "id": to_global_id_or_none(checkout_line_with_one_reservation.checkout)
+ }
response = api_client.post_graphql(query, variables)
content = get_graphql_content(response)
assert content["data"]["checkout"]["stockReservationExpires"] is None
MUTATION_CHECKOUT_CUSTOMER_DETACH = """
- mutation checkoutCustomerDetach($token: UUID) {
- checkoutCustomerDetach(token: $token) {
+ mutation checkoutCustomerDetach($id: ID) {
+ checkoutCustomerDetach(id: $id) {
checkout {
token
}
@@ -2783,7 +2799,7 @@ def test_checkout_customer_detach(user_api_client, checkout_with_item, customer_
checkout.save(update_fields=["user"])
previous_last_change = checkout.last_change
- variables = {"token": checkout.token}
+ variables = {"id": to_global_id_or_none(checkout)}
# Mutation should succeed if the user owns this checkout.
response = user_api_client.post_graphql(
@@ -2814,7 +2830,7 @@ def test_checkout_customer_detach_by_app(
checkout.save(update_fields=["user"])
previous_last_change = checkout.last_change
- variables = {"token": checkout.token}
+ variables = {"id": to_global_id_or_none(checkout)}
# Mutation should succeed if the user owns this checkout.
response = app_api_client.post_graphql(
@@ -2838,7 +2854,7 @@ def test_checkout_customer_detach_by_app_without_permissions(
checkout.save(update_fields=["user"])
previous_last_change = checkout.last_change
- variables = {"token": checkout.token}
+ variables = {"id": to_global_id_or_none(checkout)}
# Mutation should succeed if the user owns this checkout.
response = app_api_client.post_graphql(MUTATION_CHECKOUT_CUSTOMER_DETACH, variables)
@@ -2850,9 +2866,9 @@ def test_checkout_customer_detach_by_app_without_permissions(
MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE = """
mutation checkoutShippingAddressUpdate(
- $token: UUID, $shippingAddress: AddressInput!) {
+ $id: ID, $shippingAddress: AddressInput!) {
checkoutShippingAddressUpdate(
- token: $token, shippingAddress: $shippingAddress) {
+ id: $id, shippingAddress: $shippingAddress) {
checkout {
token,
id
@@ -2882,7 +2898,10 @@ def test_checkout_shipping_address_update(
previous_last_change = checkout.last_change
shipping_address = graphql_address_data
- variables = {"token": checkout_with_item.token, "shippingAddress": shipping_address}
+ variables = {
+ "id": to_global_id_or_none(checkout_with_item),
+ "shippingAddress": shipping_address,
+ }
response = user_api_client.post_graphql(
MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE, variables
@@ -2935,7 +2954,10 @@ def test_checkout_shipping_address_update_changes_checkout_country(
shipping_address["country"] = "US"
shipping_address["countryArea"] = "New York"
shipping_address["postalCode"] = "10001"
- variables = {"token": checkout.token, "shippingAddress": shipping_address}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "shippingAddress": shipping_address,
+ }
response = user_api_client.post_graphql(
MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE, variables
@@ -2992,7 +3014,10 @@ def test_checkout_shipping_address_update_insufficient_stocks(
shipping_address["country"] = "US"
shipping_address["countryArea"] = "New York"
shipping_address["postalCode"] = "10001"
- variables = {"token": checkout.token, "shippingAddress": shipping_address}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "shippingAddress": shipping_address,
+ }
response = user_api_client.post_graphql(
MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE, variables
@@ -3031,7 +3056,10 @@ def test_checkout_shipping_address_update_with_reserved_stocks(
shipping_address["country"] = "US"
shipping_address["countryArea"] = "New York"
shipping_address["postalCode"] = "10001"
- variables = {"token": checkout.token, "shippingAddress": shipping_address}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "shippingAddress": shipping_address,
+ }
other_checkout = Checkout.objects.create(channel=channel_USD, currency="USD")
other_checkout_line = other_checkout.lines.create(
variant=variant,
@@ -3082,7 +3110,10 @@ def test_checkout_shipping_address_update_against_reserved_stocks(
shipping_address["country"] = "US"
shipping_address["countryArea"] = "New York"
shipping_address["postalCode"] = "10001"
- variables = {"token": checkout.token, "shippingAddress": shipping_address}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "shippingAddress": shipping_address,
+ }
other_checkout = Checkout.objects.create(channel=channel_USD, currency="USD")
other_checkout_line = other_checkout.lines.create(
@@ -3119,7 +3150,10 @@ def test_checkout_shipping_address_update_channel_without_shipping_zones(
previous_last_change = checkout.last_change
shipping_address = graphql_address_data
- variables = {"token": checkout.token, "shippingAddress": shipping_address}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "shippingAddress": shipping_address,
+ }
response = user_api_client.post_graphql(
MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE, variables
@@ -3146,7 +3180,7 @@ def test_checkout_shipping_address_with_invalid_phone_number_returns_error(
user_api_client.post_graphql(
MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE,
{
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"shippingAddress": shipping_address,
},
)
@@ -3172,7 +3206,10 @@ def test_checkout_shipping_address_update_with_phone_country_prefix(
shipping_address = graphql_address_data
shipping_address["phone"] = number
- variables = {"token": checkout.token, "shippingAddress": shipping_address}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "shippingAddress": shipping_address,
+ }
response = user_api_client.post_graphql(
MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE, variables
@@ -3190,7 +3227,10 @@ def test_checkout_shipping_address_update_without_phone_country_prefix(
shipping_address = graphql_address_data
shipping_address["phone"] = "+1-202-555-0132"
- variables = {"token": checkout.token, "shippingAddress": shipping_address}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "shippingAddress": shipping_address,
+ }
response = user_api_client.post_graphql(
MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE, variables
@@ -3219,7 +3259,10 @@ def test_checkout_shipping_address_update_exclude_shipping_method(
ExcludedShippingMethod(shipping_method.id, webhook_reason)
]
shipping_address = graphql_address_data
- variables = {"token": checkout.token, "shippingAddress": shipping_address}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "shippingAddress": shipping_address,
+ }
user_api_client.post_graphql(MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE, variables)
checkout.refresh_from_db()
@@ -3235,9 +3278,9 @@ def test_checkout_billing_address_update(
query = """
mutation checkoutBillingAddressUpdate(
- $token: UUID, $billingAddress: AddressInput!) {
+ $id: ID, $billingAddress: AddressInput!) {
checkoutBillingAddressUpdate(
- token: $token, billingAddress: $billingAddress) {
+ id: $id, billingAddress: $billingAddress) {
checkout {
token,
id
@@ -3251,7 +3294,10 @@ def test_checkout_billing_address_update(
"""
billing_address = graphql_address_data
- variables = {"token": checkout_with_item.token, "billingAddress": billing_address}
+ variables = {
+ "id": to_global_id_or_none(checkout_with_item),
+ "billingAddress": billing_address,
+ }
response = user_api_client.post_graphql(query, variables)
content = get_graphql_content(response)
@@ -3274,8 +3320,8 @@ def test_checkout_billing_address_update(
CHECKOUT_EMAIL_UPDATE_MUTATION = """
- mutation checkoutEmailUpdate($token: UUID, $email: String!) {
- checkoutEmailUpdate(token: $token, email: $email) {
+ mutation checkoutEmailUpdate($id: ID, $email: String!) {
+ checkoutEmailUpdate(id: $id, email: $email) {
checkout {
id,
email
@@ -3301,7 +3347,7 @@ def test_checkout_email_update(user_api_client, checkout_with_item):
previous_last_change = checkout.last_change
- variables = {"token": checkout.token, "email": email}
+ variables = {"id": to_global_id_or_none(checkout), "email": email}
response = user_api_client.post_graphql(CHECKOUT_EMAIL_UPDATE_MUTATION, variables)
content = get_graphql_content(response)
@@ -3313,7 +3359,7 @@ def test_checkout_email_update(user_api_client, checkout_with_item):
def test_checkout_email_update_validation(user_api_client, checkout_with_item):
- variables = {"token": checkout_with_item.token, "email": ""}
+ variables = {"id": to_global_id_or_none(checkout_with_item), "email": ""}
response = user_api_client.post_graphql(CHECKOUT_EMAIL_UPDATE_MUTATION, variables)
content = get_graphql_content(response)
@@ -3356,8 +3402,8 @@ TRANSACTION_CONFIRM_GATEWAY_RESPONSE = GatewayResponse(
)
QUERY_CHECKOUT_USER_ID = """
- query getCheckout($token: UUID!) {
- checkout(token: $token) {
+ query getCheckout($id: ID) {
+ checkout(id: $id) {
user {
id
}
@@ -3369,7 +3415,7 @@ QUERY_CHECKOUT_USER_ID = """
def test_anonymous_client_can_fetch_anonymoues_checkout_user(api_client, checkout):
# given
query = QUERY_CHECKOUT_USER_ID
- variables = {"token": str(checkout.token)}
+ variables = {"id": to_global_id_or_none(checkout)}
# when
response = api_client.post_graphql(query, variables)
@@ -3388,7 +3434,7 @@ def test_anonymous_client_cant_fetch_checkout_with_attached_user(
checkout.save()
query = QUERY_CHECKOUT_USER_ID
- variables = {"token": str(checkout.token)}
+ variables = {"id": to_global_id_or_none(checkout)}
# when
response = api_client.post_graphql(query, variables)
@@ -3407,7 +3453,7 @@ def test_authorized_access_to_checkout_user_as_customer(
checkout.user = customer_user
checkout.save()
- variables = {"token": str(checkout.token)}
+ variables = {"id": to_global_id_or_none(checkout)}
customer_user_id = graphene.Node.to_global_id("User", customer_user.id)
response = user_api_client.post_graphql(query, variables)
@@ -3426,7 +3472,7 @@ def test_authorized_access_to_checkout_user_as_staff(
checkout.user = customer_user
checkout.save()
- variables = {"token": str(checkout.token)}
+ variables = {"id": to_global_id_or_none(checkout)}
customer_user_id = graphene.Node.to_global_id("User", customer_user.id)
response = staff_api_client.post_graphql(
@@ -3450,7 +3496,7 @@ def test_authorized_access_to_checkout_user_as_staff_no_permission(
checkout.user = customer_user
checkout.save()
- variables = {"token": str(checkout.token)}
+ variables = {"id": to_global_id_or_none(checkout)}
response = staff_api_client.post_graphql(
query,
@@ -3462,8 +3508,8 @@ def test_authorized_access_to_checkout_user_as_staff_no_permission(
QUERY_CHECKOUT = """
- query getCheckout($token: UUID!) {
- checkout(token: $token) {
+ query getCheckout($id: ID) {
+ checkout(id: $id) {
token
}
}
@@ -3471,15 +3517,15 @@ QUERY_CHECKOUT = """
def test_query_anonymous_customer_checkout_as_anonymous_customer(api_client, checkout):
- variables = {"token": str(checkout.token), "channel": checkout.channel.slug}
+ variables = {"id": to_global_id_or_none(checkout), "channel": checkout.channel.slug}
response = api_client.post_graphql(QUERY_CHECKOUT, variables)
content = get_graphql_content(response)
assert content["data"]["checkout"]["token"] == str(checkout.token)
QUERY_CHECKOUT_CHANNEL_SLUG = """
- query getCheckout($token: UUID!) {
- checkout(token: $token) {
+ query getCheckout($id: ID) {
+ checkout(id: $id) {
token
channel {
slug
@@ -3495,7 +3541,7 @@ def test_query_anonymous_customer_channel_checkout_as_anonymous_customer(
query = QUERY_CHECKOUT_CHANNEL_SLUG
checkout_token = str(checkout.token)
channel_slug = checkout.channel.slug
- variables = {"token": checkout_token}
+ variables = {"id": to_global_id_or_none(checkout)}
response = api_client.post_graphql(query, variables)
content = get_graphql_content(response)
@@ -3511,7 +3557,7 @@ def test_query_anonymous_customer_channel_checkout_as_customer(
checkout_token = str(checkout.token)
channel_slug = checkout.channel.slug
variables = {
- "token": checkout_token,
+ "id": to_global_id_or_none(checkout),
}
response = user_api_client.post_graphql(query, variables)
@@ -3522,7 +3568,7 @@ def test_query_anonymous_customer_channel_checkout_as_customer(
def test_query_anonymous_customer_checkout_as_customer(user_api_client, checkout):
- variables = {"token": str(checkout.token)}
+ variables = {"id": to_global_id_or_none(checkout)}
response = user_api_client.post_graphql(QUERY_CHECKOUT, variables)
content = get_graphql_content(response)
assert content["data"]["checkout"]["token"] == str(checkout.token)
@@ -3531,7 +3577,7 @@ def test_query_anonymous_customer_checkout_as_customer(user_api_client, checkout
def test_query_anonymous_customer_checkout_as_staff_user(
staff_api_client, checkout, permission_manage_checkouts
):
- variables = {"token": str(checkout.token)}
+ variables = {"id": to_global_id_or_none(checkout)}
response = staff_api_client.post_graphql(
QUERY_CHECKOUT,
variables,
@@ -3545,7 +3591,7 @@ def test_query_anonymous_customer_checkout_as_staff_user(
def test_query_anonymous_customer_checkout_as_app(
app_api_client, checkout, permission_manage_checkouts
):
- variables = {"token": str(checkout.token)}
+ variables = {"id": to_global_id_or_none(checkout)}
response = app_api_client.post_graphql(
QUERY_CHECKOUT,
variables,
@@ -3561,7 +3607,7 @@ def test_query_customer_checkout_as_anonymous_customer(
):
checkout.user = customer_user
checkout.save(update_fields=["user"])
- variables = {"token": str(checkout.token)}
+ variables = {"id": to_global_id_or_none(checkout)}
response = api_client.post_graphql(QUERY_CHECKOUT, variables)
content = get_graphql_content(response)
assert not content["data"]["checkout"]
@@ -3570,7 +3616,7 @@ def test_query_customer_checkout_as_anonymous_customer(
def test_query_customer_checkout_as_customer(user_api_client, checkout, customer_user):
checkout.user = customer_user
checkout.save(update_fields=["user"])
- variables = {"token": str(checkout.token)}
+ variables = {"id": to_global_id_or_none(checkout)}
response = user_api_client.post_graphql(QUERY_CHECKOUT, variables)
content = get_graphql_content(response)
assert content["data"]["checkout"]["token"] == str(checkout.token)
@@ -3581,7 +3627,7 @@ def test_query_other_customer_checkout_as_customer(
):
checkout.user = staff_user
checkout.save(update_fields=["user"])
- variables = {"token": str(checkout.token)}
+ variables = {"id": to_global_id_or_none(checkout)}
response = user_api_client.post_graphql(QUERY_CHECKOUT, variables)
content = get_graphql_content(response)
assert not content["data"]["checkout"]
@@ -3592,7 +3638,7 @@ def test_query_customer_checkout_as_staff_user(
):
checkout.user = customer_user
checkout.save(update_fields=["user"])
- variables = {"token": str(checkout.token)}
+ variables = {"id": to_global_id_or_none(checkout)}
response = app_api_client.post_graphql(
QUERY_CHECKOUT,
variables,
@@ -3608,7 +3654,7 @@ def test_query_customer_checkout_as_app(
):
checkout.user = customer_user
checkout.save(update_fields=["user"])
- variables = {"token": str(checkout.token)}
+ variables = {"id": to_global_id_or_none(checkout)}
response = staff_api_client.post_graphql(
QUERY_CHECKOUT,
variables,
@@ -3619,8 +3665,9 @@ def test_query_customer_checkout_as_app(
assert content["data"]["checkout"]["token"] == str(checkout.token)
-def test_fetch_checkout_invalid_token(user_api_client, channel_USD):
- variables = {"token": str(uuid.uuid4())}
+def test_fetch_checkout_invalid_token(user_api_client, channel_USD, checkout):
+ variables = {"id": to_global_id_or_none(checkout)}
+ checkout.delete()
response = user_api_client.post_graphql(QUERY_CHECKOUT, variables)
content = get_graphql_content(response)
data = content["data"]["checkout"]
@@ -3628,8 +3675,8 @@ def test_fetch_checkout_invalid_token(user_api_client, channel_USD):
QUERY_CHECKOUT_PRICES = """
- query getCheckout($token: UUID!) {
- checkout(token: $token) {
+ query getCheckout($id: ID) {
+ checkout(id: $id) {
token,
totalPrice {
currency
@@ -3672,7 +3719,7 @@ QUERY_CHECKOUT_PRICES = """
def test_checkout_prices(user_api_client, checkout_with_item):
# given
query = QUERY_CHECKOUT_PRICES
- variables = {"token": str(checkout_with_item.token)}
+ variables = {"id": to_global_id_or_none(checkout_with_item)}
# when
response = user_api_client.post_graphql(query, variables)
@@ -3747,7 +3794,8 @@ def test_checkout_prices_checkout_with_custom_prices(
price_override = Decimal("20.00")
checkout_line.price_override = price_override
checkout_line.save(update_fields=["price_override"])
- variables = {"token": str(checkout_with_item.token)}
+
+ variables = {"id": to_global_id_or_none(checkout_with_item)}
# when
response = user_api_client.post_graphql(query, variables)
@@ -3790,7 +3838,7 @@ def test_checkout_prices_checkout_with_custom_prices(
def test_checkout_prices_with_sales(user_api_client, checkout_with_item, discount_info):
# given
query = QUERY_CHECKOUT_PRICES
- variables = {"token": str(checkout_with_item.token)}
+ variables = {"id": to_global_id_or_none(checkout_with_item)}
# when
response = user_api_client.post_graphql(query, variables)
@@ -3862,7 +3910,7 @@ def test_checkout_prices_with_specific_voucher(
# given
checkout = checkout_with_item_and_voucher_specific_products
query = QUERY_CHECKOUT_PRICES
- variables = {"token": str(checkout.token)}
+ variables = {"id": to_global_id_or_none(checkout)}
# when
response = user_api_client.post_graphql(query, variables)
@@ -3936,7 +3984,7 @@ def test_checkout_prices_with_voucher_once_per_order(
# given
checkout = checkout_with_item_and_voucher_once_per_order
query = QUERY_CHECKOUT_PRICES
- variables = {"token": str(checkout.token)}
+ variables = {"id": to_global_id_or_none(checkout)}
# when
response = user_api_client.post_graphql(query, variables)
@@ -4005,9 +4053,9 @@ def test_checkout_prices_with_voucher_once_per_order(
MUTATION_UPDATE_SHIPPING_METHOD = """
mutation checkoutShippingMethodUpdate(
- $token: UUID, $shippingMethodId: ID!){
+ $id: ID, $shippingMethodId: ID!){
checkoutShippingMethodUpdate(
- token: $token, shippingMethodId: $shippingMethodId) {
+ id: $id, shippingMethodId: $shippingMethodId) {
errors {
field
message
@@ -4022,9 +4070,9 @@ MUTATION_UPDATE_SHIPPING_METHOD = """
MUTATION_UPDATE_DELIVERY_METHOD = """
mutation checkoutDeliveryMethodUpdate(
- $token: UUID, $deliveryMethodId: ID) {
+ $id: ID, $deliveryMethodId: ID) {
checkoutDeliveryMethodUpdate(
- token: $token,
+ id: $id,
deliveryMethodId: $deliveryMethodId) {
checkout {
id
@@ -4075,7 +4123,7 @@ def test_checkout_shipping_method_update(
method_id = graphene.Node.to_global_id("ShippingMethod", shipping_method.id)
response = staff_api_client.post_graphql(
- query, {"token": checkout.token, "shippingMethodId": method_id}
+ query, {"id": to_global_id_or_none(checkout), "shippingMethodId": method_id}
)
data = get_graphql_content(response)["data"]["checkoutShippingMethodUpdate"]
checkout.refresh_from_db()
@@ -4145,7 +4193,7 @@ def test_checkout_shipping_method_update_external_shipping_method(
response = staff_api_client.post_graphql(
MUTATION_UPDATE_SHIPPING_METHOD,
- {"token": checkout_with_item.token, "shippingMethodId": method_id},
+ {"id": to_global_id_or_none(checkout_with_item), "shippingMethodId": method_id},
)
data = get_graphql_content(response)["data"]["checkoutShippingMethodUpdate"]
checkout.refresh_from_db()
@@ -4193,7 +4241,7 @@ def test_checkout_shipping_method_update_external_shipping_method_with_tax_plugi
# Set external shipping method for first time
response = staff_api_client.post_graphql(
MUTATION_UPDATE_SHIPPING_METHOD,
- {"token": checkout_with_item.token, "shippingMethodId": method_id},
+ {"id": to_global_id_or_none(checkout_with_item), "shippingMethodId": method_id},
)
data = get_graphql_content(response)["data"]["checkoutShippingMethodUpdate"]
assert not data["errors"]
@@ -4203,7 +4251,7 @@ def test_checkout_shipping_method_update_external_shipping_method_with_tax_plugi
# between Avalara and Webhooks plugins
response = staff_api_client.post_graphql(
MUTATION_UPDATE_SHIPPING_METHOD,
- {"token": checkout_with_item.token, "shippingMethodId": method_id},
+ {"id": to_global_id_or_none(checkout_with_item), "shippingMethodId": method_id},
)
data = get_graphql_content(response)["data"]["checkoutShippingMethodUpdate"]
assert not data["errors"]
@@ -4251,7 +4299,7 @@ def test_checkout_delivery_method_update(
method_id = graphene.Node.to_global_id(node_name, delivery_method.id)
response = api_client.post_graphql(
- query, {"token": checkout.token, "deliveryMethodId": method_id}
+ query, {"id": to_global_id_or_none(checkout), "deliveryMethodId": method_id}
)
data = get_graphql_content(response)["data"]["checkoutDeliveryMethodUpdate"]
checkout.refresh_from_db()
@@ -4311,7 +4359,7 @@ def test_checkout_delivery_method_update_external_shipping(
)
response = api_client.post_graphql(
- query, {"token": checkout.token, "deliveryMethodId": method_id}
+ query, {"id": to_global_id_or_none(checkout), "deliveryMethodId": method_id}
)
data = get_graphql_content(response)["data"]["checkoutDeliveryMethodUpdate"]
checkout.refresh_from_db()
@@ -4350,7 +4398,7 @@ def test_checkout_delivery_method_update_with_id_of_different_type_causes_and_er
response = api_client.post_graphql(
query,
{
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"deliveryMethodId": invalid_method_id,
},
)
@@ -4386,7 +4434,7 @@ def test_checkout_delivery_method_with_nonexistant_id_results_not_found(
response = api_client.post_graphql(
query,
{
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"deliveryMethodId": nonexistant_id,
},
)
@@ -4420,7 +4468,7 @@ def test_checkout_delivery_method_with_empty_fields_results_None(
response = api_client.post_graphql(
query,
{
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
},
)
data = get_graphql_content(response)["data"]["checkoutDeliveryMethodUpdate"]
@@ -4455,7 +4503,8 @@ def test_checkout_shipping_method_update_excluded_webhook(
# when
response = staff_api_client.post_graphql(
- query, {"token": checkout_with_item.token, "shippingMethodId": method_id}
+ query,
+ {"id": to_global_id_or_none(checkout_with_item), "shippingMethodId": method_id},
)
data = get_graphql_content(response)["data"]["checkoutShippingMethodUpdate"]
@@ -4487,7 +4536,8 @@ def test_checkout_shipping_method_update_excluded_postal_code(
method_id = graphene.Node.to_global_id("ShippingMethod", shipping_method.id)
response = staff_api_client.post_graphql(
- query, {"token": checkout_with_item.token, "shippingMethodId": method_id}
+ query,
+ {"id": to_global_id_or_none(checkout_with_item), "shippingMethodId": method_id},
)
data = get_graphql_content(response)["data"]["checkoutShippingMethodUpdate"]
@@ -4521,7 +4571,8 @@ def test_checkout_delivery_method_update_unavailable_variant(
method_id = graphene.Node.to_global_id("ShippingMethod", shipping_method.id)
response = staff_api_client.post_graphql(
- query, {"token": checkout_with_item.token, "shippingMethodId": method_id}
+ query,
+ {"id": to_global_id_or_none(checkout_with_item), "shippingMethodId": method_id},
)
data = get_graphql_content(response)["data"]["checkoutShippingMethodUpdate"]
@@ -4550,7 +4601,7 @@ def test_checkout_delivery_method_update_excluded_postal_code(
method_id = graphene.Node.to_global_id("ShippingMethod", shipping_method.id)
response = staff_api_client.post_graphql(
- query, {"token": checkout.token, "deliveryMethodId": method_id}
+ query, {"id": to_global_id_or_none(checkout), "deliveryMethodId": method_id}
)
data = get_graphql_content(response)["data"]["checkoutDeliveryMethodUpdate"]
@@ -4583,7 +4634,8 @@ def test_checkout_shipping_method_update_shipping_zone_without_channel(
method_id = graphene.Node.to_global_id("ShippingMethod", shipping_method.id)
response = staff_api_client.post_graphql(
- query, {"token": checkout_with_item.token, "shippingMethodId": method_id}
+ query,
+ {"id": to_global_id_or_none(checkout_with_item), "shippingMethodId": method_id},
)
data = get_graphql_content(response)["data"]["checkoutShippingMethodUpdate"]
@@ -4611,7 +4663,7 @@ def test_checkout_delivery_method_update_shipping_zone_without_channel(
method_id = graphene.Node.to_global_id("ShippingMethod", shipping_method.id)
response = api_client.post_graphql(
- query, {"token": checkout.token, "deliveryMethodId": method_id}
+ query, {"id": to_global_id_or_none(checkout), "deliveryMethodId": method_id}
)
data = get_graphql_content(response)["data"]["checkoutDeliveryMethodUpdate"]
@@ -4639,7 +4691,8 @@ def test_checkout_shipping_method_update_shipping_zone_with_channel(
method_id = graphene.Node.to_global_id("ShippingMethod", shipping_method.id)
response = staff_api_client.post_graphql(
- query, {"token": checkout_with_item.token, "shippingMethodId": method_id}
+ query,
+ {"id": to_global_id_or_none(checkout_with_item), "shippingMethodId": method_id},
)
data = get_graphql_content(response)["data"]["checkoutShippingMethodUpdate"]
@@ -4667,7 +4720,7 @@ def test_checkout_delivery_method_update_shipping_zone_with_channel(
method_id = graphene.Node.to_global_id("ShippingMethod", shipping_method.id)
response = staff_api_client.post_graphql(
- query, {"token": checkout.token, "deliveryMethodId": method_id}
+ query, {"id": to_global_id_or_none(checkout), "deliveryMethodId": method_id}
)
data = get_graphql_content(response)["data"]["checkoutDeliveryMethodUpdate"]
@@ -4893,8 +4946,8 @@ def test_clean_checkout_no_payment(checkout_with_item, shipping_method, address)
QUERY_CHECKOUT = """
- query getCheckout($token: UUID!){
- checkout(token: $token){
+ query getCheckout($id: ID){
+ checkout(id: $id){
id
token
lines{
@@ -4925,7 +4978,7 @@ def test_get_variant_data_from_checkout_line_variant_hidden_in_listings(
checkout = checkout_with_item
variant = checkout.lines.get().variant
variant.product.channel_listings.update(visible_in_listings=False)
- variables = {"token": checkout.token}
+ variables = {"id": to_global_id_or_none(checkout)}
# when
response = api_client.post_graphql(query, variables)
@@ -4950,7 +5003,7 @@ def test_get_checkout_with_vatlayer_set(
variant = checkout.lines.get().variant
variant.product.channel_listings.update(visible_in_listings=False)
- variables = {"token": checkout.token}
+ variables = {"id": to_global_id_or_none(checkout)}
# when
response = api_client.post_graphql(query, variables)
@@ -4961,8 +5014,8 @@ def test_get_checkout_with_vatlayer_set(
QUERY_CHECKOUT_TRANSACTIONS = """
- query getCheckout($token: UUID!) {
- checkout(token: $token) {
+ query getCheckout($id: ID) {
+ checkout(id: $id) {
transactions {
id
}
@@ -4982,7 +5035,7 @@ def test_checkout_transactions_missing_permission(api_client, checkout):
available_actions=[TransactionAction.CHARGE, TransactionAction.VOID],
)
query = QUERY_CHECKOUT_TRANSACTIONS
- variables = {"token": str(checkout.token)}
+ variables = {"id": to_global_id_or_none(checkout)}
# when
response = api_client.post_graphql(query, variables)
@@ -5004,7 +5057,7 @@ def test_checkout_transactions_with_manage_checkouts(
available_actions=[TransactionAction.CHARGE, TransactionAction.VOID],
)
query = QUERY_CHECKOUT_TRANSACTIONS
- variables = {"token": str(checkout.token)}
+ variables = {"id": to_global_id_or_none(checkout)}
# when
response = staff_api_client.post_graphql(
@@ -5033,7 +5086,7 @@ def test_checkout_transactions_with_handle_payments(
available_actions=[TransactionAction.CHARGE, TransactionAction.VOID],
)
query = QUERY_CHECKOUT_TRANSACTIONS
- variables = {"token": str(checkout.token)}
+ variables = {"id": to_global_id_or_none(checkout)}
# when
response = staff_api_client.post_graphql(
diff --git a/saleor/graphql/checkout/tests/test_checkout_billing_address_update.py b/saleor/graphql/checkout/tests/test_checkout_billing_address_update.py
index 6bebc2679b..b639f6cfd6 100644
--- a/saleor/graphql/checkout/tests/test_checkout_billing_address_update.py
+++ b/saleor/graphql/checkout/tests/test_checkout_billing_address_update.py
@@ -1,11 +1,12 @@
+from ...core.utils import to_global_id_or_none
from ...tests.utils import get_graphql_content
MUTATION_CHECKOUT_BILLING_ADDRESS_UPDATE = """
mutation checkoutBillingAddressUpdate(
- $checkoutId: ID, $token: UUID, $billingAddress: AddressInput!) {
+ $checkoutId: ID, $id: ID, $billingAddress: AddressInput!) {
checkoutBillingAddressUpdate(
+ id: $id,
checkoutId: $checkoutId,
- token: $token,
billingAddress: $billingAddress
){
checkout {
@@ -22,7 +23,7 @@ MUTATION_CHECKOUT_BILLING_ADDRESS_UPDATE = """
"""
-def test_checkout_billing_address_update_by_token(
+def test_checkout_billing_address_update_by_id(
user_api_client, checkout_with_item, graphql_address_data
):
checkout = checkout_with_item
@@ -31,7 +32,10 @@ def test_checkout_billing_address_update_by_token(
query = MUTATION_CHECKOUT_BILLING_ADDRESS_UPDATE
billing_address = graphql_address_data
- variables = {"token": checkout_with_item.token, "billingAddress": billing_address}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "billingAddress": billing_address,
+ }
response = user_api_client.post_graphql(query, variables)
content = get_graphql_content(response)
@@ -52,7 +56,7 @@ def test_checkout_billing_address_update_by_token(
assert checkout.billing_address.city == billing_address["city"].upper()
-def test_checkout_billing_address_update_by_token_without_required_fields(
+def test_checkout_billing_address_update_by_id_without_required_fields(
user_api_client, checkout_with_item, graphql_address_data
):
checkout = checkout_with_item
@@ -66,7 +70,10 @@ def test_checkout_billing_address_update_by_token_without_required_fields(
billing_address = graphql_address_data
- variables = {"token": checkout_with_item.token, "billingAddress": billing_address}
+ variables = {
+ "id": to_global_id_or_none(checkout_with_item),
+ "billingAddress": billing_address,
+ }
response = user_api_client.post_graphql(query, variables)
content = get_graphql_content(response)
@@ -86,7 +93,7 @@ def test_checkout_billing_address_update_by_token_without_required_fields(
]
-def test_checkout_billing_address_update_by_token_without_street_address_2(
+def test_checkout_billing_address_update_by_id_without_street_address_2(
user_api_client, checkout_with_item, graphql_address_data
):
checkout = checkout_with_item
@@ -98,7 +105,10 @@ def test_checkout_billing_address_update_by_token_without_street_address_2(
billing_address = graphql_address_data
- variables = {"token": checkout_with_item.token, "billingAddress": billing_address}
+ variables = {
+ "id": to_global_id_or_none(checkout_with_item),
+ "billingAddress": billing_address,
+ }
response = user_api_client.post_graphql(query, variables)
content = get_graphql_content(response)
diff --git a/saleor/graphql/checkout/tests/test_checkout_complete.py b/saleor/graphql/checkout/tests/test_checkout_complete.py
index 659c647218..aea50f0a16 100644
--- a/saleor/graphql/checkout/tests/test_checkout_complete.py
+++ b/saleor/graphql/checkout/tests/test_checkout_complete.py
@@ -1,4 +1,3 @@
-import uuid
from datetime import datetime, timedelta
from decimal import Decimal
from unittest.mock import ANY, patch
@@ -28,11 +27,12 @@ from ....plugins.manager import PluginsManager, get_plugins_manager
from ....tests.utils import flush_post_commit_hooks
from ....warehouse.models import Reservation, Stock, WarehouseClickAndCollectOption
from ....warehouse.tests.utils import get_available_quantity_for_stock
+from ...core.utils import to_global_id_or_none
from ...tests.utils import get_graphql_content
MUTATION_CHECKOUT_COMPLETE = """
- mutation checkoutComplete($token: UUID, $redirectUrl: String) {
- checkoutComplete(token: $token, redirectUrl: $redirectUrl) {
+ mutation checkoutComplete($id: ID, $redirectUrl: String) {
+ checkoutComplete(id: $id, redirectUrl: $redirectUrl) {
order {
id
token
@@ -93,7 +93,10 @@ def test_checkout_complete_unconfirmed_order_already_exists(
order_with_lines.status = OrderStatus.UNCONFIRMED
order_with_lines.checkout_token = checkout.pk
order_with_lines.save()
- variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "redirectUrl": "https://www.example.com",
+ }
checkout.delete()
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
@@ -118,7 +121,10 @@ def test_checkout_complete_order_already_exists(
orders_count = Order.objects.count()
order_with_lines.checkout_token = checkout.pk
order_with_lines.save()
- variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "redirectUrl": "https://www.example.com",
+ }
checkout.delete()
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
@@ -146,7 +152,10 @@ def test_checkout_complete_with_inactive_channel_order_already_exists(
channel.save()
order_with_lines.save()
- variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "redirectUrl": "https://www.example.com",
+ }
checkout.delete()
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
@@ -197,7 +206,10 @@ def test_checkout_complete_with_inactive_channel(
payment.save()
assert not payment.transactions.exists()
- variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "redirectUrl": "https://www.example.com",
+ }
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -252,7 +264,7 @@ def test_checkout_complete(
orders_count = Order.objects.count()
redirect_url = "https://www.example.com"
- variables = {"token": checkout.token, "redirectUrl": redirect_url}
+ variables = {"id": to_global_id_or_none(checkout), "redirectUrl": redirect_url}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -334,7 +346,7 @@ def test_checkout_complete_by_app(
payment.save()
redirect_url = "https://www.example.com"
- variables = {"token": checkout.token, "redirectUrl": redirect_url}
+ variables = {"id": to_global_id_or_none(checkout), "redirectUrl": redirect_url}
response = app_api_client.post_graphql(
MUTATION_CHECKOUT_COMPLETE,
@@ -398,7 +410,7 @@ def test_checkout_complete_by_app_with_missing_permission(
payment.save()
redirect_url = "https://www.example.com"
- variables = {"token": checkout.token, "redirectUrl": redirect_url}
+ variables = {"id": to_global_id_or_none(checkout), "redirectUrl": redirect_url}
response = app_api_client.post_graphql(
MUTATION_CHECKOUT_COMPLETE,
@@ -470,7 +482,7 @@ def test_checkout_complete_gift_card_bought(
orders_count = Order.objects.count()
redirect_url = "https://www.example.com"
- variables = {"token": checkout.token, "redirectUrl": redirect_url}
+ variables = {"id": to_global_id_or_none(checkout), "redirectUrl": redirect_url}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -507,7 +519,7 @@ def test_checkout_complete_no_checkout_email(
checkout.save(update_fields=["email"])
redirect_url = "https://www.example.com"
- variables = {"token": checkout.token, "redirectUrl": redirect_url}
+ variables = {"id": to_global_id_or_none(checkout), "redirectUrl": redirect_url}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -555,7 +567,7 @@ def test_checkout_complete_with_variant_without_sku(
orders_count = Order.objects.count()
redirect_url = "https://www.example.com"
- variables = {"token": checkout.token, "redirectUrl": redirect_url}
+ variables = {"id": to_global_id_or_none(checkout), "redirectUrl": redirect_url}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -597,7 +609,7 @@ def test_checkout_complete_with_variant_without_price(
variant_id = graphene.Node.to_global_id("ProductVariant", checkout_line_variant.pk)
redirect_url = "https://www.example.com"
- variables = {"token": checkout.token, "redirectUrl": redirect_url}
+ variables = {"id": to_global_id_or_none(checkout), "redirectUrl": redirect_url}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -622,7 +634,7 @@ def test_checkout_complete_requires_confirmation(
payment.save()
variables = {
- "token": checkout_ready_to_complete.token,
+ "id": to_global_id_or_none(checkout_ready_to_complete),
"redirectUrl": "https://www.example.com",
}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
@@ -678,7 +690,10 @@ def test_checkout_with_voucher_complete(
assert not payment.transactions.exists()
orders_count = Order.objects.count()
- variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "redirectUrl": "https://www.example.com",
+ }
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -741,7 +756,10 @@ def test_checkout_with_voucher_not_increase_uses_on_preprocess_order_creation_fa
payment.save()
assert not payment.transactions.exists()
- variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "redirectUrl": "https://www.example.com",
+ }
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -793,7 +811,10 @@ def test_checkout_complete_without_inventory_tracking(
assert not payment.transactions.exists()
orders_count = Order.objects.count()
- variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "redirectUrl": "https://www.example.com",
+ }
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -861,7 +882,7 @@ def test_checkout_complete_checkout_without_lines(
assert not payment.transactions.exists()
redirect_url = "https://www.example.com"
- variables = {"token": checkout.token, "redirectUrl": redirect_url}
+ variables = {"id": to_global_id_or_none(checkout), "redirectUrl": redirect_url}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -916,7 +937,10 @@ def test_checkout_complete_error_in_gateway_response_for_dummy_credit_card(
assert not payment.transactions.exists()
orders_count = Order.objects.count()
- variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "redirectUrl": "https://www.example.com",
+ }
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -988,7 +1012,10 @@ def test_checkout_complete_does_not_delete_checkout_after_unsuccessful_payment(
assert not payment.transactions.exists()
orders_count = Order.objects.count()
- variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "redirectUrl": "https://www.example.com",
+ }
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
get_graphql_content(response)
@@ -1010,15 +1037,15 @@ def test_checkout_complete_does_not_delete_checkout_after_unsuccessful_payment(
mocked_process_payment.assert_called_once()
-def test_checkout_complete_invalid_token(user_api_client):
- token = uuid.uuid4()
- variables = {"token": token, "redirectUrl": "https://www.example.com"}
+def test_checkout_complete_invalid_id(user_api_client):
+ id = "12345"
+ variables = {"id": id, "redirectUrl": "https://www.example.com"}
orders_count = Order.objects.count()
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
data = content["data"]["checkoutComplete"]
- assert data["errors"][0]["message"] == f"Couldn't resolve to a node: {token}."
- assert data["errors"][0]["field"] == "token"
+ assert data["errors"][0]["message"] == f"Couldn't resolve id: {id}."
+ assert data["errors"][0]["field"] == "id"
assert orders_count == Order.objects.count()
@@ -1030,7 +1057,10 @@ def test_checkout_complete_no_payment(
checkout.shipping_method = shipping_method
checkout.billing_address = address
checkout.save()
- variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "redirectUrl": "https://www.example.com",
+ }
orders_count = Order.objects.count()
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -1072,7 +1102,10 @@ def test_checkout_complete_confirmation_needed(
payment.checkout = checkout
payment.save()
- variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "redirectUrl": "https://www.example.com",
+ }
orders_count = Order.objects.count()
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
@@ -1127,7 +1160,10 @@ def test_checkout_confirm(
orders_count = Order.objects.count()
- variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "redirectUrl": "https://www.example.com",
+ }
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
data = content["data"]["checkoutComplete"]
@@ -1169,7 +1205,10 @@ def test_checkout_complete_insufficient_stock(
payment.currency = total.gross.currency
payment.checkout = checkout
payment.save()
- variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "redirectUrl": "https://www.example.com",
+ }
orders_count = Order.objects.count()
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -1216,7 +1255,10 @@ def test_checkout_complete_insufficient_stock_payment_refunded(
payment.charge_status = ChargeStatus.FULLY_CHARGED
payment.save()
- variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "redirectUrl": "https://www.example.com",
+ }
orders_count = Order.objects.count()
# when
@@ -1272,7 +1314,10 @@ def test_checkout_complete_insufficient_stock_payment_voided(
payment.charge_status = ChargeStatus.NOT_CHARGED
payment.save()
- variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "redirectUrl": "https://www.example.com",
+ }
orders_count = Order.objects.count()
# when
@@ -1337,7 +1382,10 @@ def test_checkout_complete_insufficient_stock_reserved_by_other_user(
payment.currency = total.gross.currency
payment.checkout = checkout
payment.save()
- variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "redirectUrl": "https://www.example.com",
+ }
orders_count = Order.objects.count()
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -1389,7 +1437,10 @@ def test_checkout_complete_own_reservation(
payment.checkout = checkout
payment.save()
- variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "redirectUrl": "https://www.example.com",
+ }
orders_count = Order.objects.count()
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -1453,7 +1504,7 @@ def test_checkout_complete_without_redirect_url(
assert not payment.transactions.exists()
orders_count = Order.objects.count()
- variables = {"token": checkout.token}
+ variables = {"id": to_global_id_or_none(checkout)}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -1520,7 +1571,10 @@ def test_checkout_complete_payment_payment_total_different_than_checkout(
assert not payment.transactions.exists()
orders_count = Order.objects.count()
- variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "redirectUrl": "https://www.example.com",
+ }
# when
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
@@ -1544,10 +1598,12 @@ def test_order_already_exists(
checkout = checkout_ready_to_complete
order_with_lines.checkout_token = checkout.token
order_with_lines.save()
- token = checkout.token
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "redirectUrl": "https://www.example.com",
+ }
checkout.delete()
- variables = {"token": token, "redirectUrl": "https://www.example.com"}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -1586,7 +1642,10 @@ def test_create_order_raises_insufficient_stock(
payment.checkout = checkout
payment.save()
- variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "redirectUrl": "https://www.example.com",
+ }
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -1605,7 +1664,10 @@ def test_checkout_complete_with_digital(
order_count = Order.objects.count()
checkout = checkout_with_digital_item
- variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "redirectUrl": "https://www.example.com",
+ }
# Set a billing address
checkout.billing_address = address
@@ -1686,7 +1748,10 @@ def test_checkout_complete_0_total_value(
assert not payment.transactions.exists()
orders_count = Order.objects.count()
- variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "redirectUrl": "https://www.example.com",
+ }
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -1723,7 +1788,10 @@ def test_complete_checkout_for_click_and_collect(
):
order_count = Order.objects.count()
checkout = checkout_with_item_for_cc
- variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "redirectUrl": "https://www.example.com",
+ }
checkout.billing_address = address
checkout.collection_point = warehouse_for_cc
@@ -1773,7 +1841,10 @@ def test_complete_checkout_raises_error_for_local_stock(
checkout_line.quantity = quantity_available + 1
checkout_line.save()
- variables = {"token": checkout.token, "rediirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "rediirectUrl": "https://www.example.com",
+ }
checkout.collection_point = warehouse_for_cc
checkout.billing_address = address
@@ -1826,7 +1897,10 @@ def test_comp_checkout_builds_order_for_all_warehouse_even_if_not_available_loca
)
warehouse_for_cc.save()
- variables = {"token": checkout.token, "rediirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "rediirectUrl": "https://www.example.com",
+ }
checkout.collection_point = warehouse_for_cc
checkout.save(update_fields=["collection_point"])
@@ -1876,7 +1950,10 @@ def test_checkout_complete_raises_InsufficientStock_when_quantity_above_stock_su
)
warehouse_for_cc.save()
- variables = {"token": checkout.token, "rediirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "rediirectUrl": "https://www.example.com",
+ }
checkout.collection_point = warehouse_for_cc
checkout.billing_address = address
@@ -1914,7 +1991,10 @@ def test_checkout_complete_raises_InvalidShippingMethod_when_warehouse_disabled(
):
initial_order_count = Order.objects.count()
checkout = checkout_with_item_for_cc
- variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "redirectUrl": "https://www.example.com",
+ }
checkout.billing_address = address
checkout.collection_point = warehouse_for_cc
@@ -1994,7 +2074,10 @@ def test_checkout_complete_with_preorder_variant(
assert not payment.transactions.exists()
orders_count = Order.objects.count()
- variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "redirectUrl": "https://www.example.com",
+ }
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -2044,7 +2127,10 @@ def test_checkout_complete_with_click_collect_preorder_fails_for_disabled_wareho
):
initial_order_count = Order.objects.count()
checkout = checkout_with_items_for_cc
- variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "redirectUrl": "https://www.example.com",
+ }
checkout.billing_address = address
checkout.collection_point = warehouse_for_cc
@@ -2142,7 +2228,7 @@ def test_checkout_complete_variant_channel_listing_does_not_exist(
orders_count = Order.objects.count()
redirect_url = "https://www.example.com"
- variables = {"token": checkout.token, "redirectUrl": redirect_url}
+ variables = {"id": to_global_id_or_none(checkout), "redirectUrl": redirect_url}
# when
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
@@ -2206,7 +2292,7 @@ def test_checkout_complete_variant_channel_listing_no_price(
orders_count = Order.objects.count()
redirect_url = "https://www.example.com"
- variables = {"token": checkout.token, "redirectUrl": redirect_url}
+ variables = {"id": to_global_id_or_none(checkout), "redirectUrl": redirect_url}
# when
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
@@ -2266,7 +2352,7 @@ def test_checkout_complete_product_channel_listing_does_not_exist(
orders_count = Order.objects.count()
redirect_url = "https://www.example.com"
- variables = {"token": checkout.token, "redirectUrl": redirect_url}
+ variables = {"id": to_global_id_or_none(checkout), "redirectUrl": redirect_url}
# when
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
@@ -2332,7 +2418,7 @@ def test_checkout_complete_product_channel_listing_not_available_for_purchase(
orders_count = Order.objects.count()
redirect_url = "https://www.example.com"
- variables = {"token": checkout.token, "redirectUrl": redirect_url}
+ variables = {"id": to_global_id_or_none(checkout), "redirectUrl": redirect_url}
# when
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
@@ -2377,7 +2463,10 @@ def test_checkout_complete_0_total_value_no_payment(
manager=manager, checkout_info=checkout_info, lines=lines, address=address
)
orders_count = Order.objects.count()
- variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "redirectUrl": "https://www.example.com",
+ }
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -2435,7 +2524,10 @@ def test_checkout_complete_0_total_value_from_voucher(
manager=manager, checkout_info=checkout_info, lines=lines, address=address
)
orders_count = Order.objects.count()
- variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "redirectUrl": "https://www.example.com",
+ }
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
@@ -2490,7 +2582,10 @@ def test_checkout_complete_0_total_value_from_giftcard(
manager=manager, checkout_info=checkout_info, lines=lines, address=address
)
orders_count = Order.objects.count()
- variables = {"token": checkout.token, "redirectUrl": "https://www.example.com"}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "redirectUrl": "https://www.example.com",
+ }
response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)
content = get_graphql_content(response)
data = content["data"]["checkoutComplete"]
diff --git a/saleor/graphql/checkout/tests/test_checkout_digital.py b/saleor/graphql/checkout/tests/test_checkout_digital.py
index 59dbcbe758..1a44349c61 100644
--- a/saleor/graphql/checkout/tests/test_checkout_digital.py
+++ b/saleor/graphql/checkout/tests/test_checkout_digital.py
@@ -8,6 +8,7 @@ from ....checkout.fetch import fetch_checkout_info, fetch_checkout_lines
from ....checkout.models import Checkout
from ....checkout.utils import add_variant_to_checkout
from ....plugins.manager import get_plugins_manager
+from ...core.utils import to_global_id_or_none
from ...tests.utils import get_graphql_content
from ..mutations.utils import update_checkout_shipping_method_if_invalid
from .test_checkout import (
@@ -69,8 +70,8 @@ def test_checkout_has_no_available_shipping_methods(
"""Test no shipping method are available on digital orders."""
query = """
- query getCheckout($token: UUID!) {
- checkout(token: $token) {
+ query getCheckout($id: ID!) {
+ checkout(id: $id) {
availableShippingMethods {
name
price {
@@ -87,7 +88,7 @@ def test_checkout_has_no_available_shipping_methods(
checkout.shipping_address = address
checkout.save(update_fields=["shipping_address"])
- variables = {"token": checkout.token}
+ variables = {"id": to_global_id_or_none(checkout)}
response = api_client.post_graphql(query, variables)
content = get_graphql_content(response)
data = content["data"]["checkout"]
@@ -101,7 +102,10 @@ def test_checkout_update_shipping_address(
"""Test updating the shipping address of a digital order throws an error."""
checkout = checkout_with_digital_item
- variables = {"token": checkout.token, "shippingAddress": graphql_address_data}
+ variables = {
+ "id": to_global_id_or_none(checkout),
+ "shippingAddress": graphql_address_data,
+ }
response = api_client.post_graphql(
MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE, variables
@@ -129,7 +133,7 @@ def test_checkout_update_shipping_method(
checkout = checkout_with_digital_item
method_id = graphene.Node.to_global_id("ShippingMethod", shipping_method.pk)
- variables = {"token": checkout.token, "shippingMethodId": method_id}
+ variables = {"id": to_global_id_or_none(checkout), "shippingMethodId": method_id}
# Put a shipping address, to ensure it is still handled properly
checkout.shipping_address = address
@@ -186,7 +190,7 @@ def test_checkout_lines_update_remove_shipping_if_removed_product_with_shipping(
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 0}],
}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
@@ -213,7 +217,7 @@ def test_checkout_line_delete_remove_shipping_if_removed_product_with_shipping(
line_id = graphene.Node.to_global_id("CheckoutLine", line.pk)
- variables = {"token": checkout.token, "lineId": line_id}
+ variables = {"id": to_global_id_or_none(checkout), "lineId": line_id}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINE_DELETE, variables)
content = get_graphql_content(response)
diff --git a/saleor/graphql/checkout/tests/test_checkout_language_code_update.py b/saleor/graphql/checkout/tests/test_checkout_language_code_update.py
index 4d28f3d0f5..cb7e4fce08 100644
--- a/saleor/graphql/checkout/tests/test_checkout_language_code_update.py
+++ b/saleor/graphql/checkout/tests/test_checkout_language_code_update.py
@@ -1,8 +1,9 @@
+from saleor.graphql.core.utils import to_global_id_or_none
from saleor.graphql.tests.utils import get_graphql_content
MUTATION_CHECKOUT_UPDATE_LANGUAGE_CODE = """
-mutation checkoutLanguageCodeUpdate($token: UUID, $languageCode: LanguageCodeEnum!){
- checkoutLanguageCodeUpdate(token: $token, languageCode: $languageCode){
+mutation checkoutLanguageCodeUpdate($id: ID, $languageCode: LanguageCodeEnum!){
+ checkoutLanguageCodeUpdate(id: $id, languageCode: $languageCode){
checkout{
id
languageCode
@@ -24,7 +25,7 @@ def test_checkout_update_language_code(
language_code = "PL"
checkout = checkout_with_gift_card
previous_last_change = checkout.last_change
- variables = {"token": checkout.token, "languageCode": language_code}
+ variables = {"id": to_global_id_or_none(checkout), "languageCode": language_code}
response = user_api_client.post_graphql(
MUTATION_CHECKOUT_UPDATE_LANGUAGE_CODE, variables
diff --git a/saleor/graphql/checkout/tests/test_checkout_lines.py b/saleor/graphql/checkout/tests/test_checkout_lines.py
index c899b8c16b..dcc275cca7 100644
--- a/saleor/graphql/checkout/tests/test_checkout_lines.py
+++ b/saleor/graphql/checkout/tests/test_checkout_lines.py
@@ -1,5 +1,4 @@
import datetime
-import uuid
from decimal import Decimal
from unittest import mock
@@ -17,6 +16,7 @@ from ....product.models import ProductChannelListing
from ....warehouse import WarehouseClickAndCollectOption
from ....warehouse.models import Reservation, Stock
from ....warehouse.tests.utils import get_available_quantity_for_stock
+from ...core.utils import to_global_id_or_none
from ...tests.utils import assert_no_permission, get_graphql_content
from ..mutations.utils import (
CheckoutLineData,
@@ -26,8 +26,8 @@ from ..mutations.utils import (
MUTATION_CHECKOUT_LINES_ADD = """
mutation checkoutLinesAdd(
- $token: UUID, $lines: [CheckoutLineInput!]!) {
- checkoutLinesAdd(token: $token, lines: $lines) {
+ $id: ID, $lines: [CheckoutLineInput!]!) {
+ checkoutLinesAdd(id: $id, lines: $lines) {
checkout {
token
quantity
@@ -65,7 +65,7 @@ def test_checkout_lines_add(
previous_last_change = checkout.last_change
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 1}],
"channelSlug": checkout.channel.slug,
}
@@ -99,7 +99,7 @@ def test_checkout_lines_add_with_reservations(
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 1}],
"channelSlug": checkout.channel.slug,
}
@@ -134,7 +134,7 @@ def test_checkout_lines_add_updates_reservation(
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 1}],
"channelSlug": checkout.channel.slug,
}
@@ -182,7 +182,7 @@ def test_checkout_lines_add_new_variant_updates_other_lines_reservations_expirat
variant_other_id = graphene.Node.to_global_id("ProductVariant", variant_other.pk)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_other_id, "quantity": 3}],
"channelSlug": checkout.channel.slug,
}
@@ -223,7 +223,7 @@ def test_checkout_lines_add_existing_variant(user_api_client, checkout_with_item
previous_last_change = checkout.last_change
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 7}],
"channelSlug": checkout.channel.slug,
}
@@ -245,7 +245,7 @@ def test_checkout_lines_add_custom_price(
price = Decimal("13.11")
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 1, "price": price}],
"channelSlug": checkout.channel.slug,
}
@@ -273,7 +273,7 @@ def test_checkout_lines_add_existing_variant_with_custom_price(
price = Decimal("13.11")
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 7, "price": price}],
"channelSlug": checkout.channel.slug,
}
@@ -303,7 +303,7 @@ def test_checkout_lines_add_existing_variant_override_previous_custom_price(
price = Decimal("13.11")
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 7, "price": price}],
"channelSlug": checkout.channel.slug,
}
@@ -327,7 +327,7 @@ def test_checkout_lines_add_custom_price_app_no_perm(app_api_client, checkout, s
price = Decimal("13.11")
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 1, "price": price}],
"channelSlug": checkout.channel.slug,
}
@@ -343,7 +343,7 @@ def test_checkout_lines_add_custom_price_permission_denied_for_staff_user(
price = Decimal("13.11")
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 1, "price": price}],
"channelSlug": checkout.channel.slug,
}
@@ -364,7 +364,7 @@ def test_checkout_lines_add_existing_variant_over_allowed_stock(
current_stock = line.variant.stocks.first()
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": current_stock.quantity - 1}],
"channelSlug": checkout.channel.slug,
}
@@ -387,7 +387,7 @@ def test_checkout_lines_add_with_unavailable_variant(
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 1}],
"channelSlug": checkout.channel.slug,
}
@@ -407,7 +407,7 @@ def test_checkout_lines_add_with_insufficient_stock(
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 49}],
"channelSlug": checkout.channel.slug,
}
@@ -443,7 +443,7 @@ def test_checkout_lines_add_with_reserved_insufficient_stock(
)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 2}],
"channelSlug": checkout.channel.slug,
}
@@ -475,7 +475,7 @@ def test_checkout_lines_for_click_and_collect_insufficient_stock(
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 42}],
"channelSlug": checkout.channel.slug,
}
@@ -496,7 +496,7 @@ def test_checkout_lines_add_with_zero_quantity(
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 0}],
"channelSlug": checkout.channel.slug,
}
@@ -518,7 +518,7 @@ def test_checkout_lines_add_no_channel_shipping_zones(
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 1}],
"channelSlug": checkout.channel.slug,
}
@@ -544,7 +544,7 @@ def test_checkout_lines_add_with_unpublished_product(
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
variables = {
- "token": checkout_with_item.token,
+ "id": to_global_id_or_none(checkout_with_item),
"lines": [{"variantId": variant_id, "quantity": 1}],
"channelSlug": checkout_with_item.channel.slug,
}
@@ -567,7 +567,7 @@ def test_checkout_lines_add_with_unavailable_for_purchase_product(
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
variables = {
- "token": checkout_with_item.token,
+ "id": to_global_id_or_none(checkout_with_item),
"lines": [{"variantId": variant_id, "quantity": 1}],
}
@@ -596,7 +596,7 @@ def test_checkout_lines_add_with_available_for_purchase_from_tomorrow_product(
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
variables = {
- "token": checkout_with_item.token,
+ "id": to_global_id_or_none(checkout_with_item),
"lines": [{"variantId": variant_id, "quantity": 1}],
}
@@ -616,7 +616,7 @@ def test_checkout_lines_add_too_many(user_api_client, checkout_with_item, stock)
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
variables = {
- "token": checkout_with_item.token,
+ "id": to_global_id_or_none(checkout_with_item),
"lines": [{"variantId": variant_id, "quantity": 51}],
"channelSlug": checkout_with_item.channel.slug,
}
@@ -647,7 +647,7 @@ def test_checkout_lines_add_too_many_after_two_trials(
variant.save(update_fields=["is_preorder", "preorder_end_date"])
variables = {
- "token": checkout_with_item.token,
+ "id": to_global_id_or_none(checkout_with_item),
"lines": [{"variantId": variant_id, "quantity": 26}],
"channelSlug": checkout_with_item.channel.slug,
}
@@ -674,7 +674,7 @@ def test_checkout_lines_add_empty_checkout(user_api_client, checkout, stock):
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 1}],
}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
@@ -694,7 +694,7 @@ def test_checkout_lines_add_variant_without_inventory_tracking(
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 1}],
}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
@@ -712,7 +712,7 @@ def test_checkout_lines_add_check_lines_quantity(user_api_client, checkout, stoc
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 16}],
}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)
@@ -730,7 +730,7 @@ def test_checkout_lines_invalid_variant_id(user_api_client, checkout, stock):
invalid_variant_id = "InvalidId"
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [
{"variantId": variant_id, "quantity": 1},
{"variantId": invalid_variant_id, "quantity": 3},
@@ -746,8 +746,8 @@ def test_checkout_lines_invalid_variant_id(user_api_client, checkout, stock):
MUTATION_CHECKOUT_LINES_UPDATE = """
mutation checkoutLinesUpdate(
- $token: UUID, $lines: [CheckoutLineUpdateInput!]!) {
- checkoutLinesUpdate(token: $token, lines: $lines) {
+ $id: ID, $lines: [CheckoutLineUpdateInput!]!) {
+ checkoutLinesUpdate(id: $id, lines: $lines) {
checkout {
id
token
@@ -790,7 +790,7 @@ def test_checkout_lines_update(
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
variables = {
- "token": checkout_with_item.token,
+ "id": to_global_id_or_none(checkout_with_item),
"lines": [{"variantId": variant_id, "quantity": 1}],
}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
@@ -834,7 +834,7 @@ def test_checkout_lines_update_with_new_reservations(
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 1}],
}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
@@ -886,7 +886,7 @@ def test_checkout_lines_update_against_reserved_stock(
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 5}],
}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
@@ -939,7 +939,7 @@ def test_checkout_lines_update_other_lines_reservations_expirations(
variant_other_id = graphene.Node.to_global_id("ProductVariant", variant_other.pk)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_other_id, "quantity": 3}],
}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
@@ -986,7 +986,7 @@ def test_checkout_lines_update_quantity_and_custom_price(
price = Decimal("22.22")
variables = {
- "token": checkout_with_item.token,
+ "id": to_global_id_or_none(checkout_with_item),
"lines": [{"variantId": variant_id, "quantity": 1, "price": price}],
}
response = app_api_client.post_graphql(
@@ -1023,7 +1023,7 @@ def test_checkout_lines_update_custom_price(
price = Decimal("22.22")
variables = {
- "token": checkout_with_item.token,
+ "id": to_global_id_or_none(checkout_with_item),
"lines": [{"variantId": variant_id, "price": price}],
}
response = app_api_client.post_graphql(
@@ -1062,7 +1062,7 @@ def test_checkout_lines_update_with_custom_price_override_existing_price(
price = Decimal("22.10")
variables = {
- "token": checkout_with_item.token,
+ "id": to_global_id_or_none(checkout_with_item),
"lines": [{"variantId": variant_id, "quantity": 1, "price": price}],
}
response = app_api_client.post_graphql(
@@ -1100,7 +1100,7 @@ def test_checkout_lines_update_clear_custom_price(
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
variables = {
- "token": checkout_with_item.token,
+ "id": to_global_id_or_none(checkout_with_item),
"lines": [{"variantId": variant_id, "quantity": 1, "price": None}],
}
response = app_api_client.post_graphql(
@@ -1141,7 +1141,7 @@ def test_checkout_lines_update_set_quantity_to_0_then_update_customer_price(
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
variables = {
- "token": checkout_with_item.token,
+ "id": to_global_id_or_none(checkout_with_item),
"lines": [
{"variantId": variant_id, "quantity": 0},
{"variantId": variant_id, "price": 10},
@@ -1177,7 +1177,7 @@ def test_checkout_lines_update_with_custom_price_by_app_no_perm(
price = Decimal("22.22")
variables = {
- "token": checkout_with_item.token,
+ "id": to_global_id_or_none(checkout_with_item),
"lines": [{"variantId": variant_id, "quantity": 1, "price": price}],
}
response = app_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
@@ -1199,7 +1199,7 @@ def test_checkout_lines_update_with_custom_price_raise_permission_denied_for_sta
price = Decimal("22.22")
variables = {
- "token": checkout_with_item.token,
+ "id": to_global_id_or_none(checkout_with_item),
"lines": [{"variantId": variant_id, "quantity": 1, "price": price}],
}
response = staff_api_client.post_graphql(
@@ -1224,7 +1224,7 @@ def test_checkout_lines_update_no_quantity_provided(
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
variables = {
- "token": checkout_with_item.token,
+ "id": to_global_id_or_none(checkout_with_item),
"lines": [{"variantId": variant_id}],
}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
@@ -1253,7 +1253,7 @@ def test_checkout_lines_update_with_unavailable_variant(
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 1}],
}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
@@ -1280,7 +1280,7 @@ def test_checkout_lines_update_channel_without_shipping_zones(
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 1}],
}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
@@ -1303,7 +1303,7 @@ def test_checkout_lines_update_variant_quantity_over_avability_stock(
line.save()
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": current_stock.quantity - 2}],
"channelSlug": checkout.channel.slug,
}
@@ -1325,7 +1325,7 @@ def test_checkout_lines_delete_with_by_zero_quantity_when_variant_out_of_stock(
previous_last_change = checkout.last_change
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 0}],
"channelSlug": checkout.channel.slug,
}
@@ -1355,7 +1355,7 @@ def test_checkout_line_delete_by_zero_quantity(
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 0}],
}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
@@ -1391,7 +1391,7 @@ def test_checkout_line_delete_by_zero_quantity_when_variant_unavailable_for_purc
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 0}],
}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
@@ -1427,7 +1427,7 @@ def test_checkout_line_update_by_zero_quantity_dont_create_new_lines(
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 0}],
}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
@@ -1458,7 +1458,7 @@ def test_checkout_lines_update_with_unpublished_product(
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 1}],
}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
@@ -1469,11 +1469,11 @@ def test_checkout_lines_update_with_unpublished_product(
def test_checkout_lines_update_invalid_checkout_id(user_api_client):
- variables = {"token": uuid.uuid4(), "lines": []}
+ variables = {"id": "1234", "lines": []}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
content = get_graphql_content(response)
data = content["data"]["checkoutLinesUpdate"]
- assert data["errors"][0]["field"] == "token"
+ assert data["errors"][0]["field"] == "id"
def test_checkout_lines_update_check_lines_quantity(
@@ -1486,7 +1486,7 @@ def test_checkout_lines_update_check_lines_quantity(
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 11}],
}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
@@ -1509,7 +1509,7 @@ def test_checkout_lines_update_with_chosen_shipping(
variant = stock.product_variant
variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"lines": [{"variantId": variant_id, "quantity": 1}],
}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
@@ -1523,8 +1523,8 @@ def test_checkout_lines_update_with_chosen_shipping(
MUTATION_CHECKOUT_LINE_DELETE = """
- mutation checkoutLineDelete($token: UUID, $lineId: ID!) {
- checkoutLineDelete(token: $token, lineId: $lineId) {
+ mutation checkoutLineDelete($id: ID, $lineId: ID!) {
+ checkoutLineDelete(id: $id, lineId: $lineId) {
checkout {
token
lines {
@@ -1564,7 +1564,7 @@ def test_checkout_line_delete(
line_id = graphene.Node.to_global_id("CheckoutLine", line.pk)
- variables = {"token": checkout.token, "lineId": line_id}
+ variables = {"id": to_global_id_or_none(checkout), "lineId": line_id}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINE_DELETE, variables)
content = get_graphql_content(response)
@@ -1582,8 +1582,8 @@ def test_checkout_line_delete(
MUTATION_CHECKOUT_LINES_DELETE = """
- mutation checkoutLinesDelete($token: UUID!, $linesIds: [ID!]!) {
- checkoutLinesDelete(token: $token, linesIds: $linesIds) {
+ mutation checkoutLinesDelete($id: ID, $linesIds: [ID!]!) {
+ checkoutLinesDelete(id: $id, linesIds: $linesIds) {
checkout {
token
lines {
@@ -1623,7 +1623,7 @@ def test_checkout_lines_delete(
second_line_id = graphene.Node.to_global_id("CheckoutLine", second_line.pk)
lines_list = [first_line_id, second_line_id]
- variables = {"token": checkout.token, "linesIds": lines_list}
+ variables = {"id": to_global_id_or_none(checkout), "linesIds": lines_list}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_DELETE, variables)
content = get_graphql_content(response)
@@ -1641,11 +1641,10 @@ def test_checkout_lines_delete(
assert checkout.last_change != previous_last_change
-def test_checkout_lines_delete_invalid_checkout_token(
+def test_checkout_lines_delete_invalid_checkout_id(
user_api_client, checkout_with_items
):
checkout = checkout_with_items
- previous_last_change = checkout.last_change
line = checkout.lines.first()
second_line = checkout.lines.last()
@@ -1654,15 +1653,14 @@ def test_checkout_lines_delete_invalid_checkout_token(
lines_list = [first_line_id, second_line_id]
variables = {
- "token": "bd159cc8-9dd6-4529-a6f6-8a5dee169806",
+ "id": graphene.Node.to_global_id("Checkout", checkout.pk),
"linesIds": lines_list,
}
+ checkout.delete()
response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_DELETE, variables)
content = get_graphql_content(response)
errors = content["data"]["checkoutLinesDelete"]["errors"][0]
assert errors["code"] == CheckoutErrorCode.NOT_FOUND.name
- checkout.refresh_from_db()
- assert checkout.last_change == previous_last_change
def tests_checkout_lines_delete_invalid_lines_ids(user_api_client, checkout_with_items):
@@ -1673,7 +1671,7 @@ def tests_checkout_lines_delete_invalid_lines_ids(user_api_client, checkout_with
first_line_id = graphene.Node.to_global_id("CheckoutLine", line.pk)
lines_list = [first_line_id, "Q2hlY2tvdXRMaW5lOjE8"]
- variables = {"token": checkout.token, "linesIds": lines_list}
+ variables = {"id": to_global_id_or_none(checkout), "linesIds": lines_list}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_DELETE, variables)
content = get_graphql_content(response, ignore_errors=True)
errors = content["errors"][0]
diff --git a/saleor/graphql/checkout/tests/test_checkout_promo_codes.py b/saleor/graphql/checkout/tests/test_checkout_promo_codes.py
index ec3e57605c..2934aa71b6 100644
--- a/saleor/graphql/checkout/tests/test_checkout_promo_codes.py
+++ b/saleor/graphql/checkout/tests/test_checkout_promo_codes.py
@@ -1,4 +1,3 @@
-import uuid
from datetime import date, timedelta
from decimal import Decimal
from unittest import mock
@@ -19,6 +18,7 @@ from ....core.taxes import TaxedMoney
from ....discount import DiscountInfo, VoucherType
from ....plugins.manager import get_plugins_manager
from ....warehouse.models import Stock
+from ...core.utils import to_global_id_or_none
from ...tests.utils import get_graphql_content
from .test_checkout import MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE
from .test_checkout_lines import MUTATION_CHECKOUT_LINE_DELETE
@@ -47,7 +47,7 @@ def test_checkout_lines_delete_with_not_applicable_voucher(
line = checkout_with_item.lines.first()
line_id = graphene.Node.to_global_id("CheckoutLine", line.pk)
- variables = {"token": checkout_with_item.token, "lineId": line_id}
+ variables = {"id": to_global_id_or_none(checkout_with_item), "lineId": line_id}
response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINE_DELETE, variables)
content = get_graphql_content(response)
@@ -84,7 +84,10 @@ def test_checkout_shipping_address_update_with_not_applicable_voucher(
assert checkout_with_item.voucher_code == voucher.code
new_address = graphql_address_data
- variables = {"token": checkout_with_item.token, "shippingAddress": new_address}
+ variables = {
+ "id": to_global_id_or_none(checkout_with_item),
+ "shippingAddress": new_address,
+ }
response = user_api_client.post_graphql(
MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE, variables
)
@@ -108,8 +111,8 @@ def test_checkout_totals_use_discounts(
sale.products.add(product)
query = """
- query getCheckout($token: UUID) {
- checkout(token: $token) {
+ query getCheckout($id: ID) {
+ checkout(id: $id) {
lines {
totalPrice {
gross {
@@ -131,7 +134,7 @@ def test_checkout_totals_use_discounts(
}
"""
- variables = {"token": str(checkout.token)}
+ variables = {"id": to_global_id_or_none(checkout)}
response = api_client.post_graphql(query, variables)
content = get_graphql_content(response)
data = content["data"]["checkout"]
@@ -174,8 +177,8 @@ def test_checkout_totals_use_discounts(
QUERY_GET_CHECKOUT_GIFT_CARD_CODES = """
-query getCheckout($token: UUID!) {
- checkout(token: $token) {
+query getCheckout($id: ID) {
+ checkout(id: $id) {
token
giftCards {
last4CodeChars
@@ -190,7 +193,7 @@ query getCheckout($token: UUID!) {
def test_checkout_get_gift_card_code(user_api_client, checkout_with_gift_card):
gift_card = checkout_with_gift_card.gift_cards.first()
- variables = {"token": str(checkout_with_gift_card.token)}
+ variables = {"id": to_global_id_or_none(checkout_with_gift_card)}
response = user_api_client.post_graphql(
QUERY_GET_CHECKOUT_GIFT_CARD_CODES, variables
)
@@ -207,7 +210,7 @@ def test_checkout_get_gift_card_codes(
checkout_with_gift_card.save()
gift_card_first = checkout_with_gift_card.gift_cards.first()
gift_card_last = checkout_with_gift_card.gift_cards.last()
- variables = {"token": str(checkout_with_gift_card.token)}
+ variables = {"id": to_global_id_or_none(checkout_with_gift_card)}
response = user_api_client.post_graphql(
QUERY_GET_CHECKOUT_GIFT_CARD_CODES, variables
)
@@ -220,7 +223,7 @@ def test_checkout_get_gift_card_codes(
def test_checkout_get_gift_card_code_without_gift_card(user_api_client, checkout):
- variables = {"token": str(checkout.token)}
+ variables = {"id": to_global_id_or_none(checkout)}
response = user_api_client.post_graphql(
QUERY_GET_CHECKOUT_GIFT_CARD_CODES, variables
)
@@ -230,9 +233,9 @@ def test_checkout_get_gift_card_code_without_gift_card(user_api_client, checkout
MUTATION_CHECKOUT_ADD_PROMO_CODE = """
- mutation($token: UUID, $promoCode: String!) {
+ mutation($id: ID, $promoCode: String!) {
checkoutAddPromoCode(
- token: $token, promoCode: $promoCode) {
+ id: $id, promoCode: $promoCode) {
errors {
field
message
@@ -277,7 +280,10 @@ def _mutate_checkout_add_promo_code(client, variables):
def test_checkout_add_voucher_for_entire_order(api_client, checkout_with_item, voucher):
# given
- variables = {"token": checkout_with_item.token, "promoCode": voucher.code}
+ variables = {
+ "id": to_global_id_or_none(checkout_with_item),
+ "promoCode": voucher.code,
+ }
assert voucher.type == VoucherType.ENTIRE_ORDER
manager = get_plugins_manager()
lines, _ = fetch_checkout_lines(checkout_with_item)
@@ -305,7 +311,10 @@ def test_checkout_add_voucher_for_entire_order(api_client, checkout_with_item, v
def test_checkout_add_voucher_code_by_token(api_client, checkout_with_item, voucher):
- variables = {"token": checkout_with_item.token, "promoCode": voucher.code}
+ variables = {
+ "id": to_global_id_or_none(checkout_with_item),
+ "promoCode": voucher.code,
+ }
data = _mutate_checkout_add_promo_code(api_client, variables)
assert not data["errors"]
@@ -345,7 +354,10 @@ def test_checkout_add_voucher_code_by_token_with_external_shipment(
set_external_shipping_id(checkout, external_shipping_method_id)
checkout.save(update_fields=["shipping_address", "private_metadata"])
- variables = {"token": checkout_with_item.token, "promoCode": voucher.code}
+ variables = {
+ "id": to_global_id_or_none(checkout_with_item),
+ "promoCode": voucher.code,
+ }
data = _mutate_checkout_add_promo_code(api_client, variables)
assert not data["errors"]
@@ -374,7 +386,10 @@ def test_checkout_add_voucher_code_with_display_gross_prices(
),
)
- variables = {"token": checkout_with_item.token, "promoCode": voucher.code}
+ variables = {
+ "id": to_global_id_or_none(checkout_with_item),
+ "promoCode": voucher.code,
+ }
data = _mutate_checkout_add_promo_code(api_client, variables)
assert not data["errors"]
@@ -404,7 +419,10 @@ def test_checkout_add_voucher_code_without_display_gross_prices(
),
)
- variables = {"token": checkout_with_item.token, "promoCode": voucher.code}
+ variables = {
+ "id": to_global_id_or_none(checkout_with_item),
+ "promoCode": voucher.code,
+ }
data = _mutate_checkout_add_promo_code(api_client, variables)
assert data["errors"][0]["code"] == CheckoutErrorCode.VOUCHER_NOT_APPLICABLE.name
@@ -417,7 +435,10 @@ def test_checkout_add_voucher_code_without_display_gross_prices(
def test_checkout_add_voucher_code_variant_unavailable(
api_client, checkout_with_item, voucher
):
- variables = {"token": checkout_with_item.token, "promoCode": voucher.code}
+ variables = {
+ "id": to_global_id_or_none(checkout_with_item),
+ "promoCode": voucher.code,
+ }
checkout_with_item.lines.first().variant.channel_listings.filter(
channel=checkout_with_item.channel
).delete()
@@ -450,7 +471,7 @@ def test_checkout_add_voucher_code_checkout_with_sale(
previous_checkout_last_change = checkout_with_item.last_change
variables = {
- "token": checkout_with_item.token,
+ "id": to_global_id_or_none(checkout_with_item),
"promoCode": voucher_percentage.code,
}
data = _mutate_checkout_add_promo_code(api_client, variables)
@@ -489,7 +510,10 @@ def test_checkout_add_specific_product_voucher_code_checkout_with_sale(
)
assert subtotal > subtotal_discounted
- variables = {"token": checkout_with_item.token, "promoCode": voucher.code}
+ variables = {
+ "id": to_global_id_or_none(checkout_with_item),
+ "promoCode": voucher.code,
+ }
# when
data = _mutate_checkout_add_promo_code(api_client, variables)
@@ -544,7 +568,10 @@ def test_checkout_add_products_voucher_code_checkout_with_sale(
discounts=[discount_info],
)
assert subtotal > subtotal_discounted
- variables = {"token": checkout_with_item.token, "promoCode": voucher.code}
+ variables = {
+ "id": to_global_id_or_none(checkout_with_item),
+ "promoCode": voucher.code,
+ }
# when
data = _mutate_checkout_add_promo_code(api_client, variables)
@@ -596,7 +623,10 @@ def test_checkout_add_collection_voucher_code_checkout_with_sale(
discounts=[discount_info],
)
assert subtotal > subtotal_discounted
- variables = {"token": checkout_with_item.token, "promoCode": voucher.code}
+ variables = {
+ "id": to_global_id_or_none(checkout_with_item),
+ "promoCode": voucher.code,
+ }
# when
data = _mutate_checkout_add_promo_code(api_client, variables)
@@ -649,7 +679,10 @@ def test_checkout_add_category_code_checkout_with_sale(
discounts=[discount_info],
)
assert subtotal > subtotal_discounted
- variables = {"token": checkout_with_item.token, "promoCode": voucher.code}
+ variables = {
+ "id": to_global_id_or_none(checkout_with_item),
+ "promoCode": voucher.code,
+ }
# when
data = _mutate_checkout_add_promo_code(api_client, variables)
@@ -674,7 +707,7 @@ def test_checkout_add_voucher_code_not_applicable_voucher(
api_client, checkout_with_item, voucher_with_high_min_spent_amount
):
variables = {
- "token": checkout_with_item.token,
+ "id": to_global_id_or_none(checkout_with_item),
"promoCode": voucher_with_high_min_spent_amount.code,
}
data = _mutate_checkout_add_promo_code(api_client, variables)
@@ -687,7 +720,7 @@ def test_checkout_add_voucher_code_not_assigned_to_channel(
api_client, checkout_with_item, voucher_without_channel
):
variables = {
- "token": checkout_with_item.token,
+ "id": to_global_id_or_none(checkout_with_item),
"promoCode": voucher_without_channel.code,
}
data = _mutate_checkout_add_promo_code(api_client, variables)
@@ -698,7 +731,10 @@ def test_checkout_add_voucher_code_not_assigned_to_channel(
def test_checkout_add_gift_card_code(api_client, checkout_with_item, gift_card):
gift_card_id = graphene.Node.to_global_id("GiftCard", gift_card.pk)
- variables = {"token": checkout_with_item.token, "promoCode": gift_card.code}
+ variables = {
+ "id": to_global_id_or_none(checkout_with_item),
+ "promoCode": gift_card.code,
+ }
data = _mutate_checkout_add_promo_code(api_client, variables)
assert not data["errors"]
@@ -713,7 +749,7 @@ def test_checkout_add_many_gift_card_code(
assert checkout_with_gift_card.gift_cards.count() > 0
gift_card_id = graphene.Node.to_global_id("GiftCard", gift_card_created_by_staff.pk)
variables = {
- "token": checkout_with_gift_card.token,
+ "id": to_global_id_or_none(checkout_with_gift_card),
"promoCode": gift_card_created_by_staff.code,
}
data = _mutate_checkout_add_promo_code(api_client, variables)
@@ -731,7 +767,10 @@ def test_checkout_add_inactive_gift_card_code(
gift_card.is_active = False
gift_card.save(update_fields=["is_active"])
- variables = {"token": checkout_with_item.token, "promoCode": gift_card.code}
+ variables = {
+ "id": to_global_id_or_none(checkout_with_item),
+ "promoCode": gift_card.code,
+ }
# when
data = _mutate_checkout_add_promo_code(staff_api_client, variables)
@@ -750,7 +789,10 @@ def test_checkout_add_expired_gift_card_code(
gift_card.expiry_date = date.today() - timedelta(days=10)
gift_card.save(update_fields=["expiry_date"])
- variables = {"token": checkout_with_item.token, "promoCode": gift_card.code}
+ variables = {
+ "id": to_global_id_or_none(checkout_with_item),
+ "promoCode": gift_card.code,
+ }
# when
data = _mutate_checkout_add_promo_code(staff_api_client, variables)
@@ -771,7 +813,10 @@ def test_checkout_add_used_gift_card_code(
gift_card_id = graphene.Node.to_global_id("GiftCard", gift_card_used.pk)
- variables = {"token": checkout_with_item.token, "promoCode": gift_card_used.code}
+ variables = {
+ "id": to_global_id_or_none(checkout_with_item),
+ "promoCode": gift_card_used.code,
+ }
# when
data = _mutate_checkout_add_promo_code(staff_api_client, variables)
@@ -793,7 +838,10 @@ def test_checkout_add_used_gift_card_code_invalid_user(
checkout_with_item.user = staff_user
assert gift_card_used.used_by_email != checkout_with_item.user.email
- variables = {"token": checkout_with_item.token, "promoCode": gift_card_used.code}
+ variables = {
+ "id": to_global_id_or_none(checkout_with_item),
+ "promoCode": gift_card_used.code,
+ }
# when
data = _mutate_checkout_add_promo_code(staff_api_client, variables)
@@ -817,7 +865,10 @@ def test_checkout_get_total_with_gift_card(api_client, checkout_with_item, gift_
)
total_with_gift_card = taxed_total.gross.amount - gift_card.current_balance_amount
- variables = {"token": checkout_with_item.token, "promoCode": gift_card.code}
+ variables = {
+ "id": to_global_id_or_none(checkout_with_item),
+ "promoCode": gift_card.code,
+ }
data = _mutate_checkout_add_promo_code(api_client, variables)
assert not data["errors"]
@@ -846,7 +897,7 @@ def test_checkout_get_total_with_many_gift_card(
assert checkout_with_gift_card.gift_cards.count() > 0
variables = {
- "token": checkout_with_gift_card.token,
+ "id": to_global_id_or_none(checkout_with_gift_card),
"promoCode": gift_card_created_by_staff.code,
}
data = _mutate_checkout_add_promo_code(api_client, variables)
@@ -862,7 +913,10 @@ def test_checkout_get_total_with_more_money_on_gift_card(
checkout_with_item.email = gift_card_used.used_by_email
checkout_with_item.save(update_fields=["email"])
- variables = {"token": checkout_with_item.token, "promoCode": gift_card_used.code}
+ variables = {
+ "id": to_global_id_or_none(checkout_with_item),
+ "promoCode": gift_card_used.code,
+ }
data = _mutate_checkout_add_promo_code(api_client, variables)
assert not data["errors"]
@@ -875,7 +929,10 @@ def test_checkout_add_same_gift_card_code(api_client, checkout_with_gift_card):
gift_card = checkout_with_gift_card.gift_cards.first()
gift_card_id = graphene.Node.to_global_id("GiftCard", gift_card.pk)
gift_card_count = checkout_with_gift_card.gift_cards.count()
- variables = {"token": checkout_with_gift_card.token, "promoCode": gift_card.code}
+ variables = {
+ "id": to_global_id_or_none(checkout_with_gift_card),
+ "promoCode": gift_card.code,
+ }
data = _mutate_checkout_add_promo_code(api_client, variables)
assert not data["errors"]
@@ -891,7 +948,10 @@ def test_checkout_add_gift_card_code_in_active_gift_card(
gift_card.is_active = False
gift_card.save()
- variables = {"token": checkout_with_item.token, "promoCode": gift_card.code}
+ variables = {
+ "id": to_global_id_or_none(checkout_with_item),
+ "promoCode": gift_card.code,
+ }
data = _mutate_checkout_add_promo_code(api_client, variables)
assert data["errors"]
@@ -904,23 +964,30 @@ def test_checkout_add_gift_card_code_in_expired_gift_card(
gift_card.expiry_date = date.today() - timedelta(days=1)
gift_card.save()
- variables = {"token": checkout_with_item.token, "promoCode": gift_card.code}
+ variables = {
+ "id": to_global_id_or_none(checkout_with_item),
+ "promoCode": gift_card.code,
+ }
data = _mutate_checkout_add_promo_code(api_client, variables)
assert data["errors"]
assert data["errors"][0]["field"] == "promoCode"
-def test_checkout_add_promo_code_invalid_checkout(api_client, voucher):
- variables = {"token": uuid.uuid4(), "promoCode": voucher.code}
+def test_checkout_add_promo_code_invalid_checkout(api_client, voucher, checkout):
+ variables = {"id": to_global_id_or_none(checkout), "promoCode": voucher.code}
+ checkout.delete()
data = _mutate_checkout_add_promo_code(api_client, variables)
assert data["errors"]
- assert data["errors"][0]["field"] == "token"
+ assert data["errors"][0]["field"] == "id"
def test_checkout_add_promo_code_invalid_promo_code(api_client, checkout_with_item):
- variables = {"token": checkout_with_item.token, "promoCode": "unexisting_code"}
+ variables = {
+ "id": to_global_id_or_none(checkout_with_item),
+ "promoCode": "unexisting_code",
+ }
data = _mutate_checkout_add_promo_code(api_client, variables)
assert data["errors"]
@@ -956,7 +1023,7 @@ def test_checkout_add_promo_code_invalidate_shipping_method(
add_variant_to_checkout(checkout_info, variant, 5)
# Apply voucher
- variables = {"token": checkout.token, "promoCode": voucher.code}
+ variables = {"id": to_global_id_or_none(checkout), "promoCode": voucher.code}
data = _mutate_checkout_add_promo_code(api_client, variables)
shipping_method_id = graphene.Node.to_global_id(
@@ -972,7 +1039,10 @@ def test_checkout_add_promo_code_no_checkout_email(
checkout_with_item.email = None
checkout_with_item.save(update_fields=["email"])
- variables = {"token": checkout_with_item.token, "promoCode": voucher.code}
+ variables = {
+ "id": to_global_id_or_none(checkout_with_item),
+ "promoCode": voucher.code,
+ }
data = _mutate_checkout_add_promo_code(api_client, variables)
assert data["errors"]
@@ -1014,7 +1084,7 @@ def test_checkout_add_free_shipping_voucher_do_not_invalidate_shipping_method(
shipping_listing.save(update_fields=["price_amount", "minimum_order_price_amount"])
variables = {
- "token": checkout_with_item.token,
+ "id": to_global_id_or_none(checkout_with_item),
"promoCode": voucher_free_shipping.code,
}
data = _mutate_checkout_add_promo_code(api_client, variables)
@@ -1065,7 +1135,7 @@ def test_checkout_add_shipping_voucher_do_not_invalidate_shipping_method(
voucher_shipping_type.save(update_fields=["countries"])
variables = {
- "token": checkout_with_item.token,
+ "id": to_global_id_or_none(checkout_with_item),
"promoCode": voucher_shipping_type.code,
}
data = _mutate_checkout_add_promo_code(api_client, variables)
@@ -1077,9 +1147,9 @@ def test_checkout_add_shipping_voucher_do_not_invalidate_shipping_method(
MUTATION_CHECKOUT_REMOVE_PROMO_CODE = """
- mutation($token: UUID, $promoCode: String, $promoCodeId: ID) {
+ mutation($id: ID, $promoCode: String, $promoCodeId: ID) {
checkoutRemovePromoCode(
- token: $token, promoCode: $promoCode, promoCodeId: $promoCodeId) {
+ id: $id, promoCode: $promoCode, promoCodeId: $promoCodeId) {
errors {
field
code
@@ -1109,7 +1179,7 @@ def test_checkout_remove_voucher_code(api_client, checkout_with_voucher):
previous_checkout_last_change = checkout_with_voucher.last_change
variables = {
- "token": checkout_with_voucher.token,
+ "id": to_global_id_or_none(checkout_with_voucher),
"promoCode": checkout_with_voucher.voucher_code,
}
@@ -1132,7 +1202,7 @@ def test_checkout_remove_voucher_code_with_inactive_channel(
previous_checkout_last_change = checkout_with_voucher.last_change
variables = {
- "token": checkout_with_voucher.token,
+ "id": to_global_id_or_none(checkout_with_voucher),
"promoCode": checkout_with_voucher.voucher_code,
}
@@ -1150,7 +1220,7 @@ def test_checkout_remove_gift_card_code(api_client, checkout_with_gift_card):
previous_checkout_last_change = checkout_with_gift_card.last_change
variables = {
- "token": checkout_with_gift_card.token,
+ "id": to_global_id_or_none(checkout_with_gift_card),
"promoCode": checkout_with_gift_card.gift_cards.first().code,
}
@@ -1173,7 +1243,7 @@ def test_checkout_remove_one_of_gift_cards(
gift_card_last = checkout_with_gift_card.gift_cards.last()
variables = {
- "token": checkout_with_gift_card.token,
+ "id": to_global_id_or_none(checkout_with_gift_card),
"promoCode": gift_card_first.code,
}
@@ -1189,7 +1259,10 @@ def test_checkout_remove_one_of_gift_cards(
def test_checkout_remove_promo_code_invalid_promo_code(api_client, checkout_with_item):
previous_checkout_last_change = checkout_with_item.last_change
- variables = {"token": checkout_with_item.token, "promoCode": "unexisting_code"}
+ variables = {
+ "id": to_global_id_or_none(checkout_with_item),
+ "promoCode": "unexisting_code",
+ }
data = _mutate_checkout_remove_promo_code(api_client, variables)
@@ -1199,13 +1272,14 @@ def test_checkout_remove_promo_code_invalid_promo_code(api_client, checkout_with
assert checkout_with_item.last_change == previous_checkout_last_change
-def test_checkout_remove_promo_code_invalid_checkout(api_client, voucher):
- variables = {"token": uuid.uuid4(), "promoCode": voucher.code}
+def test_checkout_remove_promo_code_invalid_checkout(api_client, voucher, checkout):
+ variables = {"id": to_global_id_or_none(checkout), "promoCode": voucher.code}
+ checkout.delete()
data = _mutate_checkout_remove_promo_code(api_client, variables)
assert data["errors"]
- assert data["errors"][0]["field"] == "token"
+ assert data["errors"][0]["field"] == "id"
def test_checkout_remove_voucher_code_by_id(
@@ -1215,7 +1289,7 @@ def test_checkout_remove_voucher_code_by_id(
checkout_with_voucher.gift_cards.add(gift_card)
variables = {
- "token": checkout_with_voucher.token,
+ "id": to_global_id_or_none(checkout_with_voucher),
"promoCodeId": graphene.Node.to_global_id("Voucher", voucher.id),
}
@@ -1236,7 +1310,7 @@ def test_checkout_remove_gift_card_by_id(
checkout_with_voucher.gift_cards.add(gift_card, gift_card_expiry_date)
variables = {
- "token": checkout_with_voucher.token,
+ "id": to_global_id_or_none(checkout_with_voucher),
"promoCodeId": graphene.Node.to_global_id("GiftCard", gift_card.id),
}
diff --git a/saleor/graphql/core/utils/__init__.py b/saleor/graphql/core/utils/__init__.py
index c10d3d9564..a13b37eb4e 100644
--- a/saleor/graphql/core/utils/__init__.py
+++ b/saleor/graphql/core/utils/__init__.py
@@ -236,9 +236,9 @@ def from_global_id_or_none(
def to_global_id_or_none(instance):
class_name = instance.__class__.__name__
- if instance.id is None:
+ if instance.pk is None:
return None
- return graphene.Node.to_global_id(class_name, instance.id)
+ return graphene.Node.to_global_id(class_name, instance.pk)
def add_hash_to_file_name(file):
diff --git a/saleor/graphql/payment/mutations.py b/saleor/graphql/payment/mutations.py
index 0a27118bb8..fa4222152d 100644
--- a/saleor/graphql/payment/mutations.py
+++ b/saleor/graphql/payment/mutations.py
@@ -35,7 +35,7 @@ from ...payment.gateway import (
from ...payment.utils import create_payment, is_currency_supported
from ..account.i18n import I18nMixin
from ..channel.utils import validate_channel
-from ..checkout.mutations.utils import get_checkout_by_token
+from ..checkout.mutations.utils import get_checkout
from ..checkout.types import Checkout
from ..core.descriptions import (
ADDED_IN_31,
@@ -48,7 +48,6 @@ from ..core.fields import JSONString
from ..core.mutations import BaseMutation
from ..core.scalars import UUID, PositiveDecimal
from ..core.types import common as common_types
-from ..core.validators import validate_one_of_args_is_in_mutation
from ..meta.mutations import MetadataInput
from ..utils import get_user_or_app_from_context
from .enums import TransactionActionEnum, TransactionStatusEnum
@@ -137,13 +136,20 @@ class CheckoutPaymentCreate(BaseMutation, I18nMixin):
payment = graphene.Field(Payment, description="A newly created payment.")
class Arguments:
+ id = graphene.ID(
+ description="The checkout's ID." + ADDED_IN_34,
+ required=False,
+ )
+ token = UUID(
+ description=f"Checkout token.{DEPRECATED_IN_3X_INPUT} Use `id` instead.",
+ required=False,
+ )
checkout_id = graphene.ID(
+ required=False,
description=(
- f"The ID of the checkout. {DEPRECATED_IN_3X_INPUT} Use token instead."
+ f"The ID of the checkout. {DEPRECATED_IN_3X_INPUT} Use `id` instead."
),
- required=False,
)
- token = UUID(description="Checkout token.", required=False)
input = PaymentInput(
description="Data required to create a new payment.", required=True
)
@@ -245,20 +251,18 @@ class CheckoutPaymentCreate(BaseMutation, I18nMixin):
)
@classmethod
- def perform_mutation(cls, _root, info, checkout_id=None, token=None, **data):
- # DEPRECATED
- validate_one_of_args_is_in_mutation(
- PaymentErrorCode, "checkout_id", checkout_id, "token", token
+ def perform_mutation(
+ cls, _root, info, checkout_id=None, token=None, id=None, **data
+ ):
+ checkout = get_checkout(
+ cls,
+ info,
+ checkout_id=checkout_id,
+ token=token,
+ id=id,
+ error_class=PaymentErrorCode,
)
- if token:
- checkout = get_checkout_by_token(token)
- # DEPRECATED
- else:
- checkout = cls.get_node_or_error(
- info, checkout_id or token, only_type=Checkout, field="checkout_id"
- )
-
cls.validate_checkout_email(checkout)
data = data["input"]
diff --git a/saleor/graphql/payment/tests/mutations/test_checkout_payment_create.py b/saleor/graphql/payment/tests/mutations/test_checkout_payment_create.py
index d343d58fe8..041d2c9064 100644
--- a/saleor/graphql/payment/tests/mutations/test_checkout_payment_create.py
+++ b/saleor/graphql/payment/tests/mutations/test_checkout_payment_create.py
@@ -12,17 +12,18 @@ from .....payment.error_codes import PaymentErrorCode
from .....payment.interface import StorePaymentMethodEnum
from .....payment.models import ChargeStatus, Payment
from .....plugins.manager import get_plugins_manager
+from ....core.utils import to_global_id_or_none
from ....tests.utils import get_graphql_content
DUMMY_GATEWAY = "mirumee.payments.dummy"
CREATE_PAYMENT_MUTATION = """
mutation CheckoutPaymentCreate(
- $token: UUID,
+ $id: ID,
$input: PaymentInput!,
) {
checkoutPaymentCreate(
- token: $token,
+ id: $id,
input: $input,
) {
payment {
@@ -52,7 +53,7 @@ def test_checkout_add_payment_without_shipping_method_and_not_shipping_required(
manager=manager, checkout_info=checkout_info, lines=lines, address=address
)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"input": {
"gateway": DUMMY_GATEWAY,
"token": "sample-token",
@@ -90,7 +91,7 @@ def test_checkout_add_payment_without_shipping_method_with_shipping_required(
manager=manager, checkout_info=checkout_info, lines=lines, address=address
)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"input": {
"gateway": DUMMY_GATEWAY,
"token": "sample-token",
@@ -121,7 +122,7 @@ def test_checkout_add_payment_with_shipping_method_and_shipping_required(
manager=manager, checkout_info=checkout_info, lines=lines, address=address
)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"input": {
"gateway": DUMMY_GATEWAY,
"token": "sample-token",
@@ -162,7 +163,7 @@ def test_checkout_add_payment(
)
return_url = "https://www.example.com"
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"input": {
"gateway": DUMMY_GATEWAY,
"token": "sample-token",
@@ -204,7 +205,7 @@ def test_checkout_add_payment_default_amount(
)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"input": {"gateway": DUMMY_GATEWAY, "token": "sample-token"},
}
response = user_api_client.post_graphql(CREATE_PAYMENT_MUTATION, variables)
@@ -235,7 +236,7 @@ def test_checkout_add_payment_bad_amount(
)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"input": {
"gateway": DUMMY_GATEWAY,
"token": "sample-token",
@@ -265,7 +266,7 @@ def test_checkout_add_payment_no_checkout_email(
)
return_url = "https://www.example.com"
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"input": {
"gateway": DUMMY_GATEWAY,
"token": "sample-token",
@@ -294,7 +295,7 @@ def test_checkout_add_payment_not_supported_currency(
checkout.save(update_fields=["billing_address", "currency"])
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"input": {"gateway": DUMMY_GATEWAY, "token": "sample-token", "amount": "10.0"},
}
response = user_api_client.post_graphql(CREATE_PAYMENT_MUTATION, variables)
@@ -312,7 +313,7 @@ def test_checkout_add_payment_not_existing_gateway(
checkout.save(update_fields=["billing_address", "currency"])
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"input": {"gateway": "not.existing", "token": "sample-token", "amount": "10.0"},
}
response = user_api_client.post_graphql(CREATE_PAYMENT_MUTATION, variables)
@@ -331,7 +332,7 @@ def test_checkout_add_payment_gateway_inactive(
checkout.save(update_fields=["billing_address", "currency"])
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"input": {"gateway": DUMMY_GATEWAY, "token": "sample-token", "amount": "10.0"},
}
response = user_api_client.post_graphql(CREATE_PAYMENT_MUTATION, variables)
@@ -352,7 +353,7 @@ def test_use_checkout_billing_address_as_payment_billing(
manager=manager, checkout_info=checkout_info, lines=lines, address=address
)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"input": {
"gateway": DUMMY_GATEWAY,
"token": "sample-token",
@@ -401,7 +402,7 @@ def test_create_payment_for_checkout_with_active_payments(
manager=manager, checkout_info=checkout_info, lines=lines, address=address
)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"input": {
"gateway": DUMMY_GATEWAY,
"token": "sample-token",
@@ -454,7 +455,7 @@ def test_create_payment_with_store(
manager=manager, checkout_info=checkout_info, lines=lines, address=address
)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"input": {
"gateway": DUMMY_GATEWAY,
"token": "sample-token",
@@ -490,7 +491,7 @@ def test_create_payment_with_metadata(
manager=manager, checkout_info=checkout_info, lines=lines, address=address
)
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"input": {
"gateway": DUMMY_GATEWAY,
"token": "sample-token",
@@ -528,7 +529,7 @@ def test_checkout_add_payment_no_variant_channel_listings(
)
return_url = "https://www.example.com"
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"input": {
"gateway": DUMMY_GATEWAY,
"token": "sample-token",
@@ -569,7 +570,7 @@ def test_checkout_add_payment_no_product_channel_listings(
)
return_url = "https://www.example.com"
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"input": {
"gateway": DUMMY_GATEWAY,
"token": "sample-token",
@@ -609,7 +610,7 @@ def test_checkout_add_payment_checkout_without_lines(
)
return_url = "https://www.example.com"
variables = {
- "token": checkout.token,
+ "id": to_global_id_or_none(checkout),
"input": {
"gateway": DUMMY_GATEWAY,
"token": "sample-token",
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 8b714c9b73..38f3a214d6 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -931,7 +931,18 @@ type Query {
"""Look up a checkout by token and slug of channel."""
checkout(
- """The checkout's token."""
+ """
+ The checkout's ID.
+
+ Added in Saleor 3.4.
+ """
+ id: ID
+
+ """
+ The checkout's token.
+
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
+ """
token: UUID
): Checkout
@@ -7195,7 +7206,13 @@ type User implements Node & ObjectWithMetadata {
checkoutTokens(
"""Slug of a channel for which the data should be returned."""
channel: String
- ): [UUID!]
+ ): [UUID!] @deprecated(reason: "This field will be removed in Saleor 4.0. Use `checkoutIds` instead.")
+
+ """Returns the checkout ID's assigned to this user."""
+ checkoutIds(
+ """Slug of a channel for which the data should be returned."""
+ channel: String
+ ): [ID!]
"""List of the user gift cards."""
giftCards(
@@ -12518,16 +12535,27 @@ type Mutation {
"""Adds a gift card or a voucher to a checkout."""
checkoutAddPromoCode(
"""
- The ID of the checkout.
+ The ID of the checkout.
- DEPRECATED: this field will be removed in Saleor 4.0. Use token instead.
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
"""
checkoutId: ID
+ """
+ The checkout's ID.
+
+ Added in Saleor 3.4.
+ """
+ id: ID
+
"""Gift card code or voucher code."""
promoCode: String!
- """Checkout token."""
+ """
+ Checkout token.
+
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
+ """
token: UUID
): CheckoutAddPromoCode
@@ -12539,11 +12567,22 @@ type Mutation {
"""
The ID of the checkout.
- DEPRECATED: this field will be removed in Saleor 4.0. Use token instead.
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
"""
checkoutId: ID
- """Checkout token."""
+ """
+ The checkout's ID.
+
+ Added in Saleor 3.4.
+ """
+ id: ID
+
+ """
+ Checkout token.
+
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
+ """
token: UUID
): CheckoutBillingAddressUpdate
@@ -12554,10 +12593,17 @@ type Mutation {
"""
The ID of the checkout.
- DEPRECATED: this field will be removed in Saleor 4.0. Use token instead.
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
"""
checkoutId: ID
+ """
+ The checkout's ID.
+
+ Added in Saleor 3.4.
+ """
+ id: ID
+
"""Client-side generated data required to finalize the payment."""
paymentData: JSONString
@@ -12573,7 +12619,11 @@ type Mutation {
"""
storeSource: Boolean = false
- """Checkout token."""
+ """
+ Checkout token.
+
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
+ """
token: UUID
): CheckoutComplete
@@ -12592,7 +12642,7 @@ type Mutation {
"""
The ID of the checkout.
- DEPRECATED: this field will be removed in Saleor 4.0. Use token instead.
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
"""
checkoutId: ID
@@ -12601,7 +12651,18 @@ type Mutation {
"""
customerId: ID
- """Checkout token."""
+ """
+ The checkout's ID.
+
+ Added in Saleor 3.4.
+ """
+ id: ID
+
+ """
+ Checkout token.
+
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
+ """
token: UUID
): CheckoutCustomerAttach
@@ -12614,11 +12675,22 @@ type Mutation {
"""
The ID of the checkout.
- DEPRECATED: this field will be removed in Saleor 4.0. Use token instead.
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
"""
checkoutId: ID
- """Checkout token."""
+ """
+ The checkout's ID.
+
+ Added in Saleor 3.4.
+ """
+ id: ID
+
+ """
+ Checkout token.
+
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
+ """
token: UUID
): CheckoutCustomerDetach
@@ -12627,14 +12699,25 @@ type Mutation {
"""
The ID of the checkout.
- DEPRECATED: this field will be removed in Saleor 4.0. Use token instead.
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
"""
checkoutId: ID
"""email."""
email: String!
- """Checkout token."""
+ """
+ The checkout's ID.
+
+ Added in Saleor 3.4.
+ """
+ id: ID
+
+ """
+ Checkout token.
+
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
+ """
token: UUID
): CheckoutEmailUpdate
@@ -12643,24 +12726,46 @@ type Mutation {
"""
The ID of the checkout.
- DEPRECATED: this field will be removed in Saleor 4.0. Use token instead.
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
"""
checkoutId: ID
+ """
+ The checkout's ID.
+
+ Added in Saleor 3.4.
+ """
+ id: ID
+
"""ID of the checkout line to delete."""
lineId: ID
- """Checkout token."""
+ """
+ Checkout token.
+
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
+ """
token: UUID
): CheckoutLineDelete @deprecated(reason: "DEPRECATED: Will be removed in Saleor 4.0. Use `checkoutLinesDelete` instead.")
"""Deletes checkout lines."""
checkoutLinesDelete(
+ """
+ The checkout's ID.
+
+ Added in Saleor 3.4.
+ """
+ id: ID
+
"""A list of checkout lines."""
linesIds: [ID!]!
- """Checkout token."""
- token: UUID!
+ """
+ Checkout token.
+
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
+ """
+ token: UUID
): CheckoutLinesDelete
"""
@@ -12670,16 +12775,27 @@ type Mutation {
"""
The ID of the checkout.
- DEPRECATED: this field will be removed in Saleor 4.0. Use token instead.
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
"""
checkoutId: ID
+ """
+ The checkout's ID.
+
+ Added in Saleor 3.4.
+ """
+ id: ID
+
"""
A list of checkout lines, each containing information about an item in the checkout.
"""
lines: [CheckoutLineInput!]!
- """Checkout token."""
+ """
+ Checkout token.
+
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
+ """
token: UUID
): CheckoutLinesAdd
@@ -12688,16 +12804,27 @@ type Mutation {
"""
The ID of the checkout.
- DEPRECATED: this field will be removed in Saleor 4.0. Use token instead.
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
"""
checkoutId: ID
+ """
+ The checkout's ID.
+
+ Added in Saleor 3.4.
+ """
+ id: ID
+
"""
A list of checkout lines, each containing information about an item in the checkout.
"""
lines: [CheckoutLineUpdateInput!]!
- """Checkout token."""
+ """
+ Checkout token.
+
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
+ """
token: UUID
): CheckoutLinesUpdate
@@ -12706,17 +12833,28 @@ type Mutation {
"""
The ID of the checkout.
- DEPRECATED: this field will be removed in Saleor 4.0. Use token instead.
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
"""
checkoutId: ID
+ """
+ The checkout's ID.
+
+ Added in Saleor 3.4.
+ """
+ id: ID
+
"""Gift card code or voucher code."""
promoCode: String
"""Gift card or voucher ID."""
promoCodeId: ID
- """Checkout token."""
+ """
+ Checkout token.
+
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
+ """
token: UUID
): CheckoutRemovePromoCode
@@ -12725,14 +12863,25 @@ type Mutation {
"""
The ID of the checkout.
- DEPRECATED: this field will be removed in Saleor 4.0. Use token instead.
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
"""
checkoutId: ID
+ """
+ The checkout's ID.
+
+ Added in Saleor 3.4.
+ """
+ id: ID
+
"""Data required to create a new payment."""
input: PaymentInput!
- """Checkout token."""
+ """
+ Checkout token.
+
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
+ """
token: UUID
): CheckoutPaymentCreate
@@ -12741,14 +12890,25 @@ type Mutation {
"""
The ID of the checkout.
- DEPRECATED: this field will be removed in Saleor 4.0. Use token instead.
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
"""
checkoutId: ID
+ """
+ The checkout's ID.
+
+ Added in Saleor 3.4.
+ """
+ id: ID
+
"""The mailing address to where the checkout will be shipped."""
shippingAddress: AddressInput!
- """Checkout token."""
+ """
+ Checkout token.
+
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
+ """
token: UUID
): CheckoutShippingAddressUpdate
@@ -12757,14 +12917,25 @@ type Mutation {
"""
The ID of the checkout.
- DEPRECATED: this field will be removed in Saleor 4.0. Use token instead.
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
"""
checkoutId: ID
+ """
+ The checkout's ID.
+
+ Added in Saleor 3.4.
+ """
+ id: ID
+
"""Shipping method."""
shippingMethodId: ID!
- """Checkout token."""
+ """
+ Checkout token.
+
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
+ """
token: UUID
): CheckoutShippingMethodUpdate @deprecated(reason: "This field will be removed in Saleor 4.0. Use `checkoutDeliveryMethodUpdate` instead.")
@@ -12779,7 +12950,18 @@ type Mutation {
"""Delivery Method ID (`Warehouse` ID or `ShippingMethod` ID)."""
deliveryMethodId: ID
- """Checkout token."""
+ """
+ The checkout's ID.
+
+ Added in Saleor 3.4.
+ """
+ id: ID
+
+ """
+ Checkout token.
+
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
+ """
token: UUID
): CheckoutDeliveryMethodUpdate
@@ -12788,14 +12970,25 @@ type Mutation {
"""
The ID of the checkout.
- DEPRECATED: this field will be removed in Saleor 4.0. Use token instead.
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
"""
checkoutId: ID
+ """
+ The checkout's ID.
+
+ Added in Saleor 3.4.
+ """
+ id: ID
+
"""New language code."""
languageCode: LanguageCodeEnum!
- """Checkout token."""
+ """
+ Checkout token.
+
+ DEPRECATED: this field will be removed in Saleor 4.0. Use `id` instead.
+ """
token: UUID
): CheckoutLanguageCodeUpdate