"""Test for nr_delivery_email.""" from unittest.mock import patch import flask from notifications import config from notifications.constants.email import ( NR_OWNERSHIP_DELIVERY_ORDER_COMPLETED_SUBJECT, NR_OWNERSHIP_DELIVERY_ORDER_COMPLETED_TEMPLATE, NR_OWNERSHIP_DELIVERY_ORDER_FAILED_SUBJECT, NR_OWNERSHIP_DELIVERY_ORDER_FAILED_TEMPLATE, ) from notifications.logic import nr_ownership_delivery_email app = flask.Flask(config.SERVICE_NAME) order_details = { 'id': '5', 'status': 'READY', 'cmo': { 'id': '1606', 'name': 'ERATO', }, 'createdBy': {'id': '0bb49c74-34a6-4ba7-958b-c7267368d986', 'email': 'astorkey@theorchard.com'}, 'summary': {'outputFileCount': 2}, } @patch('flask.render_template', return_value=' Test message ') @patch('notifications.connectors.ses.send_html_email', return_value={}) @patch( 'notifications.models.graphql_router.nr_ownership_delivery_order_by_id', return_value=order_details, ) def test_nr_ownership_delivery_order_completed( mock_nr_ownership_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_ownership_delivery_email.order_completed(order_id) mock_nr_ownership_delivery_order_by_id.assert_called_with(order_id) render_template.assert_called_once() mock_send_email.assert_called_with( NR_OWNERSHIP_DELIVERY_ORDER_COMPLETED_TEMPLATE, **{ 'subject': NR_OWNERSHIP_DELIVERY_ORDER_COMPLETED_SUBJECT, 'orderId': order_id, 'orderUrl': f'https://distribution.qaorch.com/monitor/sound-recording/ownership?orderId={order_id}', 'iconsBaseUrl': 'https://cdn.theorchard.io/web-icons/', 'outputFileCount': 2, }, ) 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_ownership_delivery_order_by_id', return_value=order_details, ) def test_nr_ownership_delivery_order_failed( mock_nr_ownership_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_ownership_delivery_email.order_failed(order_id) mock_nr_ownership_delivery_order_by_id.assert_called_with(order_id) render_template.assert_called_once() mock_send_email.assert_called_with( NR_OWNERSHIP_DELIVERY_ORDER_FAILED_TEMPLATE, **{ 'subject': NR_OWNERSHIP_DELIVERY_ORDER_FAILED_SUBJECT, 'orderId': order_id, 'orderUrl': f'https://distribution.qaorch.com/monitor/sound-recording/ownership?orderId={order_id}', 'iconsBaseUrl': 'https://cdn.theorchard.io/web-icons/', }, ) assert result.status == 202