Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
przlada committed May 14, 2020
1 parent 255c0a3 commit c1faddd
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/test_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,46 @@ def test_send_fulfillment_emails(
email_connection.get_email_message(to=recipients, **expected_call_kwargs)


@pytest.mark.parametrize(
"send_email,template",
[
(
emails.send_fulfillment_confirmation,
emails.CONFIRM_FULFILLMENT_TEMPLATE,
), # noqa
(emails.send_fulfillment_update, emails.UPDATE_FULFILLMENT_TEMPLATE),
],
)
@mock.patch("saleor.order.emails.send_templated_mail")
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_fullfillment_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_email_having_display_name_in_settings(customer_user, site_settings, settings):
expected_from_email = "Info <[email protected]>"

Expand Down
8 changes: 8 additions & 0 deletions tests/test_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,14 @@ def test_update_order_status(fulfilled_order):
assert fulfilled_order.status == OrderStatus.UNFULFILLED


def test_validate_fulfillment_tracking_number_as_url(fulfilled_order):
fulfillment = fulfilled_order.fulfillments.first()
assert not fulfillment.is_tracking_number_url
fulfillment.tracking_number = "https://www.example.com"
fulfillment.save()
assert fulfillment.is_tracking_number_url


def test_order_queryset_confirmed(draft_order):
other_orders = [
Order.objects.create(status=OrderStatus.UNFULFILLED),
Expand Down

0 comments on commit c1faddd

Please sign in to comment.