Skip to content

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

Tests improvements

Tomasz Szymański14a766903f1d
diff --git a/saleor/graphql/account/mutations/account.py b/saleor/graphql/account/mutations/account.py
index 8d8377e1b4..655889c955 100644
--- a/saleor/graphql/account/mutations/account.py
+++ b/saleor/graphql/account/mutations/account.py
@@ -67,6 +67,11 @@ class AccountRegister(ModelMutation):
def clean_input(cls, info, instance, data, input_cls=None):
if not settings.ENABLE_ACCOUNT_CONFIRMATION_BY_EMAIL:
return super().clean_input(info, instance, data, input_cls=None)
+ elif not data.get("redirect_url"):
+ raise ValidationError(
+ {"redirect_url": "This field is required."},
+ code=AccountErrorCode.INVALID,
+ )
try:
validate_storefront_url(data["redirect_url"])
@@ -74,11 +79,7 @@ class AccountRegister(ModelMutation):
raise ValidationError(
{"redirect_url": error}, code=AccountErrorCode.INVALID
)
- except KeyError:
- raise ValidationError(
- {"redirect_url": "This field is required."},
- code=AccountErrorCode.INVALID,
- )
+
return super().clean_input(info, instance, data, input_cls=None)
@classmethod
diff --git a/tests/api/test_account.py b/tests/api/test_account.py
index 6544a2bdb6..c95b973053 100644
--- a/tests/api/test_account.py
+++ b/tests/api/test_account.py
@@ -640,7 +640,21 @@ def test_customer_register_disabled_email_confirmation(
send_account_confirmation_email_mock, user_api_client
):
variables = {"email": "[email protected]", "password": "Password"}
- user_api_client.post_graphql(ACCOUNT_REGISTER_MUTATION, variables)
+ response = user_api_client.post_graphql(ACCOUNT_REGISTER_MUTATION, variables)
+ errors = response.json()["data"]["accountRegister"]["errors"]
+ assert errors == []
+ assert send_account_confirmation_email_mock.delay.call_count == 0
+
+
+@override_settings(ENABLE_ACCOUNT_CONFIRMATION_BY_EMAIL=True)
+@patch("saleor.account.emails._send_account_confirmation_email")
+def test_customer_register_no_redirect_url(
+ send_account_confirmation_email_mock, user_api_client
+):
+ variables = {"email": "[email protected]", "password": "Password"}
+ response = user_api_client.post_graphql(ACCOUNT_REGISTER_MUTATION, variables)
+ errors = response.json()["data"]["accountRegister"]["errors"]
+ assert "redirectUrl" in map(lambda error: error["field"], errors)
assert send_account_confirmation_email_mock.delay.call_count == 0