Mercurial > kallithea
changeset 6134:8bd957e6cccb
tests: make the html from mail template dump valid html even when the html mails contain html
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Thu, 28 Jul 2016 16:36:51 +0200 |
parents | cc18e56220a2 |
children | 8b75085c2c02 |
files | kallithea/templates/email_templates/main.html kallithea/tests/models/test_dump_html_mails.ref.html kallithea/tests/models/test_notifications.py |
diffstat | 3 files changed, 316 insertions(+), 215 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/templates/email_templates/main.html Thu Jul 28 16:34:49 2016 +0200 +++ b/kallithea/templates/email_templates/main.html Thu Jul 28 16:36:51 2016 +0200 @@ -1,6 +1,15 @@ +<!doctype html> +<html lang="en"> +<head> + <title></title> + <meta name="viewport" content="width=device-width"> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> +</head> +<body> ${self.body()} - <br/> <br/> -- <br/> ${_("This is an automatic notification. Don't reply to this mail.")} +</body> +</html>
--- a/kallithea/tests/models/test_dump_html_mails.ref.html Thu Jul 28 16:34:49 2016 +0200 +++ b/kallithea/tests/models/test_dump_html_mails.ref.html Thu Jul 28 16:36:51 2016 +0200 @@ -1,15 +1,16 @@ -<html><body> - - +<!doctype html> +<html lang="en"> +<head><title>Notifications</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head> +<body> +<hr/> <h1>cs_comment, is_mention=False, status_change=None</h1> <pre> - From: u1 To: u2@example.com Subject: [Comment] repo/name changeset cafe1234 "This changeset did something cl..." on brunch - --------------------- - +</pre> +<hr/> +<pre> Comment from Opinionated User (jsmith) on repo_target changeset cafe1234c0ff: This is the new comment. @@ -26,9 +27,16 @@ -- This is an automatic notification. Don't reply to this mail. - ---------------------</pre> - +</pre> +<hr/> +<!--!doctype html--> +<!--html lang="en"--> +<!--head--> + <!--title--><!--/title--> + <!--meta name="viewport" content="width=device-width"--> + <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"--> +<!--/head--> +<!--body--> <p>Comment from Opinionated User (jsmith) on repo_target changeset cafe1234c0ff:</p> @@ -44,24 +52,22 @@ This changeset did something clever which is hard to explain </p> - <br/> <br/> -- <br/> This is an automatic notification. Don't reply to this mail. - -<pre>--------------------</pre> - - +<!--/body--> +<!--/html--> +<hr/> +<hr/> <h1>cs_comment, is_mention=True, status_change=None</h1> <pre> - From: u1 To: u2@example.com Subject: [Comment] repo/name changeset cafe1234 "This changeset did something cl..." on brunch - --------------------- - +</pre> +<hr/> +<pre> Comment from Opinionated User (jsmith) on repo_target changeset cafe1234c0ff mentioned you: This is the new comment. @@ -78,9 +84,16 @@ -- This is an automatic notification. Don't reply to this mail. - ---------------------</pre> - +</pre> +<hr/> +<!--!doctype html--> +<!--html lang="en"--> +<!--head--> + <!--title--><!--/title--> + <!--meta name="viewport" content="width=device-width"--> + <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"--> +<!--/head--> +<!--body--> <p>Comment from Opinionated User (jsmith) on repo_target changeset cafe1234c0ff mentioned you:</p> @@ -96,24 +109,22 @@ This changeset did something clever which is hard to explain </p> - <br/> <br/> -- <br/> This is an automatic notification. Don't reply to this mail. - -<pre>--------------------</pre> - - +<!--/body--> +<!--/html--> +<hr/> +<hr/> <h1>cs_comment, is_mention=False, status_change='Approved'</h1> <pre> - From: u1 To: u2@example.com Subject: [Approved: Comment] repo/name changeset cafe1234 "This changeset did something cl..." on brunch - --------------------- - +</pre> +<hr/> +<pre> Comment from Opinionated User (jsmith) on repo_target changeset cafe1234c0ff: This is the new comment. @@ -131,9 +142,16 @@ -- This is an automatic notification. Don't reply to this mail. - ---------------------</pre> - +</pre> +<hr/> +<!--!doctype html--> +<!--html lang="en"--> +<!--head--> + <!--title--><!--/title--> + <!--meta name="viewport" content="width=device-width"--> + <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"--> +<!--/head--> +<!--body--> <p>Comment from Opinionated User (jsmith) on repo_target changeset cafe1234c0ff:</p> @@ -150,24 +168,22 @@ This changeset did something clever which is hard to explain </p> - <br/> <br/> -- <br/> This is an automatic notification. Don't reply to this mail. - -<pre>--------------------</pre> - - +<!--/body--> +<!--/html--> +<hr/> +<hr/> <h1>cs_comment, is_mention=True, status_change='Approved'</h1> <pre> - From: u1 To: u2@example.com Subject: [Approved: Comment] repo/name changeset cafe1234 "This changeset did something cl..." on brunch - --------------------- - +</pre> +<hr/> +<pre> Comment from Opinionated User (jsmith) on repo_target changeset cafe1234c0ff mentioned you: This is the new comment. @@ -185,9 +201,16 @@ -- This is an automatic notification. Don't reply to this mail. - ---------------------</pre> - +</pre> +<hr/> +<!--!doctype html--> +<!--html lang="en"--> +<!--head--> + <!--title--><!--/title--> + <!--meta name="viewport" content="width=device-width"--> + <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"--> +<!--/head--> +<!--body--> <p>Comment from Opinionated User (jsmith) on repo_target changeset cafe1234c0ff mentioned you:</p> @@ -204,24 +227,22 @@ This changeset did something clever which is hard to explain </p> - <br/> <br/> -- <br/> This is an automatic notification. Don't reply to this mail. - -<pre>--------------------</pre> - - +<!--/body--> +<!--/html--> +<hr/> +<hr/> <h1>message</h1> <pre> - From: u1 To: u2@example.com Subject: Test Message - --------------------- - +</pre> +<hr/> +<pre> This is the body of the test message - nothing interesting here except indentation. @@ -229,32 +250,37 @@ -- This is an automatic notification. Don't reply to this mail. - ---------------------</pre> - +</pre> +<hr/> +<!--!doctype html--> +<!--html lang="en"--> +<!--head--> + <!--title--><!--/title--> + <!--meta name="viewport" content="width=device-width"--> + <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"--> +<!--/head--> +<!--body--> <div class="formatted-fixed">This is the body of the test message - nothing interesting here except indentation.</div> - <br/> <br/> -- <br/> This is an automatic notification. Don't reply to this mail. - -<pre>--------------------</pre> - - +<!--/body--> +<!--/html--> +<hr/> +<hr/> <h1>registration</h1> <pre> - From: u1 To: u2@example.com Subject: New user newbie registered - --------------------- - +</pre> +<hr/> +<pre> Registration body @@ -263,33 +289,38 @@ -- This is an automatic notification. Don't reply to this mail. - ---------------------</pre> - +</pre> +<hr/> +<!--!doctype html--> +<!--html lang="en"--> +<!--head--> + <!--title--><!--/title--> + <!--meta name="viewport" content="width=device-width"--> + <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"--> +<!--/head--> +<!--body--> <div class="formatted-fixed">Registration body</div> View this user here: <a href="http://newbie.org">http://newbie.org</a> - <br/> <br/> -- <br/> This is an automatic notification. Don't reply to this mail. - -<pre>--------------------</pre> - - +<!--/body--> +<!--/html--> +<hr/> +<hr/> <h1>pull_request, is_mention=False</h1> <pre> - From: u1 To: u2@example.com Subject: [Review] repo/name PR #7 "The Title" from devbranch by u2 - --------------------- - +</pre> +<hr/> +<pre> Requesting User (root) requested your review of repo/name pull request "The Title" @@ -312,9 +343,16 @@ -- This is an automatic notification. Don't reply to this mail. - ---------------------</pre> - +</pre> +<hr/> +<!--!doctype html--> +<!--html lang="en"--> +<!--head--> + <!--title--><!--/title--> + <!--meta name="viewport" content="width=device-width"--> + <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"--> +<!--/head--> +<!--body--> <p>Requesting User (root) requested your review of repo/name pull request "The Title"</p> @@ -337,24 +375,22 @@ </p> - <br/> <br/> -- <br/> This is an automatic notification. Don't reply to this mail. - -<pre>--------------------</pre> - - +<!--/body--> +<!--/html--> +<hr/> +<hr/> <h1>pull_request, is_mention=True</h1> <pre> - From: u1 To: u2@example.com Subject: [Review] repo/name PR #7 "The Title" from devbranch by u2 - --------------------- - +</pre> +<hr/> +<pre> Requesting User (root) mentioned you on repo/name pull request "The Title" @@ -377,9 +413,16 @@ -- This is an automatic notification. Don't reply to this mail. - ---------------------</pre> - +</pre> +<hr/> +<!--!doctype html--> +<!--html lang="en"--> +<!--head--> + <!--title--><!--/title--> + <!--meta name="viewport" content="width=device-width"--> + <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"--> +<!--/head--> +<!--body--> <p>Requesting User (root) mentioned you on repo/name pull request "The Title"</p> @@ -402,24 +445,22 @@ </p> - <br/> <br/> -- <br/> This is an automatic notification. Don't reply to this mail. - -<pre>--------------------</pre> - - +<!--/body--> +<!--/html--> +<hr/> +<hr/> <h1>pull_request_comment, is_mention=False, status_change=None, closing_pr=False</h1> <pre> - From: u1 To: u2@example.com Subject: [Comment] repo/name PR #7 "The Title" from devbranch by u2 - --------------------- - +</pre> +<hr/> +<pre> Comment from Opinionated User (jsmith) on repo/name pull request "The Title": Me too! @@ -432,9 +473,16 @@ -- This is an automatic notification. Don't reply to this mail. - ---------------------</pre> - +</pre> +<hr/> +<!--!doctype html--> +<!--html lang="en"--> +<!--head--> + <!--title--><!--/title--> + <!--meta name="viewport" content="width=device-width"--> + <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"--> +<!--/head--> +<!--body--> <p>Comment from Opinionated User (jsmith) on repo/name pull request "The Title":</p> @@ -445,24 +493,22 @@ <p>URL: <a href="http://pr.org/comment">http://pr.org/comment</a></p> - <br/> <br/> -- <br/> This is an automatic notification. Don't reply to this mail. - -<pre>--------------------</pre> - - +<!--/body--> +<!--/html--> +<hr/> +<hr/> <h1>pull_request_comment, is_mention=True, status_change=None, closing_pr=False</h1> <pre> - From: u1 To: u2@example.com Subject: [Comment] repo/name PR #7 "The Title" from devbranch by u2 - --------------------- - +</pre> +<hr/> +<pre> Comment from Opinionated User (jsmith) on repo/name pull request "The Title": Me too! @@ -475,9 +521,16 @@ -- This is an automatic notification. Don't reply to this mail. - ---------------------</pre> - +</pre> +<hr/> +<!--!doctype html--> +<!--html lang="en"--> +<!--head--> + <!--title--><!--/title--> + <!--meta name="viewport" content="width=device-width"--> + <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"--> +<!--/head--> +<!--body--> <p>Comment from Opinionated User (jsmith) on repo/name pull request "The Title":</p> @@ -488,24 +541,22 @@ <p>URL: <a href="http://pr.org/comment">http://pr.org/comment</a></p> - <br/> <br/> -- <br/> This is an automatic notification. Don't reply to this mail. - -<pre>--------------------</pre> - - +<!--/body--> +<!--/html--> +<hr/> +<hr/> <h1>pull_request_comment, is_mention=False, status_change='Under Review', closing_pr=False</h1> <pre> - From: u1 To: u2@example.com Subject: [Under Review: Comment] repo/name PR #7 "The Title" from devbranch by u2 - --------------------- - +</pre> +<hr/> +<pre> Comment from Opinionated User (jsmith) on repo/name pull request "The Title": Me too! @@ -519,9 +570,16 @@ -- This is an automatic notification. Don't reply to this mail. - ---------------------</pre> - +</pre> +<hr/> +<!--!doctype html--> +<!--html lang="en"--> +<!--head--> + <!--title--><!--/title--> + <!--meta name="viewport" content="width=device-width"--> + <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"--> +<!--/head--> +<!--body--> <p>Comment from Opinionated User (jsmith) on repo/name pull request "The Title":</p> @@ -533,24 +591,22 @@ <p>URL: <a href="http://pr.org/comment">http://pr.org/comment</a></p> - <br/> <br/> -- <br/> This is an automatic notification. Don't reply to this mail. - -<pre>--------------------</pre> - - +<!--/body--> +<!--/html--> +<hr/> +<hr/> <h1>pull_request_comment, is_mention=True, status_change='Under Review', closing_pr=False</h1> <pre> - From: u1 To: u2@example.com Subject: [Under Review: Comment] repo/name PR #7 "The Title" from devbranch by u2 - --------------------- - +</pre> +<hr/> +<pre> Comment from Opinionated User (jsmith) on repo/name pull request "The Title": Me too! @@ -564,9 +620,16 @@ -- This is an automatic notification. Don't reply to this mail. - ---------------------</pre> - +</pre> +<hr/> +<!--!doctype html--> +<!--html lang="en"--> +<!--head--> + <!--title--><!--/title--> + <!--meta name="viewport" content="width=device-width"--> + <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"--> +<!--/head--> +<!--body--> <p>Comment from Opinionated User (jsmith) on repo/name pull request "The Title":</p> @@ -578,24 +641,22 @@ <p>URL: <a href="http://pr.org/comment">http://pr.org/comment</a></p> - <br/> <br/> -- <br/> This is an automatic notification. Don't reply to this mail. - -<pre>--------------------</pre> - - +<!--/body--> +<!--/html--> +<hr/> +<hr/> <h1>pull_request_comment, is_mention=False, status_change=None, closing_pr=True</h1> <pre> - From: u1 To: u2@example.com Subject: [Closing: Comment] repo/name PR #7 "The Title" from devbranch by u2 - --------------------- - +</pre> +<hr/> +<pre> Comment from Opinionated User (jsmith) on repo/name pull request "The Title": Me too! @@ -608,9 +669,16 @@ -- This is an automatic notification. Don't reply to this mail. - ---------------------</pre> - +</pre> +<hr/> +<!--!doctype html--> +<!--html lang="en"--> +<!--head--> + <!--title--><!--/title--> + <!--meta name="viewport" content="width=device-width"--> + <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"--> +<!--/head--> +<!--body--> <p>Comment from Opinionated User (jsmith) on repo/name pull request "The Title":</p> @@ -621,24 +689,22 @@ <p>URL: <a href="http://pr.org/comment">http://pr.org/comment</a></p> - <br/> <br/> -- <br/> This is an automatic notification. Don't reply to this mail. - -<pre>--------------------</pre> - - +<!--/body--> +<!--/html--> +<hr/> +<hr/> <h1>pull_request_comment, is_mention=True, status_change=None, closing_pr=True</h1> <pre> - From: u1 To: u2@example.com Subject: [Closing: Comment] repo/name PR #7 "The Title" from devbranch by u2 - --------------------- - +</pre> +<hr/> +<pre> Comment from Opinionated User (jsmith) on repo/name pull request "The Title": Me too! @@ -651,9 +717,16 @@ -- This is an automatic notification. Don't reply to this mail. - ---------------------</pre> - +</pre> +<hr/> +<!--!doctype html--> +<!--html lang="en"--> +<!--head--> + <!--title--><!--/title--> + <!--meta name="viewport" content="width=device-width"--> + <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"--> +<!--/head--> +<!--body--> <p>Comment from Opinionated User (jsmith) on repo/name pull request "The Title":</p> @@ -664,24 +737,22 @@ <p>URL: <a href="http://pr.org/comment">http://pr.org/comment</a></p> - <br/> <br/> -- <br/> This is an automatic notification. Don't reply to this mail. - -<pre>--------------------</pre> - - +<!--/body--> +<!--/html--> +<hr/> +<hr/> <h1>pull_request_comment, is_mention=False, status_change='Under Review', closing_pr=True</h1> <pre> - From: u1 To: u2@example.com Subject: [Under Review, Closing: Comment] repo/name PR #7 "The Title" from devbranch by u2 - --------------------- - +</pre> +<hr/> +<pre> Comment from Opinionated User (jsmith) on repo/name pull request "The Title": Me too! @@ -695,9 +766,16 @@ -- This is an automatic notification. Don't reply to this mail. - ---------------------</pre> - +</pre> +<hr/> +<!--!doctype html--> +<!--html lang="en"--> +<!--head--> + <!--title--><!--/title--> + <!--meta name="viewport" content="width=device-width"--> + <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"--> +<!--/head--> +<!--body--> <p>Comment from Opinionated User (jsmith) on repo/name pull request "The Title":</p> @@ -709,24 +787,22 @@ <p>URL: <a href="http://pr.org/comment">http://pr.org/comment</a></p> - <br/> <br/> -- <br/> This is an automatic notification. Don't reply to this mail. - -<pre>--------------------</pre> - - +<!--/body--> +<!--/html--> +<hr/> +<hr/> <h1>pull_request_comment, is_mention=True, status_change='Under Review', closing_pr=True</h1> <pre> - From: u1 To: u2@example.com Subject: [Under Review, Closing: Comment] repo/name PR #7 "The Title" from devbranch by u2 - --------------------- - +</pre> +<hr/> +<pre> Comment from Opinionated User (jsmith) on repo/name pull request "The Title": Me too! @@ -740,9 +816,16 @@ -- This is an automatic notification. Don't reply to this mail. - ---------------------</pre> - +</pre> +<hr/> +<!--!doctype html--> +<!--html lang="en"--> +<!--head--> + <!--title--><!--/title--> + <!--meta name="viewport" content="width=device-width"--> + <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"--> +<!--/head--> +<!--body--> <p>Comment from Opinionated User (jsmith) on repo/name pull request "The Title":</p> @@ -754,24 +837,22 @@ <p>URL: <a href="http://pr.org/comment">http://pr.org/comment</a></p> - <br/> <br/> -- <br/> This is an automatic notification. Don't reply to this mail. - -<pre>--------------------</pre> - - +<!--/body--> +<!--/html--> +<hr/> +<hr/> <h1>TYPE_PASSWORD_RESET</h1> <pre> - From: u1 To: john@doe.com Subject: Password reset link - --------------------- - +</pre> +<hr/> +<pre> Hello John Doe @@ -787,9 +868,16 @@ -- This is an automatic notification. Don't reply to this mail. - ---------------------</pre> - +</pre> +<hr/> +<!--!doctype html--> +<!--html lang="en"--> +<!--head--> + <!--title--><!--/title--> + <!--meta name="viewport" content="width=device-width"--> + <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"--> +<!--/head--> +<!--body--> <h4>Hello John Doe</h4> @@ -802,12 +890,13 @@ <p>If it weren't you who requested the password reset, just disregard this message.</p> - <br/> <br/> -- <br/> This is an automatic notification. Don't reply to this mail. +<!--/body--> +<!--/html--> +<hr/> -<pre>--------------------</pre> - -</body></html> +</body> +</html>
--- a/kallithea/tests/models/test_notifications.py Thu Jul 28 16:34:49 2016 +0200 +++ b/kallithea/tests/models/test_notifications.py Thu Jul 28 16:36:51 2016 +0200 @@ -1,4 +1,5 @@ import os +import re import mock import routes.util @@ -170,17 +171,19 @@ l = [] def send_email(recipients, subject, body='', html_body='', headers=None, author=None): - l.append('\n\n<h1>%s</h1>\n' % desc) # desc is from outer scope - l.append('<pre>\n\n') + l.append('<hr/>\n') + l.append('<h1>%s</h1>\n' % desc) # desc is from outer scope + l.append('<pre>\n') l.append('From: %s\n' % author.username) l.append('To: %s\n' % ' '.join(recipients)) l.append('Subject: %s\n' % subject) - l.append('\n--------------------\n%s\n--------------------' % body) l.append('</pre>\n') - l.append('\n%s\n' % html_body) - l.append('<pre>--------------------</pre>\n') + l.append('<hr/>\n') + l.append('<pre>%s</pre>\n' % body) + l.append('<hr/>\n') + l.append(html_body) + l.append('<hr/>\n') - l.append('<html><body>\n') with mock.patch.object(kallithea.lib.celerylib.tasks, 'send_email', send_email): pr_kwargs = dict( pr_nice_id='#7', @@ -268,8 +271,8 @@ EmailNotificationModel().get_email_tmpl(EmailNotificationModel.TYPE_PASSWORD_RESET, 'html', **kwargs), author=User.get(self.u1)) - l.append('\n</body></html>\n') - out = ''.join(l) + out = '<!doctype html>\n<html lang="en">\n<head><title>Notifications</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>\n<body>\n%s\n</body>\n</html>\n' % \ + re.sub(r'<(/?(?:!doctype|html|head|title|meta|body)\b[^>]*)>', r'<!--\1-->', ''.join(l)) outfn = os.path.join(os.path.dirname(__file__), 'test_dump_html_mails.out.html') reffn = os.path.join(os.path.dirname(__file__), 'test_dump_html_mails.ref.html')