Changeset View
Changeset View
Standalone View
Standalone View
tests/functional/test_wallace/test_002_footer.py
Show All 11 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 TestWallaceFooter(unittest.TestCase): | class TestWallaceFooter(unittest.TestCase): | ||||
user = None | user = None | ||||
@classmethod | @classmethod | ||||
def setUp(self): | def setUp(self): | ||||
""" Compatibility for twisted.trial.unittest | """ Compatibility for twisted.trial.unittest | ||||
""" | """ | ||||
if not self.user: | if not self.user: | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | def check_message_delivered(self, subject): | ||||
if _msg['Subject'] == subject: | if _msg['Subject'] == subject: | ||||
found = True | found = True | ||||
time.sleep(1) | time.sleep(1) | ||||
return found | return found | ||||
def html_attachment(self): | def html_attachment(self): | ||||
html_body = "<html><body><p>This is an HTML attachment</p></body></html>" | html_body = "<html><body><p>This is an HTML attachment</p></body></html>" | ||||
Lint: PEP8 E501: line too long (81 > 79 characters) | |||||
html_part = MIMEBase("text", "html") | html_part = MIMEBase("text", "html") | ||||
html_part.add_header("Content-Disposition", "attachment", filename="html_attachment.html") | html_part.add_header("Content-Disposition", "attachment", filename="html_attachment.html") | ||||
Lint: PEP8 E501 line too long (98 > 79 characters) Lint: PEP8 E501: line too long (98 > 79 characters) | |||||
html_part.set_payload(html_body) | html_part.set_payload(html_body) | ||||
return html_part | return html_part | ||||
def image_attachment(self): | def image_attachment(self): | ||||
image_file = '/usr/share/kolab-webadmin/public_html/skins/default/images/logo_kolab.png' | image_file = '/usr/share/kolab-webadmin/public_html/skins/default/images/logo_kolab.png' | ||||
Lint: PEP8 E501 line too long (96 > 79 characters) Lint: PEP8 E501: line too long (96 > 79 characters) | |||||
image_part = MIMEImage(open(image_file, 'r').read()) | image_part = MIMEImage(open(image_file, 'r').read()) | ||||
image_part.add_header("Content-Disposition", "attachment", filename=os.path.basename(image_file)) | image_part.add_header("Content-Disposition", "attachment", filename=os.path.basename(image_file)) | ||||
Lint: PEP8 E501 line too long (105 > 79 characters) Lint: PEP8 E501: line too long (105 > 79 characters) | |||||
return image_part | return image_part | ||||
def message_standard_params(self, subject, msg): | def message_standard_params(self, subject, msg): | ||||
msg['From'] = self.message_from | msg['From'] = self.message_from | ||||
msg['To'] = self.message_to | msg['To'] = self.message_to | ||||
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() | ||||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | def test_006_send_html_with_attachment(self): | ||||
msg.attach(self.image_attachment()) | msg.attach(self.image_attachment()) | ||||
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 | ||||
def test_007_send_html_with_plaintext_alternative_and_attachment(self): | def test_007_send_html_with_plaintext_alternative_and_attachment(self): | ||||
subject = "test_007_send_html_with_plaintext_alternative_and_attachment" | subject = "test_007_send_html_with_plaintext_alternative_and_attachment" | ||||
Lint: PEP8 E501 line too long (80 > 79 characters) Lint: PEP8 E501: line too long (80 > 79 characters) | |||||
html_body = "<html><body><p>This is the HTML part</p></body></html>" | html_body = "<html><body><p>This is the HTML part</p></body></html>" | ||||
plain_body = "This is the plaintext part" | plain_body = "This is the plaintext part" | ||||
msg = MIMEMultipart("mixed") | msg = MIMEMultipart("mixed") | ||||
msg = self.message_standard_params(subject, msg) | msg = self.message_standard_params(subject, msg) | ||||
message_part = MIMEMultipart("alternative") | message_part = MIMEMultipart("alternative") | ||||
Show All 39 Lines | def test_009_send_plaintext_forwarded(self): | ||||
synchronize_once() | synchronize_once() | ||||
admin_login = conf.get('cyrus-imap', 'admin_login') | admin_login = conf.get('cyrus-imap', 'admin_login') | ||||
admin_password = conf.get('cyrus-imap', 'admin_password') | admin_password = conf.get('cyrus-imap', 'admin_password') | ||||
import sievelib.factory | import sievelib.factory | ||||
script = sievelib.factory.FiltersSet("test_wallace_test_009_forward") | script = sievelib.factory.FiltersSet("test_wallace_test_009_forward") | ||||
script.require("copy") | script.require("copy") | ||||
script.addfilter("forward", ["true"], [("redirect", ":copy", "john.doe@example.org")]) | script.addfilter("forward", ["true"], [("redirect", ":copy", "john.doe@example.org")]) | ||||
Lint: PEP8 E501 line too long (94 > 79 characters) Lint: PEP8 E501: line too long (94 > 79 characters) | |||||
import sievelib.managesieve | import sievelib.managesieve | ||||
sieveclient = sievelib.managesieve.Client('localhost', 4190, True) | sieveclient = sievelib.managesieve.Client('localhost', 4190, True) | ||||
sieveclient.connect(None, None, True) | sieveclient.connect(None, None, True) | ||||
sieveclient._plain_authentication(admin_login, admin_password, 'jane.doe@example.org') | sieveclient._plain_authentication(admin_login, admin_password, 'jane.doe@example.org') | ||||
Lint: PEP8 E501 line too long (94 > 79 characters) Lint: PEP8 E501: line too long (94 > 79 characters) | |||||
sieveclient.authenticated = True | sieveclient.authenticated = True | ||||
script_str = script.__str__() | script_str = script.__str__() | ||||
print script_str | print script_str | ||||
sieveclient.putscript("test_wallace_test_009_forward", script_str) | sieveclient.putscript("test_wallace_test_009_forward", script_str) | ||||
sieveclient.setactive("test_wallace_test_009_forward") | sieveclient.setactive("test_wallace_test_009_forward") | ||||
msg = MIMEText(body) | msg = MIMEText(body) | ||||
msg['From'] = self.message_from | msg['From'] = self.message_from | ||||
msg['To'] = '"Doe, Jane" <jane.doe@example.org>' | msg['To'] = '"Doe, Jane" <jane.doe@example.org>' | ||||
msg['Subject'] = subject | msg['Subject'] = subject | ||||
msg['Date'] = formatdate(localtime=True) | msg['Date'] = formatdate(localtime=True) | ||||
self.send_message(msg, _to='jane.doe@example.org', _from='john.doe@example.org') | self.send_message(msg, _to='jane.doe@example.org', _from='john.doe@example.org') | ||||
Lint: PEP8 E501 line too long (88 > 79 characters) Lint: PEP8 E501: line too long (88 > 79 characters) | |||||
raise Exception | raise Exception |
line too long (81 > 79 characters)