Changeset View
Changeset View
Standalone View
Standalone View
tests/functional/test_wallace/test_004_nonascii_addresses.py
Show All 13 Lines | |||||
import pykolab | import pykolab | ||||
from pykolab import wap_client | from pykolab import wap_client | ||||
from pykolab.auth import Auth | from pykolab.auth import Auth | ||||
from pykolab.imap import IMAP | from pykolab.imap import IMAP | ||||
conf = pykolab.getConf() | conf = pykolab.getConf() | ||||
class TestWallaceNonASCIIAddresses(unittest.TestCase): | class TestWallaceNonASCIIAddresses(unittest.TestCase): | ||||
@classmethod | @classmethod | ||||
def setup_class(self, *args, **kw): | def setup_class(self, *args, **kw): | ||||
from tests.functional.purge_users import purge_users | from tests.functional.purge_users import purge_users | ||||
purge_users() | purge_users() | ||||
self.user = { | self.user = { | ||||
'local': 'nikolaj.rimskij-korsakov', | 'local': 'nikolaj.rimskij-korsakov', | ||||
'domain': 'example.org' | 'domain': 'example.org' | ||||
} | } | ||||
self.send_to = 'nikolaj.rimskij-korsakov@example.org' | self.send_to = 'nikolaj.rimskij-korsakov@example.org' | ||||
self.send_from = 'nikolaj.rimskij-korsakov@example.org' | self.send_from = 'nikolaj.rimskij-korsakov@example.org' | ||||
self.message_to = '"Римский-Корсаков, Николай" <%s>' % (self.send_to) | self.message_to = '"Римский-Корсаков, Николай" <%s>' % (self.send_to) | ||||
self.message_from = '"Римский-Корсаков, Николай" <%s>' % (self.send_from) | self.message_from = '"Римский-Корсаков, Николай" <%s>' % (self.send_from) | ||||
Lint: PEP8 E501: line too long (81 > 79 characters) | |||||
from tests.functional.user_add import user_add | from tests.functional.user_add import user_add | ||||
user_add("Николай", "Римский-Корсаков", preferredlanguage='ru_RU') | user_add("Николай", "Римский-Корсаков", preferredlanguage='ru_RU') | ||||
time.sleep(2) | time.sleep(2) | ||||
from tests.functional.synchronize import synchronize_once | from tests.functional.synchronize import synchronize_once | ||||
synchronize_once() | synchronize_once() | ||||
@classmethod | @classmethod | ||||
def teardown_class(self, *args, **kw): | def teardown_class(self, *args, **kw): | ||||
from tests.functional.purge_users import purge_users | from tests.functional.purge_users import purge_users | ||||
purge_users() | purge_users() | ||||
def check_message_delivered(self, subject): | def check_message_delivered(self, subject): | ||||
imap = IMAP() | imap = IMAP() | ||||
imap.connect() | imap.connect() | ||||
imap.set_acl("user/nikolaj.rimskij-korsakov@example.org", "cyrus-admin", "lrs") | imap.set_acl("user/nikolaj.rimskij-korsakov@example.org", "cyrus-admin", "lrs") | ||||
Lint: PEP8 E501 line too long (87 > 79 characters) Lint: PEP8 E501: line too long (87 > 79 characters) | |||||
imap.imap.m.select("user/nikolaj.rimskij-korsakov@example.org") | imap.imap.m.select("user/nikolaj.rimskij-korsakov@example.org") | ||||
found = False | found = False | ||||
max_tries = 20 | max_tries = 20 | ||||
while not found and max_tries > 0: | while not found and max_tries > 0: | ||||
max_tries -= 1 | max_tries -= 1 | ||||
Show All 15 Lines | def message_standard_params(self, subject, msg): | ||||
msg['Subject'] = subject | msg['Subject'] = subject | ||||
msg['Date'] = formatdate(localtime=True) | msg['Date'] = formatdate(localtime=True) | ||||
return msg | return msg | ||||
def send_message(self, msg, _to=None, _from=None): | def send_message(self, msg, _to=None, _from=None): | ||||
smtp = smtplib.SMTP('localhost', 10026) | smtp = smtplib.SMTP('localhost', 10026) | ||||
if _to == None: | if _to is None: | ||||
_to = self.send_to | _to = self.send_to | ||||
if _from == None: | if _from is None: | ||||
_from = self.send_from | _from = self.send_from | ||||
smtp.sendmail(_from, _to, msg.as_string()) | smtp.sendmail(_from, _to, msg.as_string()) | ||||
def test_001_inbox_created(self): | def test_001_inbox_created(self): | ||||
imap = IMAP() | imap = IMAP() | ||||
imap.connect() | imap.connect() | ||||
folders = imap.lm('user/%(local)s@%(domain)s' % (self.user)) | folders = imap.lm('user/%(local)s@%(domain)s' % (self.user)) | ||||
self.assertEqual(len(folders), 1) | self.assertEqual(len(folders), 1) | ||||
def test_002_send_nonascii_addresses(self): | def test_002_send_nonascii_addresses(self): | ||||
subject = Header(u"test_002_nonascii_addresses") | subject = Header(u"test_002_nonascii_addresses") | ||||
body = "This is a test message" | body = "This is a test message" | ||||
msg = MIMEBase("text", "plain") | msg = MIMEBase("text", "plain") | ||||
msg = self.message_standard_params(subject, msg) | msg = self.message_standard_params(subject, msg) | ||||
msg.set_payload(body) | msg.set_payload(body) | ||||
Show All 9 Lines | def test_003_send_nonascii_subject(self): | ||||
msg = self.message_standard_params(subject, msg) | msg = self.message_standard_params(subject, msg) | ||||
msg.set_payload(body) | msg.set_payload(body) | ||||
self.send_message(msg) | self.send_message(msg) | ||||
if not self.check_message_delivered(subject): | if not self.check_message_delivered(subject): | ||||
raise Exception | raise Exception | ||||
line too long (81 > 79 characters)