Pylons/pyramid_mailer — Issue #6: error while executing tests
Author: ikame
Created: 2011-12-10 02:34:25+00:00
State: open

TestMailResponse.test_to_message_with_parts2 fails when running the tests.
I think the issue occurs because in pyramid_mailer.response.MIMEPart.add_text() method is assuming that the "content" variable is "encodable" ("content" is unicode) and tries to encode it, but this must fail in the case you are working with Python 2 and the "content" variable is already an encoded string.

Here's the traceback:
======================================================================
ERROR: test_to_message_with_parts2 (pyramid_mailer.tests.TestMailResponse)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/anler/github/pyramid_mailer/pyramid_mailer/tests.py", line 856, in test_to_message_with_parts2
message = response.to_message()
File "/Users/anler/github/pyramid_mailer/pyramid_mailer/response.py", line 301, in to_message
return to_message(self.base)
File "/Users/anler/github/pyramid_mailer/pyramid_mailer/response.py", line 351, in to_message
out.attach(to_message(part))
File "/Users/anler/github/pyramid_mailer/pyramid_mailer/response.py", line 347, in to_message
out.extract_payload(mail)
File "/Users/anler/github/pyramid_mailer/pyramid_mailer/response.py", line 401, in extract_payload
self.add_text(mail.body)
File "/Users/anler/github/pyramid_mailer/pyramid_mailer/response.py", line 376, in add_text
encoded = content.encode('utf-8')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf3 in position 1: ordinal not in range(128)