"""Test for nr_delivery_email.""" from unittest.mock import patch import flask from notifications import config from notifications.constants.email import ( NR_DELIVERY_ORDER_COMPLETED_SUBJECT, NR_DELIVERY_ORDER_COMPLETED_TEMPLATE, NR_DELIVERY_ORDER_FAILED_SUBJECT, NR_DELIVERY_ORDER_FAILED_TEMPLATE, ) from notifications.logic import nr_delivery_email app = flask.Flask(config.SERVICE_NAME) order_details = { 'id': '5', 'status': 'TRIGGERED', 'outputFile': '', 'numberOfJobs': 1, 'cmo': { 'id': '1606', 'name': 'ERATO', }, 'createdBy': {'id': '47d9a1be-ad2e-48cf-a848-6aecfb2dd026', 'email': 'npatel@theorchard.com'}, } @patch('flask.render_template', return_value=' Test message ') @patch('notifications.connectors.ses.send_html_email', return_value={}) @patch('notifications.models.graphql_router.nr_delivery_order_by_id', return_value=order_details) def test_nr_delivery_order_completed( mock_nr_delivery_order_by_id, render_template, mock_send_email ): """Test nr delivery order_completed.""" with app.test_request_context('/identity/123/report/participant-data'): order_id = 1234 result = nr_delivery_email.order_completed(order_id) mock_nr_delivery_order_by_id.assert_called_with(order_id) render_template.assert_called_once() mock_send_email.assert_called_with( NR_DELIVERY_ORDER_COMPLETED_TEMPLATE, **{ 'subject': NR_DELIVERY_ORDER_COMPLETED_SUBJECT, 'numberOfJobs': order_details['numberOfJobs'], 'orderId': order_id, 'orderUrl': f'https://distribution.qaorch.com/monitor/sound-recording/performance?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.nr_delivery_order_by_id', return_value=order_details) def test_nr_delivery_order_failed(mock_nr_delivery_order_by_id, render_template, mock_send_email): """Test nr delivery order_failed.""" with app.test_request_context('/identity/123/report/participant-data'): order_id = 1234 result = nr_delivery_email.order_failed(order_id) mock_nr_delivery_order_by_id.assert_called_with(order_id) render_template.assert_called_once() mock_send_email.assert_called_with( NR_DELIVERY_ORDER_FAILED_TEMPLATE, **{ 'subject': NR_DELIVERY_ORDER_FAILED_SUBJECT, 'orderId': order_id, 'orderUrl': f'https://distribution.qaorch.com/monitor/sound-recording/performance?orderId={order_id}', 'iconsBaseUrl': 'https://cdn.theorchard.io/web-icons/', }, ) assert result.status == 202