Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Apply small changes related to the expected behaviour (#6987)

Maciej Korycinskif76d0093b450
diff --git a/saleor/order/notifications.py b/saleor/order/notifications.py
index 8799d845cb..0936861eb2 100644
--- a/saleor/order/notifications.py
+++ b/saleor/order/notifications.py
@@ -30,7 +30,7 @@ def get_default_images_payload(images: List[ProductImage]):
first_image_payload = None
first_image = images[0] if images else None
if first_image:
- first_image_payload = ({"original": get_image_payload(first_image)},)
+ first_image_payload = {"original": get_image_payload(first_image)}
images_payload = None
if images:
images_payload = [{"original": get_image_payload(image) for image in images}]
@@ -209,7 +209,7 @@ def get_default_order_payload(order: "Order", redirect_url: str = ""):
order_payload.update(
{
"channel_slug": order.channel.slug,
- "created": order.created,
+ "created": str(order.created),
"shipping_price_net_amount": order.shipping_price_net_amount,
"shipping_price_gross_amount": order.shipping_price_gross_amount,
"order_details_url": order_details_url,
diff --git a/saleor/order/tests/test_notifications.py b/saleor/order/tests/test_notifications.py
index 7af88427df..3df4fbd6e0 100644
--- a/saleor/order/tests/test_notifications.py
+++ b/saleor/order/tests/test_notifications.py
@@ -152,7 +152,7 @@ def test_get_default_order_payload(order_line):
"channel_slug": order.channel.slug,
"id": order.id,
"token": order.token,
- "created": order.created,
+ "created": str(order.created),
"display_gross_prices": order.display_gross_prices,
"currency": order.currency,
"total_gross_amount": order.total_gross_amount,
diff --git a/saleor/plugins/admin_email/plugin.py b/saleor/plugins/admin_email/plugin.py
index 94e99dae1b..e45587d94d 100644
--- a/saleor/plugins/admin_email/plugin.py
+++ b/saleor/plugins/admin_email/plugin.py
@@ -193,7 +193,8 @@ class AdminEmailPlugin(BasePlugin):
username=configuration["username"] or settings.EMAIL_HOST_USER,
password=configuration["password"] or settings.EMAIL_HOST_PASSWORD,
sender_name=configuration["sender_name"],
- sender_address=configuration["sender_address"],
+ sender_address=configuration["sender_address"]
+ or settings.DEFAULT_FROM_EMAIL,
use_tls=configuration["use_tls"] or settings.EMAIL_USE_TLS,
use_ssl=configuration["use_ssl"] or settings.EMAIL_USE_SSL,
)
diff --git a/saleor/plugins/email_common.py b/saleor/plugins/email_common.py
index f136129f28..5d3396bcb8 100644
--- a/saleor/plugins/email_common.py
+++ b/saleor/plugins/email_common.py
@@ -12,8 +12,6 @@ import html2text
import i18naddress
import pybars
from babel.numbers import format_currency
-from django.conf import settings
-from django.contrib.sites.models import Site
from django.core.exceptions import ValidationError
from django.core.mail import send_mail
from django.core.mail.backends.smtp import EmailBackend
@@ -182,17 +180,11 @@ def price(this, net_amount, gross_amount, currency, display_gross=False):
def send_email(
config: EmailConfig, recipient_list, context, subject="", template_str=""
):
- sender_name = config.sender_name
+ sender_name = config.sender_name or ""
sender_address = config.sender_address
- if not sender_address or not sender_name:
- # TODO when we deprecate the default mail config from Site, we can drop this if
- # and require the sender's data as a plugin input or take it from settings file.
- site = Site.objects.get_current()
- sender_name = sender_name or site.settings.default_mail_sender_name
- sender_address = sender_address or site.settings.default_mail_sender_address
- sender_address = sender_address or settings.DEFAULT_FROM_EMAIL
from_email = str(Address(sender_name, addr_spec=sender_address))
+
email_backend = EmailBackend(
host=config.host,
port=config.port,
@@ -268,15 +260,26 @@ def validate_default_email_configuration(plugin_configuration: "PluginConfigurat
}
)
config = EmailConfig(
- host=configuration["host"] or settings.EMAIL_HOST,
- port=configuration["port"] or settings.EMAIL_PORT,
- username=configuration["username"] or settings.EMAIL_HOST_USER,
- password=configuration["password"] or settings.EMAIL_HOST_PASSWORD,
+ host=configuration["host"],
+ port=configuration["port"],
+ username=configuration["username"],
+ password=configuration["password"],
sender_name=configuration["sender_name"],
sender_address=configuration["sender_address"],
use_tls=configuration["use_tls"],
use_ssl=configuration["use_ssl"],
)
+
+ if not config.sender_address:
+ raise ValidationError(
+ {
+ "sender_address": ValidationError(
+ "Missing sender address value.",
+ code=PluginErrorCode.PLUGIN_MISCONFIGURED.value,
+ )
+ }
+ )
+
try:
validate_email_config(config)
except Exception as e: