Resolved encoding/decoding problem.
In MIMEtext by default encodes in 'us-ascii' for py27 and 'utf-8' in py34. So 'utf-8' encoding is specified in argument. Also in py27 constant string is already in unicode type but in py34 it is byte type. So string is decoded for py27 in unit test. Partially-Implements: blueprint mistral-py3 Change-Id: I7004bae1d46d20630a30cac1abb65efe68765401
This commit is contained in:
parent
46b00683c0
commit
3170c112c7
@ -15,18 +15,19 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from email.header import Header
|
||||
from email.mime import text
|
||||
|
||||
import json
|
||||
import requests
|
||||
import smtplib
|
||||
|
||||
from oslo_log import log as logging
|
||||
|
||||
from mistral.actions import base
|
||||
from mistral import exceptions as exc
|
||||
from mistral.utils import javascript
|
||||
from mistral.utils import ssh_utils
|
||||
from mistral.workflow import utils as wf_utils
|
||||
from oslo_log import log as logging
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@ -286,9 +287,8 @@ class SendEmailAction(base.Action):
|
||||
(self.sender, self.to, self.subject,
|
||||
self.smtp_server, self.body[:128]))
|
||||
|
||||
# TODO(dzimine): handle utf-8, http://stackoverflow.com/a/14506784
|
||||
message = text.MIMEText(self.body)
|
||||
message['Subject'] = self.subject
|
||||
message = text.MIMEText(self.body, _charset='utf-8')
|
||||
message['Subject'] = Header(self.subject, 'utf-8')
|
||||
message['From'] = self.sender
|
||||
message['To'] = self.to
|
||||
|
||||
|
@ -14,8 +14,11 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import base64
|
||||
from email.header import decode_header
|
||||
from email import parser
|
||||
import mock
|
||||
import six
|
||||
import testtools
|
||||
|
||||
from mistral.actions import std_actions as std
|
||||
@ -103,8 +106,26 @@ class SendEmailActionTest(base.BaseTest):
|
||||
|
||||
self.assertEqual(self.from_addr, message['from'])
|
||||
self.assertEqual(self.to_addrs_str, message['to'])
|
||||
self.assertEqual(self.subject, message['subject'])
|
||||
self.assertEqual(self.body, message.get_payload())
|
||||
if six.PY3:
|
||||
self.assertEqual(
|
||||
self.subject,
|
||||
decode_header(message['subject'])[0][0].decode('utf-8')
|
||||
)
|
||||
else:
|
||||
self.assertEqual(
|
||||
self.subject.decode('utf-8'),
|
||||
decode_header(message['subject'])[0][0].decode('utf-8')
|
||||
)
|
||||
if six.PY3:
|
||||
self.assertEqual(
|
||||
self.body,
|
||||
base64.b64decode(message.get_payload()).decode('utf-8')
|
||||
)
|
||||
else:
|
||||
self.assertEqual(
|
||||
self.body.decode('utf-8'),
|
||||
base64.b64decode(message.get_payload()).decode('utf-8')
|
||||
)
|
||||
|
||||
@mock.patch('smtplib.SMTP')
|
||||
def test_with_password(self, smtp):
|
||||
|
Loading…
Reference in New Issue
Block a user