Skip to content

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

test improvements, setting for feature activation, cleanups

Tomasz Szymański26c441bbfd1a
diff --git a/saleor/account/emails.py b/saleor/account/emails.py
index b752413431..0be60a76f8 100644
--- a/saleor/account/emails.py
+++ b/saleor/account/emails.py
@@ -7,7 +7,6 @@ from templated_email import send_templated_mail
from ..account import events as account_events
from ..celeryconf import app
from ..core.emails import get_email_context, prepare_url
-from ..core.utils import build_absolute_uri
def send_user_password_reset_email_with_url(redirect_url, user):
diff --git a/saleor/graphql/account/mutations/account.py b/saleor/graphql/account/mutations/account.py
index 130d47dfa6..bab5785338 100644
--- a/saleor/graphql/account/mutations/account.py
+++ b/saleor/graphql/account/mutations/account.py
@@ -1,4 +1,5 @@
import graphene
+from django.conf import settings
from django.contrib.auth.tokens import default_token_generator
from django.core.exceptions import ValidationError
@@ -46,9 +47,10 @@ class AccountRegister(ModelMutation):
def save(cls, info, user, cleaned_input):
password = cleaned_input["password"]
user.set_password(password)
- user.is_active = False
+ if settings.ENABLE_ACCOUNT_CONFIRMATION_BY_EMAIL:
+ user.is_active = False
+ emails.send_account_confirmation_email(user)
user.save()
- emails.send_account_confirmation_email(user)
account_events.customer_account_created_event(user=user)
info.context.extensions.customer_created(customer=user)
diff --git a/saleor/graphql/account/mutations/base.py b/saleor/graphql/account/mutations/base.py
index 592d072f29..4d42ecf607 100644
--- a/saleor/graphql/account/mutations/base.py
+++ b/saleor/graphql/account/mutations/base.py
@@ -163,7 +163,7 @@ class ConfirmAccount(BaseMutation):
)
class Meta:
- description = "Sends an email with the account confirmation link."
+ description = "Confirm user account by token sent by email during registration"
@classmethod
def perform_mutation(cls, _root, info, **data):
diff --git a/saleor/settings.py b/saleor/settings.py
index d753d5a93a..0fa9ecc970 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -128,6 +128,8 @@ EMAIL_BACKEND = email_config["EMAIL_BACKEND"]
EMAIL_USE_TLS = email_config["EMAIL_USE_TLS"]
EMAIL_USE_SSL = email_config["EMAIL_USE_SSL"]
+ENABLE_ACCOUNT_CONFIRMATION_BY_EMAIL = True
+
ENABLE_SSL = get_bool_from_env("ENABLE_SSL", False)
if ENABLE_SSL:
diff --git a/tests/api/test_account.py b/tests/api/test_account.py
index 098f1fa3a7..d36dc9da30 100644
--- a/tests/api/test_account.py
+++ b/tests/api/test_account.py
@@ -9,6 +9,7 @@ from django.contrib.auth.tokens import default_token_generator
from django.core.exceptions import ValidationError
from django.core.files import File
from django.core.validators import URLValidator
+from django.test import override_settings
from freezegun import freeze_time
from prices import Money
@@ -603,6 +604,14 @@ def test_customer_register(send_account_confirmation_email_mock, user_api_client
assert customer_creation_event.user == new_user
+@override_settings(ENABLE_ACCOUNT_CONFIRMATION_BY_EMAIL=False)
+@patch("saleor.account.emails._send_account_confirmation_email")
+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)
+ assert send_account_confirmation_email_mock.delay.call_count == 0
+
+
CUSTOMER_CREATE_MUTATION = """
mutation CreateCustomer(
$email: String, $firstName: String, $lastName: String,
@@ -2129,22 +2138,20 @@ def test_account_reset_password(
url_validator(url)
-def test_account_confirmation(
- user_api_client, customer_user
-):
+def test_account_confirmation(user_api_client, customer_user):
customer_user.is_active = False
customer_user.save()
- token = default_token_generator.make_token(customer_user)
- variables = {"email": customer_user.email, "token": token}
- response = user_api_client.post_graphql(CONFIRM_ACCOUNT_MUTATION, variables)
- content = get_graphql_content(response)
+ variables = {
+ "email": customer_user.email,
+ "token": default_token_generator.make_token(customer_user)
+ }
+ user_api_client.post_graphql(CONFIRM_ACCOUNT_MUTATION, variables)
customer_user.refresh_from_db()
assert customer_user.is_active == True
-
@patch("saleor.account.emails._send_password_reset_email")
def test_request_password_reset_email_for_staff(
send_password_reset_email_mock, staff_api_client