def test_send_fulfillment_emails_with_tracking_number_as_url(
    mocked_templated_email, template, send_email, fulfilled_order, site_settings
):
    fulfillment = fulfilled_order.fulfillments.first()
    fulfillment.tracking_number = "https://www.example.com"
    fulfillment.save()
    assert fulfillment.is_tracking_number_url
    send_email(order_pk=fulfilled_order.pk, fulfillment_pk=fulfillment.pk)
    email_data = emails.collect_data_for_fulfillment_email(
        fulfilled_order.pk, template, fulfillment.pk
    )

    recipients = [fulfilled_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_class_name_omitted(self):
        klass = 'templated_email.backends.vanilla_django'

        connection = get_connection(klass)

        self.assertIsInstance(connection,
                              backends.vanilla_django.TemplateBackend)
Beispiel #3
0
def test_send_fulfillment_email_update(
    mocked_templated_email, fulfilled_order, site_settings
):
    template = emails.UPDATE_FULFILLMENT_TEMPLATE
    order = fulfilled_order
    fulfillment = order.fulfillments.first()
    emails.send_fulfillment_update(
        order_pk=fulfilled_order.pk, fulfillment_pk=fulfillment.pk
    )

    email_data = emails.collect_data_for_fulfillment_email(
        fulfilled_order.pk, template, fulfillment.pk
    )

    recipients = [fulfilled_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)
Beispiel #4
0
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_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)
Beispiel #6
0
def test_send_fulfillment_email_confirmation_with_tracking_number_as_url(
    mocked_templated_email, fulfilled_order, site_settings
):
    template = emails.CONFIRM_FULFILLMENT_TEMPLATE
    redirect_url = "http://localhost.pl"
    order = fulfilled_order
    fulfillment = order.fulfillments.first()
    fulfillment.tracking_number = "https://www.example.com"
    fulfillment.save()
    order.redirect_url = redirect_url
    order.save()

    assert fulfillment.is_tracking_number_url
    emails.send_fulfillment_confirmation(
        order_pk=fulfilled_order.pk, fulfillment_pk=fulfillment.pk, redirect_url=""
    )
    email_data = emails.collect_data_for_fulfillment_email(
        fulfilled_order.pk, template, fulfillment.pk
    )

    recipients = [fulfilled_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)
Beispiel #7
0
def test_send_email_order_refunded(mocked_templated_email, order, site_settings):
    # given
    template = emails.ORDER_REFUND_TEMPLATE
    amount = order.total.gross.amount

    # when
    emails.send_order_refunded(order.pk, amount, order.currency)

    # then
    email_data = emails.collect_data_for_email(order.pk, template)
    email_data["context"].update({"amount": amount, "currency": order.currency})
    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)
Beispiel #8
0
def test_send_email_changed_notification(
    mocked_templated_email, site_settings, customer_user
):
    old_email = "*****@*****.**"
    template = account_emails.EMAIL_CHANGED_NOTIFICATION_TEMPLATE
    account_emails.send_user_change_email_notification(old_email)
    ctx = {
        "domain": "mirumee.com",
        "site_name": "mirumee.com",
    }
    recipients = [old_email]

    expected_call_kwargs = {
        "context": ctx,
        "from_email": site_settings.default_from_email,
        "template_name": template,
    }

    # mocked_templated_email.assert_called_once()
    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)
Beispiel #9
0
    def test_class_name(self):
        klass = 'templated_email.backends.vanilla_django.TemplateBackend'

        connection = get_connection(klass)

        self.assertIsInstance(connection,
                              backends.vanilla_django.TemplateBackend)
Beispiel #10
0
def test_send_email_request_change(mocked_templated_email, site_settings,
                                   customer_user):
    new_email = "*****@*****.**"
    template = account_emails.REQUEST_EMAIL_CHANGE_TEMPLATE
    redirect_url = "localhost"
    token = "token_example"
    event_parameters = {
        "old_email": customer_user.email,
        "new_email": new_email
    }

    account_emails._send_request_email_change_email(new_email, redirect_url,
                                                    customer_user.pk, token,
                                                    event_parameters)
    ctx = {
        "domain": "mirumee.com",
        "redirect_url": "localhost?token=token_example",
        "site_name": "mirumee.com",
    }
    recipients = [new_email]

    expected_call_kwargs = {
        "context": ctx,
        "from_email": site_settings.default_from_email,
        "template_name": template,
    }

    # mocked_templated_email.assert_called_once()
    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)
