Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add missing cache to account tests (#18795)
Maciej Korycinskia371cc2a5c8c
diff --git a/saleor/graphql/account/tests/mutations/authentication/test_set_password.py b/saleor/graphql/account/tests/mutations/authentication/test_set_password.pyindex 48243f5dc8..185c14e4f6 100644--- a/saleor/graphql/account/tests/mutations/authentication/test_set_password.py+++ b/saleor/graphql/account/tests/mutations/authentication/test_set_password.py@@ -32,8 +32,12 @@ SET_PASSWORD_MUTATION = """"""+@patch("saleor.account.throttling.cache")@freeze_time("2018-05-31 12:00:01")-def test_set_password(user_api_client):+def test_set_password(mocked_cache, user_api_client, setup_mock_for_cache):+ # given+ setup_mock_for_cache({}, mocked_cache)+customer_user = User.objects.create_user(email="[email protected]", password="old-password")@@ -41,7 +45,11 @@ def test_set_password(user_api_client):password = "spanish-inquisition"variables = {"email": customer_user.email, "password": password, "token": token}++ # whenresponse = user_api_client.post_graphql(SET_PASSWORD_MUTATION, variables)++ # thencontent = get_graphql_content(response)data = content["data"]["setPassword"]assert data["user"]["id"]@@ -56,13 +64,16 @@ def test_set_password(user_api_client):@freeze_time("2018-05-31 12:00:01")+@patch("saleor.account.throttling.cache")@patch("saleor.graphql.account.mutations.authentication.set_password.match_orders_with_new_user")def test_set_password_confirm_user_and_match_orders(- match_orders_with_new_user_mock, user_api_client+ match_orders_with_new_user_mock, mocked_cache, user_api_client, setup_mock_for_cache):# given+ setup_mock_for_cache({}, mocked_cache)+customer_user = User.objects.create_user(email="[email protected]",password="old-password",@@ -93,9 +104,18 @@ def test_set_password_confirm_user_and_match_orders(match_orders_with_new_user_mock.assert_called_once_with(customer_user)-def test_set_password_invalid_token(user_api_client, customer_user):+@patch("saleor.account.throttling.cache")+def test_set_password_invalid_token(+ mocked_cache, user_api_client, customer_user, setup_mock_for_cache+):+ # given+ setup_mock_for_cache({}, mocked_cache)variables = {"email": customer_user.email, "password": "pass", "token": "token"}++ # whenresponse = user_api_client.post_graphql(SET_PASSWORD_MUTATION, variables)++ # thencontent = get_graphql_content(response)errors = content["data"]["setPassword"]["errors"]assert errors[0]["message"] == INVALID_TOKEN@@ -105,9 +125,19 @@ def test_set_password_invalid_token(user_api_client, customer_user):assert account_errors[0]["code"] == AccountErrorCode.INVALID.name-def test_set_password_invalid_email(user_api_client):+@patch("saleor.account.throttling.cache")+def test_set_password_invalid_email(+ mocked_cache, user_api_client, setup_mock_for_cache+):+ # given+ setup_mock_for_cache({}, mocked_cache)+variables = {"email": "[email protected]", "password": "pass", "token": "token"}++ # whenresponse = user_api_client.post_graphql(SET_PASSWORD_MUTATION, variables)++ # thencontent = get_graphql_content(response)errors = content["data"]["setPassword"]["errors"]assert len(errors) == 1@@ -119,8 +149,13 @@ def test_set_password_invalid_email(user_api_client):assert account_errors[0]["code"] == AccountErrorCode.INVALID.name+@patch("saleor.account.throttling.cache")@freeze_time("2018-05-31 12:00:01")-def test_set_password_invalid_password(user_api_client, customer_user, settings):+def test_set_password_invalid_password(+ mocked_cache, user_api_client, customer_user, settings, setup_mock_for_cache+):+ # given+ setup_mock_for_cache({}, mocked_cache)settings.AUTH_PASSWORD_VALIDATORS = [{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",@@ -131,7 +166,11 @@ def test_set_password_invalid_password(user_api_client, customer_user, settings)token = token_generator.make_token(customer_user)variables = {"email": customer_user.email, "password": "1234", "token": token}++ # whenresponse = user_api_client.post_graphql(SET_PASSWORD_MUTATION, variables)++ # thencontent = get_graphql_content(response)errors = content["data"]["setPassword"]["errors"]assert len(errors) == 2diff --git a/saleor/graphql/account/tests/mutations/authentication/test_token_create.py b/saleor/graphql/account/tests/mutations/authentication/test_token_create.pyindex 795aa992b5..0642d9b5f4 100644--- a/saleor/graphql/account/tests/mutations/authentication/test_token_create.py+++ b/saleor/graphql/account/tests/mutations/authentication/test_token_create.py@@ -397,11 +397,18 @@ def test_create_token_email_case_insensitive(assert data["token"]+@patch("saleor.account.throttling.cache")@freeze_time("2020-03-18 12:00:00")def test_create_token_do_not_update_last_login_when_in_threshold(- api_client, customer_user, settings+ mocked_cache,+ api_client,+ customer_user,+ settings,+ setup_mock_for_cache,):# given+ setup_mock_for_cache({}, mocked_cache)+customer_password = customer_user._passwordcustomer_user.last_login = datetime.datetime.now(tz=datetime.UTC)customer_user.save()@@ -423,11 +430,14 @@ def test_create_token_do_not_update_last_login_when_in_threshold(assert customer_user.last_login == expected_last_login+@patch("saleor.account.throttling.cache")@freeze_time("2020-03-18 12:00:00")def test_create_token_do_update_last_login_when_out_of_threshold(- api_client, customer_user, settings+ mocked_cache, api_client, customer_user, settings, setup_mock_for_cache):# given+ setup_mock_for_cache({}, mocked_cache)+customer_password = customer_user._passwordcustomer_user.last_login = datetime.datetime.now(tz=datetime.UTC)customer_user.save()diff --git a/saleor/graphql/core/tests/test_graphql.py b/saleor/graphql/core/tests/test_graphql.pyindex db7bae7365..9fab08f19a 100644--- a/saleor/graphql/core/tests/test_graphql.py+++ b/saleor/graphql/core/tests/test_graphql.py@@ -1,6 +1,6 @@from functools import partialfrom unittest import mock-from unittest.mock import Mock+from unittest.mock import Mock, patchimport grapheneimport pytest@@ -27,7 +27,10 @@ def test_middleware_dont_generate_sql_requests(client, settings, assert_num_querassert response.status_code == 200-def test_jwt_middleware(client, admin_user):+@patch("saleor.account.throttling.cache")+def test_jwt_middleware(mocked_cache, client, admin_user, setup_mock_for_cache):+ setup_mock_for_cache({}, mocked_cache)+# We should't base on `wsgi_request` attribute to check if user is authenticated.# Saleor is ASGI app, also request could be changed after response is returned.user_details_query = """diff --git a/saleor/graphql/tests/test_tracing.py b/saleor/graphql/tests/test_tracing.pyindex c821ce3929..645c539121 100644--- a/saleor/graphql/tests/test_tracing.py+++ b/saleor/graphql/tests/test_tracing.py@@ -308,11 +308,13 @@ def test_tracing_query_identifier_with_fragment(assert span.attributes[saleor_attributes.GRAPHQL_OPERATION_IDENTIFIER] == "products"+@patch("saleor.account.throttling.cache")def test_tracing_query_identifier_for_unnamed_mutation(- staff_api_client,- get_test_spans,+ mocked_cache, staff_api_client, get_test_spans, setup_mock_for_cache):# given+ setup_mock_for_cache({}, mocked_cache)+query = """mutation{tokenCreate(email: "[email protected]", password:"admin"){@@ -331,11 +333,12 @@ def test_tracing_query_identifier_for_unnamed_mutation()+@patch("saleor.account.throttling.cache")def test_tracing_query_identifier_for_named_mutation(- staff_api_client,- get_test_spans,+ mocked_cache, staff_api_client, get_test_spans, setup_mock_for_cache):# given+ setup_mock_for_cache({}, mocked_cache)query = """mutation MutationName{tokenCreate(email: "[email protected]", password:"admin"){@@ -354,11 +357,16 @@ def test_tracing_query_identifier_for_named_mutation()+@patch("saleor.account.throttling.cache")def test_tracing_query_identifier_for_many_mutations(+ mocked_cache,staff_api_client,get_test_spans,+ setup_mock_for_cache,):# given+ setup_mock_for_cache({}, mocked_cache)+query = """mutation {tokenCreate(email: "[email protected]", password:"admin"){