Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Move prepare_url func from core.emails module to core.utils
IKarbowiakd37617dc2bf1
diff --git a/saleor/account/emails.py b/saleor/account/emails.pyindex 1e1b419a5c..9bfd978e65 100644--- a/saleor/account/emails.py+++ b/saleor/account/emails.py@@ -5,7 +5,8 @@ from templated_email import send_templated_mailfrom ..account import events as account_eventsfrom ..celeryconf import app-from ..core.emails import get_email_context, prepare_url+from ..core.emails import get_email_context+from ..core.utils.url import prepare_urlREQUEST_EMAIL_CHANGE_TEMPLATE = "account/request_email_change"EMAIL_CHANGED_NOTIFICATION_TEMPLATE = "account/email_changed_notification"diff --git a/saleor/core/emails.py b/saleor/core/emails.pyindex 4e147dad6a..54303a41a9 100644--- a/saleor/core/emails.py+++ b/saleor/core/emails.py@@ -1,5 +1,3 @@-from urllib.parse import urlsplit-from django.contrib.sites.models import Site@@ -11,10 +9,3 @@ def get_email_context():"site_name": site.name,}return send_email_kwargs, email_template_context---def prepare_url(params: str, redirect_url: str) -> str:- """Add params to redirect url."""- split_url = urlsplit(redirect_url)- split_url = split_url._replace(query=params)- return split_url.geturl()diff --git a/saleor/core/tests/test_emails.py b/saleor/core/tests/test_emails.pyindex c82a0aa56f..5798e82e2a 100644--- a/saleor/core/tests/test_emails.py+++ b/saleor/core/tests/test_emails.py@@ -1,9 +1,7 @@-from urllib.parse import urlencode-import pytestfrom django.core.exceptions import ImproperlyConfigured-from ..emails import get_email_context, prepare_url+from ..emails import get_email_contextdef test_get_email_context(site_settings):@@ -42,10 +40,3 @@ def test_email_with_email_not_configured_raises_error(settings, site_settings):_ = site_settings.default_from_emailassert exc.value.args == ("No sender email address has been set-up",)---def test_prepare_url():- redirect_url = "https://www.example.com"- params = urlencode({"param1": "abc", "param2": "xyz"})- result = prepare_url(params, redirect_url)- assert result == "https://www.example.com?param1=abc¶m2=xyz"diff --git a/saleor/core/tests/test_url.py b/saleor/core/tests/test_url.pynew file mode 100644index 0000000000..fa2bb62100--- /dev/null+++ b/saleor/core/tests/test_url.py@@ -0,0 +1,10 @@+from urllib.parse import urlencode++from ..utils.url import prepare_url+++def test_prepare_url():+ redirect_url = "https://www.example.com"+ params = urlencode({"param1": "abc", "param2": "xyz"})+ result = prepare_url(params, redirect_url)+ assert result == "https://www.example.com?param1=abc¶m2=xyz"diff --git a/saleor/core/utils/url.py b/saleor/core/utils/url.pyindex 8a8ab526fb..f9fb6c3746 100644--- a/saleor/core/utils/url.py+++ b/saleor/core/utils/url.py@@ -1,4 +1,4 @@-from urllib.parse import urlparse+from urllib.parse import urlparse, urlsplitfrom django.conf import settingsfrom django.core.exceptions import ValidationError@@ -26,3 +26,10 @@ def validate_storefront_url(url):"`ALLOWED_CLIENT_HOSTS` configuration.")raise ValidationError(error_message)+++def prepare_url(params: str, redirect_url: str) -> str:+ """Add params to redirect url."""+ split_url = urlsplit(redirect_url)+ split_url = split_url._replace(query=params)+ return split_url.geturl()diff --git a/saleor/order/emails.py b/saleor/order/emails.pyindex da6926e6af..986182447b 100644--- a/saleor/order/emails.py+++ b/saleor/order/emails.py@@ -4,7 +4,8 @@ from templated_email import send_templated_mailfrom ..account.models import StaffNotificationRecipientfrom ..celeryconf import app-from ..core.emails import get_email_context, prepare_url+from ..core.emails import get_email_context+from ..core.utils.url import prepare_urlfrom ..seo.schema.email import get_order_confirmation_markupfrom . import eventsfrom .models import Fulfillment, Orderdiff --git a/saleor/payment/gateways/adyen/plugin.py b/saleor/payment/gateways/adyen/plugin.pyindex 9615296dbe..0dba8e1835 100644--- a/saleor/payment/gateways/adyen/plugin.py+++ b/saleor/payment/gateways/adyen/plugin.py@@ -10,8 +10,8 @@ from django.http import HttpResponse, HttpResponseNotFoundfrom graphql_relay import from_global_idfrom ....checkout.models import Checkout-from ....core.emails import prepare_urlfrom ....core.utils import build_absolute_uri+from ....core.utils.url import prepare_urlfrom ....plugins.base_plugin import BasePlugin, ConfigurationTypeFieldfrom ... import PaymentError, TransactionKindfrom ...interface import GatewayConfig, GatewayResponse, PaymentData, PaymentGateway