Beispiel #11
0
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)
Beispiel #12
0
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)
Beispiel #13
0
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)
Beispiel #14
0
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)
Beispiel #15
0
def test_send_staff_emails(mocked_templated_email, order, site_settings,
                           staff_notification_recipient):
    emails.send_staff_order_confirmation(order.pk)
    email_data = emails.collect_staff_order_notification_data(
        order.pk, emails.STAFF_CONFIRM_ORDER_TEMPLATE)

    recipients = [staff_notification_recipient.get_email()]

    expected_call_kwargs = {
        "context": email_data["context"],
        "from_email": site_settings.default_from_email,
        "template_name": emails.STAFF_CONFIRM_ORDER_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)
Beispiel #16
0
def test_send_email_with_link_to_download_file(mocked_templated_email,
                                               site_settings, user_export_file,
                                               tmpdir, media_root):
    # given
    file_mock = mock.MagicMock(spec=File)
    file_mock.name = "temp_file.csv"

    user_export_file.content_file = file_mock
    user_export_file.save()

    # when
    emails.send_email_with_link_to_download_file(user_export_file,
                                                 user_export_file.user.email,
                                                 "export_products_success")

    # then
    template = emails.EXPORT_TEMPLATES["export_products_success"]
    ctx = {
        "csv_link": f"http://mirumee.com/media/export_files/{file_mock.name}",
        "domain": "mirumee.com",
        "site_name": "mirumee.com",
    }
    recipients = [user_export_file.user.email]
    expected_call_kwargs = {
        "context": ctx,
        "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)

    assert ExportEvent.objects.filter(
        export_file=user_export_file,
        user=user_export_file.user,
        type=ExportEvents.EXPORTED_FILE_SENT,
    ).exists()
Beispiel #17
0
def test_send_fulfillment_emails(mocked_templated_email, template, send_email,
                                 fulfilled_order, settings):
    fulfillment = fulfilled_order.fulfillments.first()
    send_email(order_pk=fulfilled_order.pk, fulfillment_pk=fulfillment.pk)
    email_data = emails.collect_data_for_fullfillment_email(
        fulfilled_order.pk, template, fulfillment.pk)

    recipients = [fulfilled_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_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)
Beispiel #19
0
def test_send_export_failed_info(mocked_templated_email, site_settings,
                                 user_export_file, tmpdir, media_root):
    # given
    file_mock = mock.MagicMock(spec=File)
    file_mock.name = "temp_file.csv"

    user_export_file.content_file = file_mock
    user_export_file.save()
    recipients = [user_export_file.user.email]

    # when
    emails.send_export_failed_info(user_export_file, recipients[0],
                                   "export_failed")

    # then
    template = emails.EXPORT_TEMPLATES["export_failed"]
    ctx = {
        "domain": "mirumee.com",
        "site_name": "mirumee.com",
    }

    expected_call_kwargs = {
        "context": ctx,
        "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)

    assert ExportEvent.objects.filter(
        export_file=user_export_file,
        user=user_export_file.user,
        type=ExportEvents.EXPORT_FAILED_INFO_SENT,
    )
Beispiel #20
0
def test_send_fulfillment_emails(
    mocked_templated_email, template, send_email, fulfilled_order, settings
):
    fulfillment = fulfilled_order.fulfillments.first()
    send_email(order_pk=fulfilled_order.pk, fulfillment_pk=fulfillment.pk)
    email_data = emails.collect_data_for_fullfillment_email(
        fulfilled_order.pk, template, fulfillment.pk
    )

    recipients = [fulfilled_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)
Beispiel #21
0
 def test_can_accept_path_to_module_as_backend(self):
     self.assertIsInstance(
         get_connection('templated_email.backends.vanilla_django'),
         TemplateBackend)
Beispiel #22
0
    def test_class_instance(self):
        klass = backends.vanilla_django.TemplateBackend

        connection = get_connection(klass)

        self.assertIsInstance(connection, klass)
Beispiel #23
0
    def test_default(self):
        connection = get_connection()

        self.assertIsInstance(connection,
                              backends.vanilla_django.TemplateBackend)
    def test_can_accept_path_to_module_as_backend(self):
	self.assertIsInstance(get_connection('templated_email.backends.vanilla_django'), TemplateBackend)
    def test_class_instance(self):
        klass = backends.vanilla_django.TemplateBackend

        connection = get_connection(klass)

        self.assertIsInstance(connection, klass)
    def test_default(self):
        connection = get_connection()

        self.assertIsInstance(connection, backends.vanilla_django.TemplateBackend)