Commit b2c0a0f8 authored by godog's avatar godog
Browse files

test: fix tests for Python 3

parent 05b636b1
import codecs
import email
import imaplib
import os
......@@ -57,7 +58,7 @@ class TestMail(TestBase):
imap.login, 'foo@example.com', 'wrong password')
def _create_msg(self, sender, rcpt):
unique_id = os.urandom(4).encode('hex')
unique_id = codecs.encode(os.urandom(4), 'hex')
msg = MIMEText('This is a test message, please ignore.')
msg['Subject'] = 'test message #%s' % unique_id
msg['X-UniqueID'] = unique_id
......@@ -65,12 +66,12 @@ class TestMail(TestBase):
msg['To'] = rcpt
msg['Date'] = formatdate()
return msg, unique_id
def _send_email(self, sender, sender_password, rcpt, from_addr=None):
if not from_addr:
from_addr = sender
msg, unique_id = self._create_msg(from_addr, rcpt)
conn = smtplib.SMTP(self.frontend_ip(), 587)
conn.ehlo()
conn.starttls()
......@@ -86,7 +87,7 @@ class TestMail(TestBase):
def _send_email_and_read_it(self, sender, sender_password, rcpt,
imap_user, imap_password):
unique_id = self._send_email(sender, sender_password, rcpt)
imap = imaplib.IMAP4_SSL(self.frontend_ip())
imap.login(imap_user, imap_password)
imap.select('INBOX')
......@@ -161,9 +162,9 @@ class TestMail(TestBase):
# example.com has a SPF record that should cause the delivery to fail.
sender = 'external@example.com'
rcpt = self.users['nonpriv']['name']
msg, unique_id = self._create_msg(sender, rcpt)
conn = smtplib.SMTP(self.frontend_ip(), 25)
conn.ehlo()
self.assertRaises(
......@@ -187,7 +188,7 @@ class TestMail(TestBase):
conn.ehlo(sender_hostname)
conn.sendmail(
sender, [rcpt], msg.as_string())
def test_smtp_spf_pass(self):
# Test a successful delivery from a real Internet host.
sender = 'ale@incal.net'
......@@ -228,4 +229,3 @@ class TestMail(TestBase):
'password',
'uno@investici.org',
from_addr='uno@investici.org')
......@@ -17,6 +17,5 @@ class TestPannello(TestBase):
# page (such as set-password-recovery-hint etc).
# We simply match part of the common <title>.
self.assertTrue(
'Accounts' in result['body'],
'Accounts' in str(result['body']),
'Unexpected pannello homepage:\n%s' % result['body'])
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment