Skip to content

Commit f59de34

Browse files
authored
Merge pull request #68 from gisce/82507_cast_pass_str
fer un cast del pass per controlar py2 i py3
2 parents 9ba5793 + 8c1441f commit f59de34

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

qreu/sendcontext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def __enter__(self):
110110
else:
111111
raise
112112
if self._user and self._passwd:
113-
self._connection.login(user=self._user, password=self._passwd)
113+
self._connection.login(user=self._user, password=str(self._passwd))
114114
return super(SMTPSender, self).__enter__()
115115

116116
def __exit__(self, etype, evalue, etraceback):

spec/sendcontext_spec.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,23 @@ def call_wrongly():
142142
msmtp.side_effect = SMTPConnectError(
143143
530, "5.7.0 Must issue a STARTTLS command first.")
144144
expect(call_wrongly).to(raise_error)
145+
146+
with it('must "send" via smtp the email with SMTPSender'):
147+
with patch('qreu.sendcontext.SMTP') as mocked_conn:
148+
# Mock the SMTP connection
149+
smtp_mocked = Mock()
150+
smtp_mocked.login.return_value = True
151+
smtp_mocked.starttls.return_value = True
152+
smtp_mocked.login.return_value = True
153+
smtp_mocked.send.return_value = True
154+
smtp_mocked.sendmail.return_value = True
155+
smtp_mocked.close.return_value = True
156+
mocked_conn.return_value = smtp_mocked
157+
with SMTPSender(
158+
host='host',
159+
user='user',
160+
passwd=u'passwd',
161+
ssl_keyfile='ssl_keyfile',
162+
ssl_certfile='ssl_certfile'
163+
) as sender:
164+
sender.send(self.test_mail)

0 commit comments

Comments
 (0)