| |
@@ -117,6 +117,7 @@
|
| |
|
| |
# Mail text should be as expected.
|
| |
self.assertEqual(args[0], exptext)
|
| |
+ self.assertTrue(isinstance(args[0], unicode))
|
| |
|
| |
# Mail subject should be as expected.
|
| |
self.assertEqual(args[1], u'Issue #1: issue')
|
| |
@@ -153,6 +154,7 @@
|
| |
|
| |
# Mail text should be as expected.
|
| |
self.assertEqual(args[0], exptext)
|
| |
+ self.assertTrue(isinstance(args[0], unicode))
|
| |
|
| |
# Mail subject should be as expected.
|
| |
self.assertEqual(args[1], u'Issue #1: namespaced project issue')
|
| |
@@ -184,6 +186,7 @@
|
| |
|
| |
# Mail text should be as expected.
|
| |
self.assertEqual(args[0], exptext)
|
| |
+ self.assertTrue(isinstance(args[0], unicode))
|
| |
|
| |
# Mail subject should be as expected.
|
| |
self.assertEqual(args[1], u'Issue #1: forked project issue')
|
| |
@@ -201,6 +204,43 @@
|
| |
# Mail should be from user1 (who submitted the issue).
|
| |
self.assertEqual(kwargs['user_from'], self.user2.fullname)
|
| |
|
| |
+ @mock.patch('pagure.lib.notify.send_email')
|
| |
+ # for non-ASCII testing, we mock these return values
|
| |
+ @mock.patch('pagure.lib.git.get_author', return_value="Cecil Cõmmîttër")
|
| |
+ @mock.patch('pagure.lib.git.get_commit_subject', return_value="We love Motörhead")
|
| |
+ def test_notify_new_commits(self, _, __, fakemail): # pylint: disable=invalid-name
|
| |
+ """Test for notification on new commits, especially when
|
| |
+ non-ASCII text is involved.
|
| |
+ """
|
| |
+ exptext = u"""
|
| |
+ The following commits were pushed to the repo test on branch
|
| |
+ master, which you are following:
|
| |
+ abcdefg Cecil Cõmmîttër We love Motörhead
|
| |
+
|
| |
+
|
| |
+
|
| |
+ To view more about the commits, visit:
|
| |
+ https://pagure.org/test/commits/master
|
| |
+ """
|
| |
+ # first arg (abspath) doesn't matter and we can use a commit
|
| |
+ # ID that doesn't actually exist, as we are mocking
|
| |
+ # the get_author and get_commit_subject calls anyway
|
| |
+ pagure.lib.notify.notify_new_commits('/', self.project1, 'master', ['abcdefg'])
|
| |
+ (_, args, kwargs) = fakemail.mock_calls[0]
|
| |
+
|
| |
+ # Mail text should be as expected.
|
| |
+ self.assertEqual(args[0], exptext)
|
| |
+ self.assertTrue(isinstance(args[0], unicode))
|
| |
+
|
| |
+ # Mail subject should be as expected.
|
| |
+ self.assertEqual(args[1], u'New Commits To "test" (master)')
|
| |
+
|
| |
+ # Mail doesn't actually get sent to anyone by default
|
| |
+ self.assertEqual(args[2], '')
|
| |
+
|
| |
+ # Project name should be...project (full) name.
|
| |
+ self.assertEqual(kwargs['project_name'], self.project1.fullname)
|
| |
+
|
| |
# Add more tests to verify that correct mails are sent to correct people here
|
| |
|
| |
if __name__ == '__main__':
|
| |
This is an alternative to #3140. As @puiterwijk figured out,
when a new commit notification mail would contain non-ASCII
text - i.e. when the commit author's full name or the commit
topic contain non-ASCII text - sending the mail would fail. In
3.x at least, this resulted in the service that sends the mails
silently getting stuck; we don't know how the service behaves
when this happens in current git (it was changed from trollius
to celery), but the underlying bug is still there.
It fails because of unicode conversion issues in the new commit
notification function.
send_email
expects the body text to beprovided as a
unicode
instance, butnotify_new_commits
workswith
str
instances throughout (including the commit author andcommit topic values; these ultimately come in as UTF-8 encoded
strings, from the
pagure.git.read_output
function). Ultimatelyit produces a UTF-8 encoded
str
whichsend_email
then triesto encode again, and that crashes.
This approach fixes the problem in a way that's as consistent
as possible with the other functions in the file - the body text
is produced by
%s
-style string formatting of a unicode, and weensure the things that get put into it are also unicode type,
for the ones which can contain non-ASCII text. I also added some
comments about this area, noted the expected type for
text
inthe
send_email
docstring, and added a test.Fixes https://pagure.io/pagure/issue/1814
Signed-off-by: Adam Williamson awilliam@redhat.com