def testReplyInvitation(self): """We include a footer about replying that is appropriate for that user.""" email_task = notify_helpers._MakeEmailWorkItem( notify_reasons.AddrPerm(True, '*****@*****.**', self.member, REPLY_NOT_ALLOWED), ['reason'], self.issue, 'body non', 'body mem', self.project, 'example.com', self.commenter_view, self.detail_url) self.assertEqual(emailfmt.NoReplyAddress(), email_task['reply_to']) self.assertNotIn('Reply to this email', email_task['body']) email_task = notify_helpers._MakeEmailWorkItem( notify_reasons.AddrPerm(True, '*****@*****.**', self.member, REPLY_MAY_COMMENT), ['reason'], self.issue, 'body non', 'body mem', self.project, 'example.com', self.commenter_view, self.detail_url) self.assertEqual( '%s@%s' % (self.project.project_name, emailfmt.MailDomain()), email_task['reply_to']) self.assertIn('Reply to this email to add a comment', email_task['body']) self.assertNotIn('make changes', email_task['body']) email_task = notify_helpers._MakeEmailWorkItem( notify_reasons.AddrPerm(True, '*****@*****.**', self.member, REPLY_MAY_UPDATE), ['reason'], self.issue, 'body non', 'body mem', self.project, 'example.com', self.commenter_view, self.detail_url) self.assertEqual( '%s@%s' % (self.project.project_name, emailfmt.MailDomain()), email_task['reply_to']) self.assertIn('Reply to this email to add a comment', email_task['body']) self.assertIn('make updates', email_task['body'])
def testHtmlBody_WithEscapedHtml(self): """"An html body is sent with html content escaped.""" body_with_html_content = ( '<a href="http://www.google.com">test</a> \'something\'') email_task = notify_helpers._MakeEmailWorkItem( notify_reasons.AddrPerm(False, '*****@*****.**', self.member, REPLY_NOT_ALLOWED, user_pb2.UserPrefs()), ['reason'], self.issue, 'body link-only', body_with_html_content, 'unused body mem', self.project, 'example.com', self.commenter_view, self.detail_url) escaped_body_with_html_content = ( '<a href="http://www.google.com">test</a> ' ''something'') notify_helpers._MakeNotificationFooter(['reason'], REPLY_NOT_ALLOWED, 'example.com') expected_html_body = ( notify_helpers.HTML_BODY_WITH_GMAIL_ACTION_TEMPLATE % { 'url': self.detail_url, 'body': '%s-- <br/>%s' % (escaped_body_with_html_content, self.expected_html_footer) }) self.assertEquals(expected_html_body, email_task['html_body'])
def testBodySelection_Member(self): """We send members the email body that is indented for members.""" email_task = notify_helpers._MakeEmailWorkItem( notify_reasons.AddrPerm(True, '*****@*****.**', self.member, REPLY_NOT_ALLOWED, user_pb2.UserPrefs()), ['reason'], self.issue, 'body link-only', 'body mem', 'body mem', self.project, 'example.com', self.commenter_view, self.detail_url) self.assertIn('body mem', email_task['body'])
def testReasons(self): """The footer lists reasons why that email was sent to that user.""" email_task = notify_helpers._MakeEmailWorkItem( notify_reasons.AddrPerm(True, '*****@*****.**', self.member, REPLY_MAY_UPDATE), ['Funny', 'Caring', 'Near'], self.issue, 'body', 'body', self.project, 'example.com', self.commenter_view, self.detail_url) self.assertIn('because:', email_task['body']) self.assertIn('1. Funny', email_task['body']) self.assertIn('2. Caring', email_task['body']) self.assertIn('3. Near', email_task['body']) email_task = notify_helpers._MakeEmailWorkItem( notify_reasons.AddrPerm(True, '*****@*****.**', self.member, REPLY_MAY_UPDATE), [], self.issue, 'body', 'body', self.project, 'example.com', self.commenter_view, self.detail_url) self.assertNotIn('because', email_task['body'])
def testInboundEmailDisabled(self): """We don't invite replies if they are disabled for this project.""" self.project.process_inbound_email = False email_task = notify_helpers._MakeEmailWorkItem( notify_reasons.AddrPerm(True, '*****@*****.**', self.member, REPLY_MAY_UPDATE), ['reason'], self.issue, 'body non', 'body mem', self.project, 'example.com', self.commenter_view, self.detail_url) self.assertEqual(emailfmt.NoReplyAddress(), email_task['reply_to'])
def testBodySelection_LinkOnly(self, mock_sulo): """We send a link-only body when ShouldUseLinkOnly() is true.""" mock_sulo.return_value = True email_task = notify_helpers._MakeEmailWorkItem( notify_reasons.AddrPerm(True, '*****@*****.**', self.member, REPLY_NOT_ALLOWED, user_pb2.UserPrefs()), ['reason'], self.issue, 'body link-only', 'body mem', 'body mem', self.project, 'example.com', self.commenter_view, self.detail_url) self.assertIn('body link-only', email_task['body'])
def testHtmlBody(self): """"An html body is sent if a detail_url is specified.""" email_task = notify_helpers._MakeEmailWorkItem( notify_reasons.AddrPerm(False, '*****@*****.**', self.member, REPLY_NOT_ALLOWED), ['reason'], self.issue, 'body non', 'body mem', self.project, 'example.com', self.commenter_view, self.detail_url) expected_html_body = ( notify_helpers.HTML_BODY_WITH_GMAIL_ACTION_TEMPLATE % { 'url': self.detail_url, 'body': 'body non-- <br/>%s' % self.expected_html_footer }) self.assertEquals(expected_html_body, email_task['html_body'])
def testBodySelection(self): """We send non-members the email body that is indented for non-members.""" email_task = notify_helpers._MakeEmailWorkItem( notify_reasons.AddrPerm(False, '*****@*****.**', self.member, REPLY_NOT_ALLOWED), ['reason'], self.issue, 'body non', 'body mem', self.project, 'example.com', self.commenter_view, self.detail_url) self.assertEqual('*****@*****.**', email_task['to']) self.assertEqual('Issue 1234 in proj1: summary', email_task['subject']) self.assertIn('body non', email_task['body']) self.assertEqual( emailfmt.FormatFromAddr(self.project, commenter_view=self.commenter_view, can_reply_to=False), email_task['from_addr']) self.assertEqual(emailfmt.NoReplyAddress(), email_task['reply_to']) email_task = notify_helpers._MakeEmailWorkItem( notify_reasons.AddrPerm(True, '*****@*****.**', self.member, REPLY_NOT_ALLOWED), ['reason'], self.issue, 'body mem', 'body mem', self.project, 'example.com', self.commenter_view, self.detail_url) self.assertIn('body mem', email_task['body'])
def testHtmlBody_LinkWithinTags(self): """"An html body is sent with correct <a href>s.""" email_task = notify_helpers._MakeEmailWorkItem( notify_reasons.AddrPerm(False, '*****@*****.**', self.member, REPLY_NOT_ALLOWED), ['reason'], self.issue, 'a <http://google.com> z', 'unused body', self.project, 'example.com', self.commenter_view, self.detail_url) expected_html_body = ( notify_helpers.HTML_BODY_WITH_GMAIL_ACTION_TEMPLATE % { 'url': self.detail_url, 'body': ('a <<a href="http://google.com">http://google.com</a>> ' 'z-- <br/>%s' % self.expected_html_footer) }) self.assertEquals(expected_html_body, email_task['html_body'])
def testHtmlBody_WithLinks(self): """"An html body is sent if a detail_url is specified.""" email_task = notify_helpers._MakeEmailWorkItem( notify_reasons.AddrPerm(False, '*****@*****.**', self.member, REPLY_NOT_ALLOWED), ['reason'], self.issue, 'test google.com test', 'unused body mem', self.project, 'example.com', self.commenter_view, self.detail_url) expected_html_body = ( notify_helpers.HTML_BODY_WITH_GMAIL_ACTION_TEMPLATE % { 'url': self.detail_url, 'body': ('test <a href="http://google.com">google.com</a> test-- <br/>%s' % (self.expected_html_footer)) }) self.assertEquals(expected_html_body, email_task['html_body'])
def testHtmlBody_WithUnicodeChars(self): """"An html body is sent if a detail_url is specified.""" unicode_content = '\xe2\x9d\xa4 â â' email_task = notify_helpers._MakeEmailWorkItem( notify_reasons.AddrPerm(False, '*****@*****.**', self.member, REPLY_NOT_ALLOWED), ['reason'], self.issue, unicode_content, 'unused body mem', self.project, 'example.com', self.commenter_view, self.detail_url) expected_html_body = ( notify_helpers.HTML_BODY_WITH_GMAIL_ACTION_TEMPLATE % { 'url': self.detail_url, 'body': '%s-- <br/>%s' % (unicode_content.decode('utf-8'), self.expected_html_footer) }) self.assertEquals(expected_html_body, email_task['html_body'])
def testHtmlBody_EmailWithinTags(self): """"An html body is sent with correct <a href>s.""" email_task = notify_helpers._MakeEmailWorkItem( notify_reasons.AddrPerm(False, '*****@*****.**', self.member, REPLY_NOT_ALLOWED, user_pb2.UserPrefs()), ['reason'], self.issue, 'body link-only', 'a <*****@*****.**> <*****@*****.**> z', 'unused body mem', self.project, 'example.com', self.commenter_view, self.detail_url) expected_html_body = ( notify_helpers.HTML_BODY_WITH_GMAIL_ACTION_TEMPLATE % { 'url': self.detail_url, 'body': ('a <<a href="mailto:[email protected]">[email protected]</a>>' ' <<a href="mailto:[email protected]">[email protected]</a>> ' 'z-- <br/>%s' % self.expected_html_footer) }) self.assertEquals(expected_html_body, email_task['html_body'])