def test_collect_data_for_email(order): template = Mock(spec=str) order.user_mail = '*****@*****.**' 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_send_confirmation_emails_without_addresses_for_order( mocked_templated_email, order, site_settings, digital_content ): assert not order.lines.count() template = emails.CONFIRM_ORDER_TEMPLATE add_variant_to_draft_order(order, digital_content.product_variant, quantity=1) order.shipping_address = None order.shipping_method = None order.billing_address = None order.save(update_fields=["shipping_address", "shipping_method", "billing_address"]) 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)
def test_send_confirmation_emails_without_addresses(mocked_templated_email, order, template, send_email, settings, digital_content): assert not order.lines.count() add_variant_to_order(order, digital_content.product_variant, quantity=1) order.shipping_address = None order.shipping_method = None order.billing_address = None order.save(update_fields=[ 'shipping_address', 'shipping_method', 'billing_address' ]) send_email(order.pk) email_data = emails.collect_data_for_email(order.pk, template) recipients = [order.get_user_current_email()] expected_call_kwargs = { 'context': email_data['context'], 'from_email': settings.ORDER_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)
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
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
def test_send_confirmation_emails_without_addresses( mocked_templated_email, order, template, send_email, settings, digital_content ): assert not order.lines.count() add_variant_to_order(order, digital_content.product_variant, quantity=1) order.shipping_address = None order.shipping_method = None order.billing_address = None order.save(update_fields=["shipping_address", "shipping_method", "billing_address"]) send_email(order.pk) email_data = emails.collect_data_for_email(order.pk, template) recipients = [order.get_user_current_email()] expected_call_kwargs = { "context": email_data["context"], "from_email": settings.ORDER_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)
def test_send_emails(mocked_templated_email, order, template, send_email): send_email(order.pk) email_data = emails.collect_data_for_email(order.pk, template) mocked_templated_email.assert_called_once_with( recipient_list=[order.get_user_current_email()], context=email_data['context'], from_email=settings.ORDER_FROM_EMAIL, template_name=template)
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_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_send_emails(mocked_templated_email, order, template, send_email): send_email(order.pk) email_data = emails.collect_data_for_email(order.pk, template) email_context = email_data['context'] mocked_templated_email.assert_called_once_with( recipient_list=[order.get_user_current_email()], context=email_context, from_email=settings.ORDER_FROM_EMAIL, template_name=template)
def test_collect_data_for_fulfillment_email(fulfilled_order): template = emails.CONFIRM_FULFILLMENT_TEMPLATE fulfillment = fulfilled_order.fulfillments.first() fulfillment_data = emails.collect_data_for_fulfillment_email( fulfilled_order.pk, template, fulfillment.pk ) email_context = fulfillment_data["context"] assert email_context["fulfillment"] == fulfillment email_data = emails.collect_data_for_email(fulfilled_order.pk, template) assert all([key in email_context for key, item in email_data["context"].items()])
def test_collect_data_for_fullfillment_email(fulfilled_order): template = emails.CONFIRM_FULFILLMENT_TEMPLATE fulfillment = fulfilled_order.fulfillments.first() fulfillment_data = emails.collect_data_for_fullfillment_email( fulfilled_order.pk, template, fulfillment.pk ) email_context = fulfillment_data["context"] assert email_context["fulfillment"] == fulfillment email_data = emails.collect_data_for_email(fulfilled_order.pk, template) assert all([key in email_context for key, item in email_data["context"].items()])
def test_send_emails(mocked_templated_email, order, template, send_email): send_email(order.pk) email_data = emails.collect_data_for_email(order.pk, template) recipients = [order.get_user_current_email()] expected_call_kwargs = { 'context': email_data['context'], 'from_email': settings.ORDER_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)
def test_send_emails(mocked_templated_email, order, template, send_email, settings): send_email(order.pk) email_data = emails.collect_data_for_email(order.pk, template) recipients = [order.get_user_current_email()] expected_call_kwargs = { 'context': email_data['context'], 'from_email': settings.ORDER_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)
def test_send_emails(mocked_templated_email, order, template, send_email, site_settings): send_email(order.pk) email_data = emails.collect_data_for_email(order.pk, template) 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)
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)