Skip to content

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

Remove order matching from account creatiom/add unit tests

Damian Wysocki8534124d4787
diff --git a/saleor/graphql/account/mutations/account.py b/saleor/graphql/account/mutations/account.py
index 494eb98e4d..41983ba3e2 100644
--- a/saleor/graphql/account/mutations/account.py
+++ b/saleor/graphql/account/mutations/account.py
@@ -9,7 +9,6 @@ from ....account.error_codes import AccountErrorCode
from ....account.utils import create_jwt_token, decode_jwt_token
from ....checkout import AddressType
from ....core.utils.url import validate_storefront_url
-from ....order.utils import match_orders_with_new_user
from ...account.enums import AddressTypeEnum
from ...account.types import Address, AddressInput, User
from ...core.mutations import BaseMutation, ModelDeleteMutation, ModelMutation
@@ -100,7 +99,6 @@ class AccountRegister(ModelMutation):
emails.send_account_confirmation_email(user, cleaned_input["redirect_url"])
else:
user.save()
- match_orders_with_new_user(user)
account_events.customer_account_created_event(user=user)
info.context.extensions.customer_created(customer=user)
diff --git a/tests/api/test_account.py b/tests/api/test_account.py
index ff5077cb15..f4d418caa0 100644
--- a/tests/api/test_account.py
+++ b/tests/api/test_account.py
@@ -608,10 +608,7 @@ ACCOUNT_REGISTER_MUTATION = """
ENABLE_ACCOUNT_CONFIRMATION_BY_EMAIL=True, ALLOWED_CLIENT_HOSTS=["localhost"]
)
@patch("saleor.account.emails._send_account_confirmation_email")
-@patch("saleor.graphql.account.mutations.account.match_orders_with_new_user")
-def test_customer_register(
- match_orders_with_new_user_mock, send_account_confirmation_email_mock, api_client
-):
+def test_customer_register(send_account_confirmation_email_mock, api_client):
variables = {
"email": email,
@@ -637,24 +634,20 @@ def test_customer_register(
customer_creation_event = account_events.CustomerEvent.objects.get()
assert customer_creation_event.type == account_events.CustomerEvents.ACCOUNT_CREATED
assert customer_creation_event.user == new_user
- match_orders_with_new_user_mock.assert_not_called()
@override_settings(ENABLE_ACCOUNT_CONFIRMATION_BY_EMAIL=False)
@patch("saleor.account.emails._send_account_confirmation_email")
-@patch("saleor.graphql.account.mutations.account.match_orders_with_new_user")
def test_customer_register_disabled_email_confirmation(
- match_orders_with_new_user_mock, send_account_confirmation_email_mock, api_client
+ send_account_confirmation_email_mock, api_client
):
variables = {"email": email, "password": "Password"}
response = api_client.post_graphql(ACCOUNT_REGISTER_MUTATION, variables)
errors = response.json()["data"]["accountRegister"]["accountErrors"]
- new_user = User.objects.get(email=email)
assert errors == []
send_account_confirmation_email_mock.delay.assert_not_called()
- match_orders_with_new_user_mock.assert_called_once_with(new_user)
@override_settings(ENABLE_ACCOUNT_CONFIRMATION_BY_EMAIL=True)
@@ -2199,7 +2192,10 @@ def test_account_reset_password(
url_validator(url)
-def test_account_confirmation(api_client, customer_user):
+@patch("saleor.graphql.account.mutations.base.match_orders_with_new_user")
+def test_account_confirmation(
+ match_orders_with_new_user_mock, api_client, customer_user
+):
customer_user.is_active = False
customer_user.save()
@@ -2212,10 +2208,14 @@ def test_account_confirmation(api_client, customer_user):
assert not content["data"]["confirmAccount"]["accountErrors"]
assert content["data"]["confirmAccount"]["user"]["email"] == customer_user.email
customer_user.refresh_from_db()
+ match_orders_with_new_user_mock.assert_called_once_with(customer_user)
assert customer_user.is_active is True
-def test_account_confirmation_invalid_user(user_api_client, customer_user):
+@patch("saleor.graphql.account.mutations.base.match_orders_with_new_user")
+def test_account_confirmation_invalid_user(
+ match_orders_with_new_user_mock, user_api_client, customer_user
+):
variables = {
"email": "[email protected]",
"token": default_token_generator.make_token(customer_user),
@@ -2227,9 +2227,13 @@ def test_account_confirmation_invalid_user(user_api_client, customer_user):
content["data"]["confirmAccount"]["accountErrors"][0]["code"]
== AccountErrorCode.NOT_FOUND.name
)
+ match_orders_with_new_user_mock.assert_not_called()
-def test_account_confirmation_invalid_token(user_api_client, customer_user):
+@patch("saleor.graphql.account.mutations.base.match_orders_with_new_user")
+def test_account_confirmation_invalid_token(
+ match_orders_with_new_user_mock, user_api_client, customer_user
+):
variables = {"email": customer_user.email, "token": "invalid_token"}
response = user_api_client.post_graphql(CONFIRM_ACCOUNT_MUTATION, variables)
content = get_graphql_content(response)
@@ -2238,6 +2242,7 @@ def test_account_confirmation_invalid_token(user_api_client, customer_user):
content["data"]["confirmAccount"]["accountErrors"][0]["code"]
== AccountErrorCode.INVALID.name
)
+ match_orders_with_new_user_mock.assert_not_called()
@patch("saleor.account.emails._send_password_reset_email")