Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
tests_for_invalid_registration_and_login (#14644)
Renataafcf4329408a
diff --git a/saleor/tests/e2e/account/test_should_not_be_able_to_create_account_with_existing_email.py b/saleor/tests/e2e/account/test_should_not_be_able_to_create_account_with_existing_email.pynew file mode 100644index 0000000000..b122f0166c--- /dev/null+++ b/saleor/tests/e2e/account/test_should_not_be_able_to_create_account_with_existing_email.py@@ -0,0 +1,54 @@+import pytest++from ..channel.utils import create_channel+from ..shop.utils import update_shop_settings+from ..utils import assign_permissions+from .utils import account_register, raw_account_register+++def test_should_not_be_able_to_create_account_with_existing_email_core_1503(+ e2e_not_logged_api_client,+ e2e_staff_api_client,+ permission_manage_channels,+ permission_manage_settings,+):+ # Before+ permissions = [permission_manage_channels, permission_manage_settings]+ assign_permissions(e2e_staff_api_client, permissions)++ chanel_data = create_channel(e2e_staff_api_client)+ channel_slug = chanel_data["slug"]++ input_data = {+ "enableAccountConfirmationByEmail": False,+ }++ update_shop_settings(e2e_staff_api_client, input_data)++ user_email = "[email protected]"+ user_password = "Test1234!"++ # Step 1 - Create account for the new customer+ user_account = account_register(+ e2e_not_logged_api_client,+ user_email,+ user_password,+ channel_slug,+ )+ user_id = user_account["id"]+ assert user_id is not None+ assert user_account["isActive"] is True++ # Step 2 - Create a new account with the same email address+ new_password = "Password1!"+ new_user_account = raw_account_register(+ e2e_not_logged_api_client,+ user_email,+ new_password,+ channel_slug,+ )+ error = new_user_account["data"]["accountRegister"]["errors"][0]+ assert error["field"] == "email"+ assert error["message"] == "User with this Email already exists."+ assert error["code"] == "UNIQUE"diff --git a/saleor/tests/e2e/account/test_should_not_be_able_to_login_with_invalid_credentials.py b/saleor/tests/e2e/account/test_should_not_be_able_to_login_with_invalid_credentials.pynew file mode 100644index 0000000000..cb702515d0--- /dev/null+++ b/saleor/tests/e2e/account/test_should_not_be_able_to_login_with_invalid_credentials.py@@ -0,0 +1,61 @@+import pytest++from ..channel.utils import create_channel+from ..shop.utils import update_shop_settings+from ..utils import assign_permissions+from .utils import account_register, raw_token_create+++def test_should_not_be_able_to_login_with_invalid_credentials_core_1506(+ e2e_not_logged_api_client,+ e2e_staff_api_client,+ permission_manage_channels,+ permission_manage_settings,+):+ # Before+ permissions = [permission_manage_channels, permission_manage_settings]+ assign_permissions(e2e_staff_api_client, permissions)++ chanel_data = create_channel(e2e_staff_api_client)+ channel_slug = chanel_data["slug"]++ input_data = {+ "enableAccountConfirmationByEmail": False,+ }++ update_shop_settings(e2e_staff_api_client, input_data)++ user_email = "[email protected]"+ user_password = "Test1234!"++ # Step 1 - Create account for the new customer+ user_account = account_register(+ e2e_not_logged_api_client,+ user_email,+ user_password,+ channel_slug,+ )+ user_id = user_account["id"]+ assert user_id is not None+ assert user_account["isActive"] is True++ # Step 2 - Login with invalid password+ invalid_password = "password"+ login_data = raw_token_create(+ e2e_not_logged_api_client, user_email, invalid_password+ )+ error = login_data["data"]["tokenCreate"]["errors"][0]+ assert error["field"] == "email"+ assert error["message"] == "Please, enter valid credentials"+ assert error["code"] == "INVALID_CREDENTIALS"++ # Step 3 - Login with invalid email+ invalid_email = "[email protected]"+ login_data = raw_token_create(+ e2e_not_logged_api_client, invalid_email, user_password+ )+ error = login_data["data"]["tokenCreate"]["errors"][0]+ assert error["field"] == "email"+ assert error["message"] == "Please, enter valid credentials"+ assert error["code"] == "INVALID_CREDENTIALS"diff --git a/saleor/tests/e2e/account/utils/__init__.py b/saleor/tests/e2e/account/utils/__init__.pyindex 372309bfd2..c44822a1a4 100644--- a/saleor/tests/e2e/account/utils/__init__.py+++ b/saleor/tests/e2e/account/utils/__init__.py@@ -1,9 +1,11 @@-from .account_register import account_register+from .account_register import account_register, raw_account_registerfrom .me import get_own_data-from .token_create import token_create+from .token_create import raw_token_create, token_create__all__ = ["account_register",+ "raw_account_register","token_create",+ "raw_token_create","get_own_data",]diff --git a/saleor/tests/e2e/account/utils/account_register.py b/saleor/tests/e2e/account/utils/account_register.pyindex af928fccac..d959e95b78 100644--- a/saleor/tests/e2e/account/utils/account_register.py+++ b/saleor/tests/e2e/account/utils/account_register.py@@ -19,7 +19,7 @@ mutation AccountRegister($input: AccountRegisterInput!) {"""-def account_register(+def raw_account_register(e2e_not_logged_api_client,email,password,@@ -37,11 +37,26 @@ def account_register(ACCOUNT_REGISTER_MUTATION,variables,)- content = get_graphql_content(response)+ content = get_graphql_content(response, ignore_errors=True)++ return content+- assert content["data"]["accountRegister"]["errors"] == []+def account_register(+ e2e_not_logged_api_client,+ email,+ password,+ channel_slug,+):+ response = raw_account_register(+ e2e_not_logged_api_client,+ email,+ password,+ channel_slug,+ )+ assert response["data"]["accountRegister"]["errors"] == []- data = content["data"]["accountRegister"]["user"]+ data = response["data"]["accountRegister"]["user"]assert data["id"] is not Noneassert data["email"] == emaildiff --git a/saleor/tests/e2e/account/utils/token_create.py b/saleor/tests/e2e/account/utils/token_create.pyindex 22995b2a1d..fdec2ed886 100644--- a/saleor/tests/e2e/account/utils/token_create.py+++ b/saleor/tests/e2e/account/utils/token_create.py@@ -19,25 +19,38 @@ mutation TokenCreate($email: String!, $password: String!) {"""-def token_create(+def raw_token_create(e2e_not_logged_api_client,email,password,):variables = {"email": email, "password": password}-response = e2e_not_logged_api_client.post_graphql(TOKEN_CREATE_MUTATION,variables,)- content = get_graphql_content(response)+ content = get_graphql_content(response, ignore_errors=True)++ return content+++def token_create(+ e2e_not_logged_api_client,+ email,+ password,+):+ response = raw_token_create(+ e2e_not_logged_api_client,+ email,+ password,+ )- assert content["data"]["tokenCreate"]["errors"] == []+ assert response["data"]["tokenCreate"]["errors"] == []- assert content["data"]["tokenCreate"]["token"] is not None- assert content["data"]["tokenCreate"]["refreshToken"] is not None+ assert response["data"]["tokenCreate"]["token"] is not None+ assert response["data"]["tokenCreate"]["refreshToken"] is not None- data = content["data"]["tokenCreate"]["user"]+ data = response["data"]["tokenCreate"]["user"]assert data["id"] is not Noneassert data["email"] == email