Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix tests
Tomasz Szymanskif88b6c97ed22
diff --git a/.isort.cfg b/.isort.cfgindex 832d561519..1cdc05d770 100644--- a/.isort.cfg+++ b/.isort.cfg@@ -1,2 +1,2 @@[settings]-known_third_party = Adyen,PIL,authorizenet,babel,boto3,braintree,celery,dateutil,dj_database_url,dj_email_url,django,django_cache_url,django_countries,django_filters,django_measurement,django_prices,django_prices_openexchangerates,django_prices_vatlayer,draftjs_sanitizer,faker,freezegun,google,google_measurement_protocol,graphene,graphene_django,graphene_federation,graphql,graphql_relay,html2text,html_to_draftjs,i18naddress,jaeger_client,jwt,kombu,lxml,markdown,measurement,micawber,mptt,oauthlib,openpyxl,opentracing,petl,phonenumber_field,phonenumbers,pkg_resources,prices,promise,pybars,pytest,pythonjsonlogger,pytimeparse,pytz,razorpay,requests,sendgrid,sentry_sdk,storages,stripe,templated_email,tqdm,urllib3,versatileimagefield,weasyprint+known_third_party = Adyen,PIL,authorizenet,babel,boto3,braintree,celery,dateutil,dj_database_url,dj_email_url,django,django_cache_url,django_countries,django_filters,django_measurement,django_prices,django_prices_openexchangerates,django_prices_vatlayer,draftjs_sanitizer,faker,freezegun,google,google_measurement_protocol,graphene,graphene_django,graphene_federation,graphql,graphql_relay,html2text,html_to_draftjs,i18naddress,jaeger_client,jwt,kombu,lxml,markdown,measurement,micawber,mptt,oauthlib,openpyxl,opentracing,petl,phonenumber_field,phonenumbers,pkg_resources,prices,promise,pybars,pytest,pythonjsonlogger,pytimeparse,pytz,razorpay,requests,sendgrid,sentry_sdk,storages,stripe,tqdm,urllib3,versatileimagefield,weasyprintdiff --git a/saleor/order/tests/test_emails.py b/saleor/order/tests/test_emails.pydeleted file mode 100644index 6981815b73..0000000000--- a/saleor/order/tests/test_emails.py+++ /dev/null@@ -1,428 +0,0 @@-from decimal import Decimal-from unittest import mock--from templated_email import get_connection--from ...invoice import emails as invoice_emails-from ...invoice.models import Invoice-from ...order import OrderEvents-from ...order import emails as emails-from ...plugins.manager import get_plugins_manager-from ..utils import add_variant_to_order---def test_collect_data_for_order_confirmation_email(order):- """Order confirmation email requires extra data, which should be present- in email's context.- """- template = emails.CONFIRM_ORDER_TEMPLATE- email_data = emails.collect_data_for_email(order.pk, template)- email_context = email_data["context"]- assert email_context["order"] == order- assert "schema_markup" in email_context---def test_collect_invoice_data_for_email(order):- number = "01/12/2020/TEST"- url = "http://www.example.com"- invoice = Invoice.objects.create(number=number, url=url, order=order)- email_data = invoice_emails.collect_invoice_data_for_email(- invoice, "order/send_invoice"- )- email_context = email_data["context"]- assert email_context["number"] == number- assert email_context["download_url"] == url- assert email_data["recipient_list"] == [order.user.email]---def test_collect_data_for_fulfillment_email(fulfilled_order):- template = emails.CONFIRM_FULFILLMENT_TEMPLATE- fulfillment = fulfilled_order.fulfillments.first()- fulfillment_data = emails.collect_data_for_fulfillment_email(- fulfilled_order.pk, template, fulfillment.pk- )- email_context = fulfillment_data["context"]- assert email_context["fulfillment"] == fulfillment- email_data = emails.collect_data_for_email(fulfilled_order.pk, template)- assert all([key in email_context for key, item in email_data["context"].items()])---def test_collect_data_for_email(order):- template = emails.CONFIRM_PAYMENT_TEMPLATE- email_data = emails.collect_data_for_email(order.pk, template)- email_context = email_data["context"]- # This properties should be present only for order confirmation email- assert "schema_markup" not in email_context--[email protected]("saleor.order.emails.send_templated_mail")-def test_send_email_payment_confirmation(mocked_templated_email, order, site_settings):- template = emails.CONFIRM_PAYMENT_TEMPLATE- emails.send_payment_confirmation(order.pk)- email_data = emails.collect_data_for_email(order.pk, template)-- recipients = [order.get_customer_email()]-- expected_call_kwargs = {- "context": email_data["context"],- "from_email": site_settings.default_from_email,- "template_name": template,- }-- mocked_templated_email.assert_called_once_with(- recipient_list=recipients, **expected_call_kwargs- )-- # Render the email to ensure there is no error- email_connection = get_connection()- email_connection.get_email_message(to=recipients, **expected_call_kwargs)--[email protected]("saleor.order.emails.send_templated_mail")-def test_send_staff_emails_without_notification_recipient(- mocked_templated_email, order, site_settings-):- emails.send_staff_order_confirmation(order.pk, "http://www.example.com/")- mocked_templated_email.assert_not_called()--[email protected]("saleor.order.emails.send_templated_mail")-def test_send_staff_emails(- mocked_templated_email, order, site_settings, staff_notification_recipient-):- redirect_url = "http://www.example.com/"- emails.send_staff_order_confirmation(order.pk, redirect_url)- email_data = emails.collect_staff_order_notification_data(- order.pk, emails.STAFF_CONFIRM_ORDER_TEMPLATE, redirect_url- )-- recipients = [staff_notification_recipient.get_email()]-- expected_call_kwargs = {- "context": email_data["context"],- "from_email": site_settings.default_from_email,- "template_name": emails.STAFF_CONFIRM_ORDER_TEMPLATE,- }-- mocked_templated_email.assert_called_once_with(- recipient_list=recipients, **expected_call_kwargs- )-- # Render the email to ensure there is no error- email_connection = get_connection()- email_connection.get_email_message(to=recipients, **expected_call_kwargs)--[email protected]("saleor.order.emails.send_templated_mail")-def test_send_email_order_confirmation(mocked_templated_email, order, site_settings):- template = emails.CONFIRM_ORDER_TEMPLATE- redirect_url = "https://www.example.com"- emails.send_order_confirmation(order.pk, redirect_url)- email_data = emails.collect_data_for_email(order.pk, template, redirect_url)-- recipients = [order.get_customer_email()]-- expected_call_kwargs = {- "context": email_data["context"],- "from_email": site_settings.default_from_email,- "template_name": template,- }-- mocked_templated_email.assert_called_once_with(- recipient_list=recipients, **expected_call_kwargs- )-- # Render the email to ensure there is no error- email_connection = get_connection()- email_connection.get_email_message(to=recipients, **expected_call_kwargs)--[email protected]("saleor.order.emails.send_templated_mail")-def test_send_confirmation_emails_without_addresses_for_payment(- mocked_templated_email, order, site_settings, digital_content-):-- assert not order.lines.count()-- template = emails.CONFIRM_PAYMENT_TEMPLATE- manager = get_plugins_manager()- add_variant_to_order(- order, digital_content.product_variant, quantity=1, manager=manager- )- order.shipping_address = None- order.shipping_method = None- order.billing_address = None- order.save(update_fields=["shipping_address", "shipping_method", "billing_address"])-- emails.send_payment_confirmation(order.pk)- email_data = emails.collect_data_for_email(order.pk, template)-- recipients = [order.get_customer_email()]-- expected_call_kwargs = {- "context": email_data["context"],- "from_email": site_settings.default_from_email,- "template_name": template,- }-- mocked_templated_email.assert_called_once_with(- recipient_list=recipients, **expected_call_kwargs- )-- # Render the email to ensure there is no error- email_connection = get_connection()- email_connection.get_email_message(to=recipients, **expected_call_kwargs)--[email protected]("saleor.order.emails.send_templated_mail")-def test_send_confirmation_emails_without_addresses_for_order(- mocked_templated_email, order, site_settings, digital_content-):-- assert not order.lines.count()-- template = emails.CONFIRM_ORDER_TEMPLATE- manager = get_plugins_manager()- add_variant_to_order(- order, digital_content.product_variant, quantity=1, manager=manager- )- order.shipping_address = None- order.shipping_method = None- order.billing_address = None- order.save(update_fields=["shipping_address", "shipping_method", "billing_address"])-- redirect_url = "https://www.example.com"- emails.send_order_confirmation(order.pk, redirect_url)- email_data = emails.collect_data_for_email(order.pk, template, redirect_url)-- recipients = [order.get_customer_email()]-- expected_call_kwargs = {- "context": email_data["context"],- "from_email": site_settings.default_from_email,- "template_name": template,- }-- mocked_templated_email.assert_called_once_with(- recipient_list=recipients, **expected_call_kwargs- )-- # Render the email to ensure there is no error- email_connection = get_connection()- email_connection.get_email_message(to=recipients, **expected_call_kwargs)--[email protected]("saleor.order.emails.send_templated_mail")-def test_send_fulfillment_email_confirmation(- mocked_templated_email, fulfilled_order, site_settings-):- template = emails.CONFIRM_FULFILLMENT_TEMPLATE- redirect_url = "http://localhost.pl"- order = fulfilled_order- fulfillment = order.fulfillments.first()- order.redirect_url = redirect_url- order.save()- emails.send_fulfillment_confirmation(- order_pk=fulfilled_order.pk,- fulfillment_pk=fulfillment.pk,- redirect_url=redirect_url,- )-- email_data = emails.collect_data_for_fulfillment_email(- fulfilled_order.pk, template, fulfillment.pk, redirect_url- )-- recipients = [fulfilled_order.get_customer_email()]-- expected_call_kwargs = {- "context": email_data["context"],- "from_email": site_settings.default_from_email,- "template_name": template,- }- mocked_templated_email.assert_called_once_with(- recipient_list=recipients, **expected_call_kwargs- )-- # Render the email to ensure there is no error- email_connection = get_connection()- email_connection.get_email_message(to=recipients, **expected_call_kwargs)--[email protected]("saleor.order.emails.send_templated_mail")-def test_send_fulfillment_email_update(- mocked_templated_email, fulfilled_order, site_settings-):- template = emails.UPDATE_FULFILLMENT_TEMPLATE- order = fulfilled_order- fulfillment = order.fulfillments.first()- emails.send_fulfillment_update(- order_pk=fulfilled_order.pk, fulfillment_pk=fulfillment.pk- )-- email_data = emails.collect_data_for_fulfillment_email(- fulfilled_order.pk, template, fulfillment.pk- )-- recipients = [fulfilled_order.get_customer_email()]-- expected_call_kwargs = {- "context": email_data["context"],- "from_email": site_settings.default_from_email,- "template_name": template,- }- mocked_templated_email.assert_called_once_with(- recipient_list=recipients, **expected_call_kwargs- )-- # Render the email to ensure there is no error- email_connection = get_connection()- email_connection.get_email_message(to=recipients, **expected_call_kwargs)--[email protected]("saleor.order.emails.send_templated_mail")-def test_send_fulfillment_emails_with_tracking_number_as_url(- mocked_templated_email, fulfilled_order, site_settings-):- template = emails.UPDATE_FULFILLMENT_TEMPLATE- fulfillment = fulfilled_order.fulfillments.first()- fulfillment.tracking_number = "https://www.example.com"- fulfillment.save()- assert fulfillment.is_tracking_number_url- emails.send_fulfillment_update(- order_pk=fulfilled_order.pk, fulfillment_pk=fulfillment.pk- )- email_data = emails.collect_data_for_fulfillment_email(- fulfilled_order.pk, template, fulfillment.pk- )-- recipients = [fulfilled_order.get_customer_email()]-- expected_call_kwargs = {- "context": email_data["context"],- "from_email": site_settings.default_from_email,- "template_name": template,- }-- mocked_templated_email.assert_called_once_with(- recipient_list=recipients, **expected_call_kwargs- )-- # Render the email to ensure there is no error- email_connection = get_connection()- email_connection.get_email_message(to=recipients, **expected_call_kwargs)--[email protected]("saleor.order.emails.send_templated_mail")-def test_send_fulfillment_email_confirmation_with_tracking_number_as_url(- mocked_templated_email, fulfilled_order, site_settings-):- template = emails.CONFIRM_FULFILLMENT_TEMPLATE- redirect_url = "http://localhost.pl"- order = fulfilled_order- fulfillment = order.fulfillments.first()- fulfillment.tracking_number = "https://www.example.com"- fulfillment.save()- order.redirect_url = redirect_url- order.save()-- assert fulfillment.is_tracking_number_url- emails.send_fulfillment_confirmation(- order_pk=fulfilled_order.pk, fulfillment_pk=fulfillment.pk, redirect_url=""- )- email_data = emails.collect_data_for_fulfillment_email(- fulfilled_order.pk, template, fulfillment.pk- )-- recipients = [fulfilled_order.get_customer_email()]-- expected_call_kwargs = {- "context": email_data["context"],- "from_email": site_settings.default_from_email,- "template_name": template,- }-- mocked_templated_email.assert_called_once_with(- recipient_list=recipients, **expected_call_kwargs- )-- # Render the email to ensure there is no error- email_connection = get_connection()- email_connection.get_email_message(to=recipients, **expected_call_kwargs)--[email protected]("saleor.order.emails.send_templated_mail")-def test_send_email_order_canceled(mocked_templated_email, order, site_settings):- # given- template = emails.ORDER_CANCEl_TEMPLATE-- # when- emails.send_order_canceled(order.pk)-- # then- email_data = emails.collect_data_for_email(order.pk, template)- recipients = [order.get_customer_email()]- expected_call_kwargs = {- "context": email_data["context"],- "from_email": site_settings.default_from_email,- "template_name": template,- }-- mocked_templated_email.assert_called_once_with(- recipient_list=recipients, **expected_call_kwargs- )-- # Render the email to ensure there is no error- email_connection = get_connection()- email_connection.get_email_message(to=recipients, **expected_call_kwargs)--[email protected]("saleor.order.emails.send_templated_mail")-def test_send_email_order_refunded(mocked_templated_email, order, site_settings):- # given- template = emails.ORDER_REFUND_TEMPLATE- amount = order.total.gross.amount-- # when- emails.send_order_refunded(order.pk, amount, order.currency)-- # then- email_data = emails.collect_data_for_email(order.pk, template)- email_data["context"].update({"amount": amount, "currency": order.currency})- recipients = [order.get_customer_email()]- expected_call_kwargs = {- "context": email_data["context"],- "from_email": site_settings.default_from_email,- "template_name": template,- }-- mocked_templated_email.assert_called_once_with(- recipient_list=recipients, **expected_call_kwargs- )-- # Render the email to ensure there is no error- email_connection = get_connection()- email_connection.get_email_message(to=recipients, **expected_call_kwargs)--[email protected]("saleor.order.emails.send_order_refunded.delay")-def test_send_order_refunded_confirmation(send_order_refunded_mock, order):- # when- emails.send_order_refunded_confirmation(order, order.user, Decimal(5), "USD")-- # then- send_order_refunded_mock.assert_called_once_with(order.pk, Decimal(5), "USD")-- order_event = order.events.last()- assert order_event.type == OrderEvents.EMAIL_SENT--[email protected]("saleor.order.emails.send_order_canceled.delay")-def test_send_order_canceled_confirmation(send_order_canceled_mock, order):- # when- emails.send_order_canceled_confirmation(order, order.user)-- # then- send_order_canceled_mock.assert_called_once_with(order.pk)-- order_event = order.events.last()- assert order_event.type == OrderEvents.EMAIL_SENTdiff --git a/saleor/order/tests/test_notifications.py b/saleor/order/tests/test_notifications.pyindex d6e4cb832a..eea8e9863b 100644--- a/saleor/order/tests/test_notifications.py+++ b/saleor/order/tests/test_notifications.py@@ -17,7 +17,7 @@ from ..notifications import (get_default_order_payload,get_order_line_payload,)-from ..utils import add_variant_to_draft_order+from ..utils import add_variant_to_orderdef test_get_order_line_payload(order_line):@@ -267,7 +267,7 @@ def test_send_confirmation_emails_without_addresses_for_payment(order = payment_dummy.ordermanager = get_plugins_manager()- line = add_variant_to_draft_order(+ line = add_variant_to_order(order, digital_content.product_variant, quantity=1, manager=manager)DigitalContentUrl.objects.create(content=digital_content, line=line)@@ -306,7 +306,7 @@ def test_send_confirmation_emails_without_addresses_for_order(assert not order.lines.count()manager = get_plugins_manager()- line = add_variant_to_draft_order(+ line = add_variant_to_order(order, digital_content.product_variant, quantity=1, manager=manager)DigitalContentUrl.objects.create(content=digital_content, line=line)