Skip to content

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

Move emails test from test_order to test_emails

Pacu2c7e8e0b3f7c8
diff --git a/tests/test_emails.py b/tests/test_emails.py
index 5dc8528045..f2388f0491 100644
--- a/tests/test_emails.py
+++ b/tests/test_emails.py
@@ -2,10 +2,45 @@ from unittest import mock
import pytest
from django.conf import settings
+from django.contrib.sites.models import Site
import saleor.order.emails as emails
+def test_get_email_context(order):
+ site = Site.objects.get_current()
+ order_url = build_absolute_uri(
+ reverse('order:details', kwargs={'token': order_token}))
+ expected_ctx = {
+ 'protocol': 'https' if settings.ENABLE_SSL else 'http',
+ 'site_name': site.name,
+ 'domain': site.domain,
+ 'url': order_url}
+
+ received_context = emails.get_email_context(order.token)
+ assert expected_context == received_context
+
+
+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_data_for_email(order):
+ template = emails.CONFIRM_PAYMENT_TEMPLATE
+ email_data = emails.collect_data_for_email(order.pk, template)
+ email_context = email_data['context']
+ # Those properties should be present only for order confirmation email
+ assert 'order' not in email_context
+ assert 'schema_markup' not in email_context
+
+
@pytest.mark.parametrize('send_email,template', [
(emails.send_payment_confirmation, emails.CONFIRM_PAYMENT_TEMPLATE),
(emails.send_note_confirmation, emails.CONFIRM_NOTE_TEMPLATE),
diff --git a/tests/test_order.py b/tests/test_order.py
index 1127b0c0d7..94e9e55aea 100644
--- a/tests/test_order.py
+++ b/tests/test_order.py
@@ -1,5 +1,8 @@
from decimal import Decimal
+<<<<<<< HEAD
from unittest.mock import Mock
+=======
+>>>>>>> Move emails test from test_order to test_emails
from django.urls import reverse
from prices import Money, TaxedMoney
@@ -108,7 +111,15 @@ def test_view_connect_order_with_user_authorized_user(
def test_view_connect_order_with_user_different_email(
- order, authorized_client):
+ order, authorized_client, customer_user):
+ """Order was placed from different email, than user's
+ we are trying to assign it to."""
+ order.user = None
+ order.user_email = '[email protected]'
+ order.save()
+
+ assert order.user_email != customer_user.email
+
url = reverse(
'order:connect-order-with-user', kwargs={'token': order.token})
response = authorized_client.post(url)
@@ -136,15 +147,6 @@ def test_create_order_history(order_with_lines):
assert history_entry.content == 'test_entry'
-def test_collect_data_for_email(order):
- template = Mock(spec=str)
- order.user_mail = '[email protected]'
- email_data = collect_data_for_email(order.pk, template)
- order_url = reverse('order:details', kwargs={'token': order.token})
- assert order_url in email_data['url']
- assert email_data['email'] == order.user_email
-
-
def test_restock_order_lines(order_with_lines_and_stock):
order = order_with_lines_and_stock
line_1 = order.lines.first()
@@ -251,3 +253,30 @@ def test_update_order_status(fulfilled_order):
update_order_status(fulfilled_order)
assert fulfilled_order.status == OrderStatus.UNFULFILLED
+
+
+def test_delivery_group_is_shipping_required(delivery_group):
+ assert delivery_group.is_shipping_required()
+
+
+def test_delivery_group_is_shipping_required_no_shipping(delivery_group):
+ line = delivery_group.lines.first()
+ line.is_shipping_required = False
+ line.save()
+ assert not delivery_group.is_shipping_required()
+
+
+def test_delivery_group_is_shipping_required_partially_required(
+ delivery_group, product_without_shipping):
+ variant = product_without_shipping.variants.get()
+ product_type = product_without_shipping.product_type
+ delivery_group.lines.create(
+ delivery_group=delivery_group,
+ product=product_without_shipping,
+ product_name=product_without_shipping.name,
+ product_sku=variant.sku,
+ is_shipping_required=product_type.is_shipping_required,
+ quantity=3,
+ unit_price_net=Decimal('30.00'),
+ unit_price_gross=Decimal('30.00'))
+ assert delivery_group.is_shipping_required()