"""Test for phys_delivery_email."""
from unittest.mock import patch
import flask
from notifications import config
from notifications.constants.email import (
PHYS_DELIVERY_ORDER_COMPLETED_SUBJECT,
PHYS_DELIVERY_ORDER_COMPLETED_TEMPLATE,
PHYS_DELIVERY_ORDER_FAILED_SUBJECT,
PHYS_DELIVERY_ORDER_FAILED_TEMPLATE,
)
from notifications.logic import phys_delivery_email
app = flask.Flask(config.SERVICE_NAME)
order_details = {
'id': '5',
'createdBy': {'id': '2840115d-d31b-4864-95ea-53c3e8b4a434', 'email': 'jmarais@theorchard.com'},
}
@patch('flask.render_template', return_value=' Test message ')
@patch('notifications.connectors.ses.send_html_email', return_value={})
@patch('notifications.models.graphql_router.phys_delivery_order_by_id', return_value=order_details)
def test_phys_delivery_order_completed(
mock_phys_delivery_order_by_id, render_template, mock_send_email
):
"""Test phy delivery order_completed."""
with app.test_request_context('/identity/123/report/participant-data'):
order_id = 1234
result = phys_delivery_email.order_completed(order_id)
mock_phys_delivery_order_by_id.assert_called_with(order_id)
render_template.assert_called_once()
mock_send_email.assert_called_with(
PHYS_DELIVERY_ORDER_COMPLETED_TEMPLATE,
**{
'subject': PHYS_DELIVERY_ORDER_COMPLETED_SUBJECT,
'orderId': order_id,
'orderUrl': f'https://distribution.qaorch.com/monitor/physical/audio?orderId={order_id}',
'iconsBaseUrl': 'https://cdn.theorchard.io/web-icons/',
},
)
assert result.status == 202
@patch('flask.render_template', return_value=' Test message ')
@patch('notifications.connectors.ses.send_html_email', return_value={})
@patch('notifications.models.graphql_router.phys_delivery_order_by_id', return_value=order_details)
def test_phys_delivery_order_failed(
mock_phys_delivery_order_by_id, render_template, mock_send_email
):
"""Test phys delivery order_failed."""
with app.test_request_context('/identity/123/report/participant-data'):
order_id = 1234
result = phys_delivery_email.order_failed(order_id)
mock_phys_delivery_order_by_id.assert_called_with(order_id)
render_template.assert_called_once()
mock_send_email.assert_called_with(
PHYS_DELIVERY_ORDER_FAILED_TEMPLATE,
**{
'subject': PHYS_DELIVERY_ORDER_FAILED_SUBJECT,
'orderId': order_id,
'orderUrl': f'https://distribution.qaorch.com/monitor/physical/audio?orderId={order_id}',
'iconsBaseUrl': 'https://cdn.theorchard.io/web-icons/',
},
)
assert result.status == 202