Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Merge branch 'master' into drop-storefront-1.0
IKarbowiakec7a508bcc39
diff --cc .isort.cfgindex e2f3326beb,13f594c986..3c89d61a48--- a/.isort.cfg+++ b/.isort.cfg@@@ -1,2 -1,2 +1,2 @@@[settings]- known_third_party = PIL,babel,bleach,bootstrap4,braintree,celery,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,geolite2,google_measurement_protocol,graphene,graphene_django,graphene_django_optimizer,graphene_federation,graphql,graphql_jwt,graphql_relay,html5lib,html_to_draftjs,i18naddress,markdown,measurement,mptt,oauthlib,phonenumber_field,phonenumbers,prices,promise,pytest,razorpay,requests,sentry_sdk,six,social_core,storages,stripe,templated_email,text_unidecode,tqdm,versatileimagefield-known_third_party = PIL,babel,bleach,bootstrap4,braintree,bs4,captcha,celery,dj_database_url,dj_email_url,django,django_babel,django_cache_url,django_countries,django_elasticsearch_dsl,django_filters,django_measurement,django_prices,django_prices_openexchangerates,django_prices_vatlayer,draftjs_sanitizer,elasticsearch_dsl,faker,freezegun,geolite2,google_measurement_protocol,graphene,graphene_django,graphene_django_optimizer,graphene_federation,graphql,graphql_jwt,graphql_relay,html5lib,html_to_draftjs,i18naddress,impersonate,markdown,measurement,mptt,oauthlib,phonenumber_field,phonenumbers,prices,promise,pytest,razorpay,requests,sentry_sdk,six,social_core,storages,stripe,templated_email,text_unidecode,tqdm,versatileimagefield++known_third_party = PIL,babel,bleach,bootstrap4,braintree,celery,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,geolite2,google_measurement_protocol,graphene,graphene_django,graphene_django_optimizer,graphene_federation,graphql,graphql_jwt,graphql_relay,html5lib,html_to_draftjs,i18naddress,jwt,markdown,measurement,mptt,oauthlib,phonenumber_field,phonenumbers,prices,promise,pytest,razorpay,requests,sentry_sdk,six,social_core,storages,stripe,templated_email,text_unidecode,tqdm,versatileimagefielddiff --cc saleor/checkout/utils.pyindex 8b70fdea1d,86190cd769..72c9e8d110--- a/saleor/checkout/utils.py+++ b/saleor/checkout/utils.py@@@ -36,10 -42,16 +36,10 @@@ from ..giftcard.utils importremove_gift_card_code_from_checkout,)from ..order.actions import order_created- from ..order.emails import send_order_confirmation+ from ..order.emails import send_order_confirmation, send_staff_order_confirmationfrom ..order.models import Order, OrderLinefrom ..shipping.models import ShippingMethod-from . import AddressType, logger-from .forms import (- AddressChoiceForm,- AnonymousUserBillingForm,- AnonymousUserShippingForm,- BillingAddressChoiceForm,-)+from . import AddressTypefrom .models import Checkout, CheckoutLineif TYPE_CHECKING:@@@ -742,7 -1204,8 +742,9 @@@ def create_orderorder_created(order=order, user=user)# Send the order confirmation email- send_order_confirmation.delay(order.pk, user.pk)- send_staff_order_confirmation.delay(order.pk)+ send_order_confirmation.delay(order.pk, redirect_url, user.pk)++ send_staff_order_confirmation.delay(order.pk, redirect_url)++return orderdiff --cc saleor/order/emails.pyindex ac97d69a5f,c41e392e48..95104b4aa0--- a/saleor/order/emails.py+++ b/saleor/order/emails.py@@@ -1,9 -1,10 +1,10 @@@-from django.urls import reverse+from urllib.parse import urlencode+from templated_email import send_templated_mail+ from ..account.models import StaffNotificationRecipientfrom ..celeryconf import app-from ..core.emails import get_email_context-from ..core.utils import build_absolute_uri+from ..core.emails import get_email_context, prepare_urlfrom ..seo.schema.email import get_order_confirmation_markupfrom . import eventsfrom .models import Fulfillment, Order@@@ -14,10 -16,14 +16,24 @@@ UPDATE_FULFILLMENT_TEMPLATE = "order/upCONFIRM_PAYMENT_TEMPLATE = "order/payment/confirm_payment"-def collect_data_for_email(order_pk, template):- """Collect the required data for sending emails.++def collect_staff_order_notification_data(++ order_pk: int, template: str, redirect_url: str++) -> dict:++ data = collect_data_for_email(order_pk, template, redirect_url)++ staff_notifications = StaffNotificationRecipient.objects.filter(++ active=True, user__is_active=True, user__is_staff=True++ )++ recipient_emails = [++ notification.get_email() for notification in staff_notifications++ ]++ data["recipient_list"] = recipient_emails++ return data+- Args:- order_pk (int): order primary key- template (str): email template path+- """+def collect_data_for_email(+ order_pk: int, template: str, redirect_url: str = ""+) -> dict:+ """Collect the required data for sending emails."""order = Order.objects.get(pk=order_pk)recipient_email = order.get_customer_email()send_kwargs, email_context = get_email_context()@@@ -28,7 -33,7 +44,7 @@@email_context["order"] = order# Order confirmation template requires additional information-- if template == CONFIRM_ORDER_TEMPLATE:++ if template in [CONFIRM_ORDER_TEMPLATE, STAFF_CONFIRM_ORDER_TEMPLATE]:email_markup = get_order_confirmation_markup(order)email_context["schema_markup"] = email_markup@@@ -75,6 -106,16 +91,16 @@@ def send_order_confirmation(order_pk, r)+ @app.task-def send_staff_order_confirmation(order_pk):++def send_staff_order_confirmation(order_pk, redirect_url):+ """Send order confirmation email."""+ staff_email_data = collect_staff_order_notification_data(- order_pk, STAFF_CONFIRM_ORDER_TEMPLATE++ order_pk, STAFF_CONFIRM_ORDER_TEMPLATE, redirect_url+ )+ if staff_email_data["recipient_list"]:+ send_templated_mail(**staff_email_data)++@app.taskdef send_fulfillment_confirmation(order_pk, fulfillment_pk):email_data = collect_data_for_fullfillment_email(diff --cc saleor/urls.pyindex ed16605614,1967fb84eb..4be73eb4a9--- a/saleor/urls.py+++ b/saleor/urls.py@@@ -8,19 -10,46 +8,21 @@@ from django.views.generic.base import Rfrom .data_feeds.urls import urlpatterns as feed_urlsfrom .graphql.api import schemafrom .graphql.views import GraphQLView-from .order.urls import urlpatterns as order_urls-from .page.urls import urlpatterns as page_urls-from .product.urls import urlpatterns as product_urls-from .search.urls import urlpatterns as search_urls+from .product.views import digital_product-handler404 = "saleor.core.views.handle_404"--non_translatable_urlpatterns = [+urlpatterns = [url(r"^graphql/", csrf_exempt(GraphQLView.as_view(schema=schema)), name="api"),+ url(r"^feeds/", include((feed_urls, "data_feeds"), namespace="data_feeds")),url(- r"^sitemap\.xml$",- sitemap,- {"sitemaps": sitemaps},- name="django.contrib.sitemaps.views.sitemap",+ r"^digital-download/(?P<token>[0-9A-Za-z_\-]+)/$",+ digital_product,+ name="digital-product",),- url(r"^i18n/$", set_language, name="set_language"),- url("", include("social_django.urls", namespace="social")),-]--translatable_urlpatterns = [- url(r"^", include(core_urls)),- url(r"^checkout/", include((checkout_urls, "checkout"), namespace="checkout")),- url(r"^jsi18n/$", JavaScriptCatalog.as_view(), name="javascript-catalog"),- url(r"^order/", include((order_urls, "order"), namespace="order")),- url(r"^page/", include((page_urls, "page"), namespace="page")),- url(r"^products/", include((product_urls, "product"), namespace="product")),- url(r"^account/", include((account_urls, "account"), namespace="account")),- url(r"^feeds/", include((feed_urls, "data_feeds"), namespace="data_feeds")),- url(r"^search/", include((search_urls, "search"), namespace="search")),]-urlpatterns = non_translatable_urlpatterns + i18n_patterns(*translatable_urlpatterns)-if settings.DEBUG:+ import warnings+try:import debug_toolbarexcept ImportError:diff --cc tests/test_account.pyindex 9cc1b89618,7497e46feb..b065732929--- a/tests/test_account.py+++ b/tests/test_account.py@@@ -3,13 -4,24 +3,14 @@@ from urllib.parse import urlencodimport i18naddressimport pytest-from captcha import constants as recaptcha_constants-from captcha.client import RecaptchaResponse-from django.contrib.auth.tokens import default_token_generator-from django.core import mailfrom django.core.exceptions import ValidationErrorfrom django.core.files import File-from django.forms import Formfrom django.http import QueryDictfrom django.template import Context, Template-from django.templatetags.static import static-from django.urls import reverse-from django.utils.encoding import force_bytes-from django.utils.http import urlsafe_base64_encodefrom django_countries.fields import Country-from templated_email import send_templated_mailfrom saleor.account import forms, i18n-from saleor.account.forms import FormWithReCaptcha, NameForm++from saleor.account.i18n import AddressFormfrom saleor.account.models import Userfrom saleor.account.templatetags.i18n_address_tags import format_addressfrom saleor.account.utils import (diff --cc tests/test_emails.pyindex 38f69cc0fa,1f93f8e0b1..7a433a1649--- a/tests/test_emails.py+++ b/tests/test_emails.py@@@ -84,33 -95,50 +84,74 @@@ def test_send_email_payment_confirmatioemail_connection.get_email_message(to=recipients, **expected_call_kwargs)+ @mock.patch("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)++ emails.send_staff_order_confirmation(order.pk, "http://www.example.com/")+ mocked_templated_email.assert_not_called()+++ @mock.patch("saleor.order.emails.send_templated_mail")+ def test_send_staff_emails(+ mocked_templated_email, order, site_settings, staff_notification_recipient+ ):- emails.send_staff_order_confirmation(order.pk)++ emails.send_staff_order_confirmation(order.pk, "http://www.example.com/")+ email_data = emails.collect_staff_order_notification_data(+ order.pk, emails.STAFF_CONFIRM_ORDER_TEMPLATE+ )++ 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)+++ @pytest.mark.parametrize(+ "send_email,template",+ [+ (emails.send_payment_confirmation, emails.CONFIRM_PAYMENT_TEMPLATE),+ (emails.send_order_confirmation, emails.CONFIRM_ORDER_TEMPLATE),+ ],+ )@mock.patch("saleor.order.emails.send_templated_mail")-def test_send_confirmation_emails_without_addresses(- mocked_templated_email, order, template, send_email, site_settings, digital_content+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()