kojid: use binary msg for python3 in *Notification tasks

fixes: #1882
This commit is contained in:
Yu Ming Zhu 2019-12-20 07:27:08 +00:00 committed by Tomas Kopecek
parent 0c56cad2b5
commit 8d4a5c7129
2 changed files with 20 additions and 9 deletions

View file

@ -4934,9 +4934,12 @@ Status: %(status)s\r
message = self.message_templ % locals()
# ensure message is in UTF-8
message = koji.fixEncoding(message)
# binary for python3
if six.PY3:
message = message.encode('utf8')
server = smtplib.SMTP(self.options.smtphost)
#server.set_debuglevel(True)
server.sendmail(from_addr, recipients, message)
server.quit()
@ -5143,7 +5146,9 @@ Build Info: %(weburl)s/buildinfo?buildID=%(build_id)i\r
message = self.message_templ % locals()
# ensure message is in UTF-8
message = koji.fixEncoding(message)
# binary for python3
if six.PY3:
message = message.encode('utf8')
server = smtplib.SMTP(self.options.smtphost)
# server.set_debuglevel(True)
server.sendmail(from_addr, recipients, message)

View file

@ -1,19 +1,24 @@
from __future__ import absolute_import
import json
import locale
import mock
import os
import tempfile
try:
import unittest2 as unittest
except ImportError:
import unittest
import time
import mock
import six
import koji
import koji.util
from .loadkojid import kojid
try:
import unittest2 as unittest
except ImportError:
import unittest
class MyClientSession(koji.ClientSession):
@ -103,7 +108,8 @@ class TestBuildNotification(unittest.TestCase):
self.assertEqual(recipients, ["user@example.com"])
fn = os.path.join(os.path.dirname(__file__), 'data/calls', 'build_notif_1', 'message.txt')
with open(fn, 'rb') as fp:
msg_expect = fp.read().decode()
msg_expect = fp.read()
if six.PY2:
msg_expect = msg_expect.decode()
self.assertEqual(message, msg_expect)
locale.resetlocale()