Skip to content

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

Url name unification, test refactor

TOMEKc9a9f8c41e35
diff --git a/saleor/account/emails.py b/saleor/account/emails.py
index 30add6dbee..9ed0bc8028 100644
--- a/saleor/account/emails.py
+++ b/saleor/account/emails.py
@@ -29,7 +29,7 @@ def send_account_delete_confirmation_email(token, recipient_email):
delete_url = build_absolute_uri(
reverse('account:delete-confirm', kwargs={'token': token}))
ctx = get_email_base_context()
- ctx['url'] = delete_url
+ ctx['delete_url'] = delete_url
send_templated_mail(
template_name='account/account_delete',
from_email=settings.DEFAULT_FROM_EMAIL,
diff --git a/saleor/dashboard/emails.py b/saleor/dashboard/emails.py
index ec3fff5e0a..88f1baba44 100644
--- a/saleor/dashboard/emails.py
+++ b/saleor/dashboard/emails.py
@@ -30,7 +30,7 @@ def send_set_password_email(staff):
@shared_task
def send_promote_customer_to_staff_email(staff):
ctx = get_email_base_context()
- ctx['url'] = build_absolute_uri(reverse('dashboard:index'))
+ ctx['dashboard_url'] = build_absolute_uri(reverse('dashboard:index'))
send_templated_mail(
template_name='dashboard/staff/promote_customer',
from_email=settings.DEFAULT_FROM_EMAIL,
diff --git a/saleor/order/emails.py b/saleor/order/emails.py
index 57bfc48412..1842edfd85 100644
--- a/saleor/order/emails.py
+++ b/saleor/order/emails.py
@@ -25,7 +25,7 @@ def collect_data_for_email(order_pk, template):
order = Order.objects.get(pk=order_pk)
recipient_email = order.get_user_current_email()
email_context = get_email_base_context()
- email_context['url'] = build_absolute_uri(
+ email_context['order_details_url'] = build_absolute_uri(
reverse('order:details', kwargs={'token': order.token}))
# Order confirmation template requires additional information
diff --git a/templates/templated_email/account/account_delete.email b/templates/templated_email/account/account_delete.email
index aa640ac19c..b86171faf1 100644
--- a/templates/templated_email/account/account_delete.email
+++ b/templates/templated_email/account/account_delete.email
@@ -14,7 +14,7 @@ Click the link below to delete your account.
Please note that this action is permanent and cannot be reversed.
{% endblocktrans %}
-{{ url }}
+{{ delete_url }}
This is an automatically generated email, please do not reply.
diff --git a/templates/templated_email/order/confirm_order.email b/templates/templated_email/order/confirm_order.email
index 12dcae3ca5..47215ef752 100644
--- a/templates/templated_email/order/confirm_order.email
+++ b/templates/templated_email/order/confirm_order.email
@@ -11,7 +11,7 @@
Hi!
Thank you for your order. Below is the list of ordered products. To see your payment details please visit:
-{{ url }}{% endblocktrans %}
+{{ order_details_url }}{% endblocktrans %}
{% for line in order %}
{{ line.quantity }} x {{ line.product_name }}, {% price line.get_total display_gross=order.display_gross_prices html=False %}
{% endfor %}
diff --git a/templates/templated_email/order/payment/confirm_payment.email b/templates/templated_email/order/payment/confirm_payment.email
index e46595464c..04ef41fb24 100644
--- a/templates/templated_email/order/payment/confirm_payment.email
+++ b/templates/templated_email/order/payment/confirm_payment.email
@@ -9,7 +9,7 @@
Hi!
Thank you for your payment. To see your payment details please visit:
-{{ url }}
+{{ order_details_url }}
This is an automatically generated email, please do not reply.
diff --git a/templates/templated_email/source/account_delete.mjml b/templates/templated_email/source/account_delete.mjml
index 9c22799dee..eaab16713a 100644
--- a/templates/templated_email/source/account_delete.mjml
+++ b/templates/templated_email/source/account_delete.mjml
@@ -21,7 +21,7 @@
{% endblocktrans %}
</mj-text>
<mj-text>
- <a href="{{ url }}">{{ url }}</a>
+ <a href="{{ delete_url }}">{{ delete_url }}</a>
</mj-text>
</mj-column>
</mj-section>
diff --git a/templates/templated_email/source/confirm_note.mjml b/templates/templated_email/source/confirm_note.mjml
index 4ca41ead93..581af91d26 100644
--- a/templates/templated_email/source/confirm_note.mjml
+++ b/templates/templated_email/source/confirm_note.mjml
@@ -14,7 +14,7 @@
</mj-text>
<mj-text>
{% blocktrans trimmed context "Note confirmation e-mail text" %}
- A new note has been added to your order. To see details please visit: <a href="{{ url }}">{{ url }}</a>
+ A new note has been added to your order. To see details please visit: <a href="{{ order_details_url }}">{{ order_details_url }}</a>
{% endblocktrans %}
</mj-text>
</mj-column>
diff --git a/templates/templated_email/source/confirm_order.mjml b/templates/templated_email/source/confirm_order.mjml
index e92455d62e..eef4bda002 100644
--- a/templates/templated_email/source/confirm_order.mjml
+++ b/templates/templated_email/source/confirm_order.mjml
@@ -15,7 +15,7 @@
</mj-text>
<mj-text>
{% blocktrans trimmed context "Order confirmation e-mail text" %}
- Thank you for your order. Below is the list of ordered products. To see your payment details please visit: <a href="{{ url }}">{{ url }}</a>
+ Thank you for your order. Below is the list of ordered products. To see your payment details please visit: <a href="{{ order_details_url }}">{{ order_details_url }}</a>
{% endblocktrans %}
</mj-text>
</mj-column>
diff --git a/templates/templated_email/source/confirm_payment.mjml b/templates/templated_email/source/confirm_payment.mjml
index 0e93b68adb..da1cf07a5f 100644
--- a/templates/templated_email/source/confirm_payment.mjml
+++ b/templates/templated_email/source/confirm_payment.mjml
@@ -14,7 +14,7 @@
</mj-text>
<mj-text>
{% blocktrans trimmed context "Payment confirmation e-mail text" %}
- Thank you for your payment. To see your payment details please visit: <a href="{{ url }}">{{ url }}</a>
+ Thank you for your payment. To see your payment details please visit: <a href="{{ order_details_url }}">{{ order_details_url }}</a>
{% endblocktrans %}
</mj-text>
</mj-column>
diff --git a/templates/templated_email/source/promote_customer.mjml b/templates/templated_email/source/promote_customer.mjml
index b6eb8bc37b..39cb2c1048 100644
--- a/templates/templated_email/source/promote_customer.mjml
+++ b/templates/templated_email/source/promote_customer.mjml
@@ -15,7 +15,7 @@
<mj-text>
{% blocktrans trimmed context "Promote customer to staff member confirmation e-mail text" %}
You're receiving this e-mail because you have been promoted to staff member at {{ domain }}.<br/>
- To access dashboard please visit: <a href="{{ url }}">{{ url }}</a>
+ To access dashboard please visit: <a href="{{ dashboard_url }}">{{ dashboard_url }}</a>
{% endblocktrans %}
</mj-text>
</mj-column>
diff --git a/tests/test_core.py b/tests/test_core.py
index c697899fa9..96a78050e4 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -301,12 +301,17 @@ def test_convert_weight():
weight = Weight(kg=1)
expected_result = Weight(g=1000)
assert convert_weight(weight, WeightUnits.GRAM) == expected_result
-
+
+
def test_build_absolute_uri(site_settings):
+ # Case when we are using external service for storing static files,
+ # eg. Amazon s3
url = 'https://example.com/static/images/image.jpg'
+ assert build_absolute_uri(location=url) == url
+
+ # Case when static url is resolved to relative url
logo_url = build_absolute_uri(static('images/logo-document.svg'))
protocol = 'https' if settings.ENABLE_SSL else 'http'
current_url = '%s://%s' % (protocol, site_settings.site.domain)
logo_location = urljoin(current_url, static('images/logo-document.svg'))
- assert build_absolute_uri(location=url) == url
assert logo_url == logo_location