Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add unit tests
Damian Wysocki03998463fa01
diff --git a/tests/api/test_account.py b/tests/api/test_account.pyindex 9931b60532..69cb1c62a8 100644--- a/tests/api/test_account.py+++ b/tests/api/test_account.py@@ -607,7 +607,10 @@ ACCOUNT_REGISTER_MUTATION = """ENABLE_ACCOUNT_CONFIRMATION_BY_EMAIL=True, ALLOWED_CLIENT_HOSTS=["localhost"])@patch("saleor.account.emails._send_account_confirmation_email")-def test_customer_register(send_account_confirmation_email_mock, api_client):+@patch("saleor.graphql.account.mutations.account.match_orders_with_new_user")+def test_customer_register(+ match_orders_with_new_user_mock, send_account_confirmation_email_mock, api_client+):email = "[email protected]"variables = {"email": email,@@ -633,18 +636,21 @@ def test_customer_register(send_account_confirmation_email_mock, api_client):customer_creation_event = account_events.CustomerEvent.objects.get()assert customer_creation_event.type == account_events.CustomerEvents.ACCOUNT_CREATEDassert customer_creation_event.user == new_user+ assert match_orders_with_new_user_mock.call_count == 0@override_settings(ENABLE_ACCOUNT_CONFIRMATION_BY_EMAIL=False)@patch("saleor.account.emails._send_account_confirmation_email")+@patch("saleor.graphql.account.mutations.account.match_orders_with_new_user")def test_customer_register_disabled_email_confirmation(- send_account_confirmation_email_mock, api_client+ match_orders_with_new_user_mock, send_account_confirmation_email_mock, api_client):variables = {"email": "[email protected]", "password": "Password"}response = 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+ assert match_orders_with_new_user_mock.call_count == 1@override_settings(ENABLE_ACCOUNT_CONFIRMATION_BY_EMAIL=True)diff --git a/tests/test_order_utils.py b/tests/test_order_utils.pyindex 01c75dddbc..799a883e4e 100644--- a/tests/test_order_utils.py+++ b/tests/test_order_utils.py@@ -1,8 +1,8 @@import pytestfrom saleor.order.events import OrderEvents-from saleor.order.models import OrderEvent-from saleor.order.utils import change_order_line_quantity+from saleor.order.models import Order, OrderEvent+from saleor.order.utils import change_order_line_quantity, match_orders_with_new_user@pytest.mark.parametrize(@@ -44,3 +44,20 @@ def test_change_quantity_generates_proper_event({"quantity": expected_quantity, "line_pk": line.pk, "item": str(line)}]}+++def test_match_orders_with_new_user(customer_user):+ def get_order_user_by_customer_email(email):+ return Order.objects.filter(user_email=email).first().user++ customer_email = customer_user.email+ address = customer_user.default_billing_address.get_copy()+ Order.objects.create(+ billing_address=address, user=None, user_email=customer_email,+ )++ assert get_order_user_by_customer_email(customer_email) is None++ match_orders_with_new_user(customer_user)++ assert get_order_user_by_customer_email(customer_email) == customer_user