Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix unhandled error in AccountRegister (#15501)
Iga Karbowiak1373efea8f04
diff --git a/saleor/graphql/account/mutations/account/account_register.py b/saleor/graphql/account/mutations/account/account_register.pyindex 68d0bb5224..28c480659f 100644--- a/saleor/graphql/account/mutations/account/account_register.py+++ b/saleor/graphql/account/mutations/account/account_register.py@@ -107,7 +107,6 @@ class AccountRegister(ModelMutation):@classmethoddef clean_input(cls, info: ResolveInfo, instance, data, **kwargs):site = get_site_promise(info.context).get()-if not site.settings.enable_account_confirmation_by_email:return super().clean_input(info, instance, data, **kwargs)elif not data.get("redirect_url"):@@ -159,9 +158,8 @@ class AccountRegister(ModelMutation):with traced_atomic_transaction():user.is_confirmed = False+ user.save()if site.settings.enable_account_confirmation_by_email:- user.save()-# Notifications will be deprecated in the futuretoken = default_token_generator.make_token(user)notifications.send_account_confirmation(@@ -171,25 +169,22 @@ class AccountRegister(ModelMutation):channel_slug=cleaned_input["channel"],token=token,)- else:- user.save()-- if redirect_url:- params = urlencode(- {- "email": user.email,- "token": token or default_token_generator.make_token(user),- }+ if redirect_url:+ params = urlencode(+ {+ "email": user.email,+ "token": token or default_token_generator.make_token(user),+ }+ )+ redirect_url = prepare_url(params, redirect_url)++ cls.call_event(+ manager.account_confirmation_requested,+ user,+ cleaned_input["channel"],+ token,+ redirect_url,)- redirect_url = prepare_url(params, redirect_url)-- cls.call_event(- manager.account_confirmation_requested,- user,- cleaned_input["channel"],- token,- redirect_url,- )cls.call_event(manager.customer_created, user)account_events.customer_account_created_event(user=user)diff --git a/saleor/graphql/account/tests/mutations/account/test_account_register.py b/saleor/graphql/account/tests/mutations/account/test_account_register.pyindex db345a7b67..9d693669be 100644--- a/saleor/graphql/account/tests/mutations/account/test_account_register.py+++ b/saleor/graphql/account/tests/mutations/account/test_account_register.py@@ -16,26 +16,10 @@ from .....tests.utils import get_graphql_contentACCOUNT_REGISTER_MUTATION = """mutation RegisterAccount(- $password: String!,- $email: String!,- $firstName: String,- $lastName: String,- $redirectUrl: String,- $languageCode: LanguageCodeEnum- $metadata: [MetadataInput!],- $channel: String+ $input: AccountRegisterInput!) {accountRegister(- input: {- password: $password,- email: $email,- firstName: $firstName,- lastName: $lastName,- redirectUrl: $redirectUrl,- languageCode: $languageCode,- metadata: $metadata,- channel: $channel- }+ input: $input) {errors {field@@ -69,14 +53,16 @@ def test_customer_register(redirect_url = "http://localhost:3000"variables = {- "email": email,- "password": "Password",- "redirectUrl": redirect_url,- "firstName": "saleor",- "lastName": "rocks",- "languageCode": "PL",- "metadata": [{"key": "meta", "value": "data"}],- "channel": channel_PLN.slug,+ "input": {+ "email": email,+ "password": "Password",+ "redirectUrl": redirect_url,+ "firstName": "saleor",+ "lastName": "rocks",+ "languageCode": "PL",+ "metadata": [{"key": "meta", "value": "data"}],+ "channel": channel_PLN.slug,+ }}query = ACCOUNT_REGISTER_MUTATIONmutation_name = "accountRegister"@@ -98,8 +84,8 @@ def test_customer_register(}assert new_user.metadata == {"meta": "data"}assert new_user.language_code == "pl"- assert new_user.first_name == variables["firstName"]- assert new_user.last_name == variables["lastName"]+ assert new_user.first_name == variables["input"]["firstName"]+ assert new_user.last_name == variables["input"]["lastName"]assert new_user.search_document == generate_user_fields_search_document_value(new_user)@@ -137,14 +123,16 @@ def test_customer_register_generates_valid_token(email = "[email protected]"redirect_url = "http://localhost:3000"variables = {- "email": email,- "password": "Password",- "redirectUrl": redirect_url,- "firstName": "saleor",- "lastName": "rocks",- "languageCode": "PL",- "metadata": [{"key": "meta", "value": "data"}],- "channel": channel_PLN.slug,+ "input": {+ "email": email,+ "password": "Password",+ "redirectUrl": redirect_url,+ "firstName": "saleor",+ "lastName": "rocks",+ "languageCode": "PL",+ "metadata": [{"key": "meta", "value": "data"}],+ "channel": channel_PLN.slug,+ }}# when@@ -168,7 +156,7 @@ def test_customer_register_disabled_email_confirmation(site_settings.save(update_fields=["enable_account_confirmation_by_email"])email = "[email protected]"- variables = {"email": email, "password": "Password"}+ variables = {"input": {"email": email, "password": "Password"}}# whenresponse = api_client.post_graphql(ACCOUNT_REGISTER_MUTATION, variables)@@ -189,7 +177,7 @@ def test_customer_register_no_redirect_url(mocked_notify, api_client, site_settisite_settings.enable_account_confirmation_by_email = Truesite_settings.save(update_fields=["enable_account_confirmation_by_email"])- variables = {"email": "[email protected]", "password": "Password"}+ variables = {"input": {"email": "[email protected]", "password": "Password"}}# whenresponse = api_client.post_graphql(ACCOUNT_REGISTER_MUTATION, variables)@@ -207,7 +195,7 @@ def test_customer_register_upper_case_email(api_client, site_settings):site_settings.save(update_fields=["enable_account_confirmation_by_email"])email = "[email protected]"- variables = {"email": email, "password": "Password"}+ variables = {"input": {"email": email, "password": "Password"}}# whenresponse = api_client.post_graphql(ACCOUNT_REGISTER_MUTATION, variables)@@ -217,3 +205,37 @@ def test_customer_register_upper_case_email(api_client, site_settings):data = content["data"]["accountRegister"]assert not data["errors"]assert data["user"]["email"].lower()+++@patch("saleor.plugins.manager.PluginsManager.notify")+def test_customer_register_no_channel_email_confirmation_unset(+ mocked_notify, api_client, channel_PLN, site_settings+):+ # given+ site_settings.enable_account_confirmation_by_email = False+ site_settings.save(update_fields=["enable_account_confirmation_by_email"])++ email = "[email protected]"+ redirect_url = "http://localhost:3000"+ variables = {+ "input": {+ "email": email,+ "password": "Password",+ "redirectUrl": redirect_url,+ "firstName": "saleor",+ "lastName": "rocks",+ "languageCode": "PL",+ "metadata": [{"key": "meta", "value": "data"}],+ }+ }++ # when+ response = api_client.post_graphql(ACCOUNT_REGISTER_MUTATION, variables)+ content = get_graphql_content(response)+ data = content["data"]["accountRegister"]++ # then+ data = content["data"]["accountRegister"]+ assert not data["errors"]+ assert data["user"]["email"].lower()+ mocked_notify.assert_not_called()