"""Tests for email template rendering.""" import flask from notifications import config from notifications.constants.email import PARTICIPANT_DATA_ISSUE_TEMPLATE app = flask.Flask(config.SERVICE_NAME) def test_render_template(): """Test rendering template.""" with app.test_request_context('/identity/123/report/participant-data'): result = flask.render_template( PARTICIPANT_DATA_ISSUE_TEMPLATE, **{ 'name': 'Jacob Fowler', 'email': 'jfowler@theorchard.com', 'identity_id': '03e83149-3c7f-4587-940b-ce83dec34bc8', 'category': 'DATA_INACCURATE', 'referrer': 'PARTICIPANT_SCREEN', 'participant': { 'name': 'Phoebe Bridgers', 'id': '700cb3c2-fe8c-42eb-b1e0-dd376be6c15c', 'chartmetric_id': '122237', }, 'application': {'name': 'orchard-go', 'version': '2.0.1'}, 'message': 'Phoebe Bridgers should have more followers', }, ) assert result == ( 'From: Jacob Fowler (jfowler@theorchard.com)\n' 'Identity ID: 03e83149-3c7f-4587-940b-ce83dec34bc8\n' 'Referrer: PARTICIPANT_SCREEN\n' 'Application: orchard-go (2.0.1)\n' 'Artist: Phoebe Bridgers (700cb3c2-fe8c-42eb-b1e0-dd376be6c15c)\n' 'Insights Link: https://insights.theorchard.com/artist/700cb3c2-fe8c-42eb-b1e0-dd376be6c15c\n' 'Chartmetric Link: https://app.chartmetric.com/artist?id=122237\n' 'Category: DATA_INACCURATE\n' 'Message: Phoebe Bridgers should have more followers' ) def test_render_template_email_equals_name(): """Test rendering template with email equal to name.""" with app.test_request_context('/identity/123/report/participant-data'): result = flask.render_template( PARTICIPANT_DATA_ISSUE_TEMPLATE, **{ 'name': 'jfowler@theorchard.com', 'email': 'jfowler@theorchard.com', 'identity_id': '03e83149-3c7f-4587-940b-ce83dec34bc8', 'category': 'DATA_INACCURATE', 'referrer': 'PARTICIPANT_SCREEN', 'participant': { 'name': 'Phoebe Bridgers', 'id': '700cb3c2-fe8c-42eb-b1e0-dd376be6c15c', 'chartmetric_id': '122237', }, 'application': {'name': 'orchard-go', 'version': '2.0.1'}, 'message': 'Phoebe Bridgers should have more followers', }, ) assert result == ( 'From: jfowler@theorchard.com\n' 'Identity ID: 03e83149-3c7f-4587-940b-ce83dec34bc8\n' 'Referrer: PARTICIPANT_SCREEN\n' 'Application: orchard-go (2.0.1)\n' 'Artist: Phoebe Bridgers (700cb3c2-fe8c-42eb-b1e0-dd376be6c15c)\n' 'Insights Link: https://insights.theorchard.com/artist/700cb3c2-fe8c-42eb-b1e0-dd376be6c15c\n' 'Chartmetric Link: https://app.chartmetric.com/artist?id=122237\n' 'Category: DATA_INACCURATE\n' 'Message: Phoebe Bridgers should have more followers' )