summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2013-02-17 11:11:23 -0500
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2013-02-17 11:11:23 -0500
commite3b4839c0a0e11f5955d548d630bef0d51846ebd (patch)
tree631b932030ed3b17d3cef93e138455253ca307b6 /tests
parent8aea889ec8da68d7caf552732b164a1865142730 (diff)
parentd80a04b456bdfafa64822fe5f310ff0dc332de6e (diff)
downloadpykolab-e3b4839c0a0e11f5955d548d630bef0d51846ebd.tar.gz
Merge branch 'master' of ssh://git.kolabsys.com/git/pykolab
Diffstat (limited to 'tests')
-rw-r--r--tests/functional/test_wallace/test_002_footer.py8
-rw-r--r--tests/functional/test_wallace/test_003_nonascii_subject.py126
-rw-r--r--tests/functional/test_wallace/test_004_nonascii_addresses.py126
-rw-r--r--tests/unit/test-010-transliterate.py7
4 files changed, 263 insertions, 4 deletions
diff --git a/tests/functional/test_wallace/test_002_footer.py b/tests/functional/test_wallace/test_002_footer.py
index c8e2f4a..ac3e1ba 100644
--- a/tests/functional/test_wallace/test_002_footer.py
+++ b/tests/functional/test_wallace/test_002_footer.py
@@ -54,10 +54,10 @@ class TestWallaceFooter(unittest.TestCase):
from tests.functional.synchronize import synchronize_once
synchronize_once()
-# @classmethod
-# def teardown_class(self, *args, **kw):
-# from tests.functional.purge_users import purge_users
-# purge_users()
+ @classmethod
+ def teardown_class(self, *args, **kw):
+ from tests.functional.purge_users import purge_users
+ purge_users()
def check_message_delivered(self, subject):
imap = IMAP()
diff --git a/tests/functional/test_wallace/test_003_nonascii_subject.py b/tests/functional/test_wallace/test_003_nonascii_subject.py
new file mode 100644
index 0000000..ff21aee
--- /dev/null
+++ b/tests/functional/test_wallace/test_003_nonascii_subject.py
@@ -0,0 +1,126 @@
+# *-* encoding: utf-8 *-*
+from email.header import Header
+from email import message_from_string
+from email.MIMEMultipart import MIMEMultipart
+from email.MIMEBase import MIMEBase
+from email.MIMEImage import MIMEImage
+from email.MIMEText import MIMEText
+from email.Utils import COMMASPACE, formatdate
+from email import Encoders
+import os
+import smtplib
+import time
+import unittest
+
+import pykolab
+from pykolab import wap_client
+from pykolab.auth import Auth
+from pykolab.imap import IMAP
+
+conf = pykolab.getConf()
+
+class TestWallaceNonASCIISubject(unittest.TestCase):
+
+ @classmethod
+ def setup_class(self, *args, **kw):
+ from tests.functional.purge_users import purge_users
+ purge_users()
+
+ self.user = {
+ 'local': 'john.doe',
+ 'domain': 'example.org'
+ }
+
+ self.send_to = 'john.doe@example.org'
+ self.send_from = 'john.doe@example.org'
+
+ self.message_to = '"Doe, John" <%s>' % (self.send_to)
+ self.message_from = '"Doe, John" <%s>' % (self.send_from)
+
+ from tests.functional.user_add import user_add
+ user_add("John", "Doe")
+ time.sleep(2)
+ from tests.functional.synchronize import synchronize_once
+ synchronize_once()
+
+ @classmethod
+ def teardown_class(self, *args, **kw):
+ from tests.functional.purge_users import purge_users
+ purge_users()
+
+ def check_message_delivered(self, subject):
+ imap = IMAP()
+ imap.connect()
+ imap.set_acl("user/john.doe@example.org", "cyrus-admin", "lrs")
+ imap.imap.m.select("user/john.doe@example.org")
+
+ found = False
+ max_tries = 20
+
+ while not found and max_tries > 0:
+ max_tries -= 1
+
+ typ, data = imap.imap.m.search(None, 'ALL')
+ for num in data[0].split():
+ typ, msg = imap.imap.m.fetch(num, '(RFC822)')
+ _msg = message_from_string(msg[0][1])
+ if _msg['Subject'] == subject:
+ found = True
+
+ time.sleep(1)
+
+ return found
+
+ def message_standard_params(self, subject, msg):
+ msg['From'] = self.message_from
+ msg['To'] = self.message_to
+
+ msg['Subject'] = subject
+ msg['Date'] = formatdate(localtime=True)
+
+ return msg
+
+ def send_message(self, msg, _to=None, _from=None):
+ smtp = smtplib.SMTP('localhost', 10026)
+
+ if _to == None:
+ _to = self.send_to
+
+ if _from == None:
+ _from = self.send_from
+
+ smtp.sendmail(_from, _to, msg.as_string())
+
+ def test_001_inbox_created(self):
+ imap = IMAP()
+ imap.connect()
+
+ folders = imap.lm('user/%(local)s@%(domain)s' % (self.user))
+ self.assertEqual(len(folders), 1)
+
+ def test_002_send_nonascii_subject(self):
+ subject = Header(u"test_002_nonascii_subject chwała")
+ body = "This is a test message"
+ msg = MIMEBase("text", "plain")
+ msg = self.message_standard_params(subject, msg)
+
+ msg.set_payload(body)
+
+ self.send_message(msg)
+
+ if not self.check_message_delivered(subject):
+ raise Exception
+
+ def test_003_send_nonascii_subject(self):
+ subject = Header(u"test_003_nonascii_subject Тест")
+ body = "This is a test message"
+ msg = MIMEBase("text", "plain")
+ msg = self.message_standard_params(subject, msg)
+
+ msg.set_payload(body)
+
+ self.send_message(msg)
+
+ if not self.check_message_delivered(subject):
+ raise Exception
+
diff --git a/tests/functional/test_wallace/test_004_nonascii_addresses.py b/tests/functional/test_wallace/test_004_nonascii_addresses.py
new file mode 100644
index 0000000..45df30e
--- /dev/null
+++ b/tests/functional/test_wallace/test_004_nonascii_addresses.py
@@ -0,0 +1,126 @@
+# *-* encoding: utf-8 *-*
+from email.header import Header
+from email import message_from_string
+from email.MIMEMultipart import MIMEMultipart
+from email.MIMEBase import MIMEBase
+from email.MIMEImage import MIMEImage
+from email.MIMEText import MIMEText
+from email.Utils import COMMASPACE, formatdate
+from email import Encoders
+import os
+import smtplib
+import time
+import unittest
+
+import pykolab
+from pykolab import wap_client
+from pykolab.auth import Auth
+from pykolab.imap import IMAP
+
+conf = pykolab.getConf()
+
+class TestWallaceNonASCIIAddresses(unittest.TestCase):
+
+ @classmethod
+ def setup_class(self, *args, **kw):
+ from tests.functional.purge_users import purge_users
+ purge_users()
+
+ self.user = {
+ 'local': 'nikolaj.rimskij-korsakov',
+ 'domain': 'example.org'
+ }
+
+ self.send_to = 'nikolaj.rimskij-korsakov@example.org'
+ self.send_from = 'nikolaj.rimskij-korsakov@example.org'
+
+ self.message_to = '"Римский-Корсаков, Николай" <%s>' % (self.send_to)
+ self.message_from = '"Римский-Корсаков, Николай" <%s>' % (self.send_from)
+
+ from tests.functional.user_add import user_add
+ user_add("Николай", "Римский-Корсаков", preferredlanguage='ru_RU')
+ time.sleep(2)
+ from tests.functional.synchronize import synchronize_once
+ synchronize_once()
+
+ @classmethod
+ def teardown_class(self, *args, **kw):
+ from tests.functional.purge_users import purge_users
+ purge_users()
+
+ def check_message_delivered(self, subject):
+ imap = IMAP()
+ imap.connect()
+ imap.set_acl("user/nikolaj.rimskij-korsakov@example.org", "cyrus-admin", "lrs")
+ imap.imap.m.select("user/nikolaj.rimskij-korsakov@example.org")
+
+ found = False
+ max_tries = 20
+
+ while not found and max_tries > 0:
+ max_tries -= 1
+
+ typ, data = imap.imap.m.search(None, 'ALL')
+ for num in data[0].split():
+ typ, msg = imap.imap.m.fetch(num, '(RFC822)')
+ _msg = message_from_string(msg[0][1])
+ if _msg['Subject'] == subject:
+ found = True
+
+ time.sleep(1)
+
+ return found
+
+ def message_standard_params(self, subject, msg):
+ msg['From'] = Header(self.message_from)
+ msg['To'] = Header(self.message_to)
+
+ msg['Subject'] = subject
+ msg['Date'] = formatdate(localtime=True)
+
+ return msg
+
+ def send_message(self, msg, _to=None, _from=None):
+ smtp = smtplib.SMTP('localhost', 10026)
+
+ if _to == None:
+ _to = self.send_to
+
+ if _from == None:
+ _from = self.send_from
+
+ smtp.sendmail(_from, _to, msg.as_string())
+
+ def test_001_inbox_created(self):
+ imap = IMAP()
+ imap.connect()
+
+ folders = imap.lm('user/%(local)s@%(domain)s' % (self.user))
+ self.assertEqual(len(folders), 1)
+
+ def test_002_send_nonascii_addresses(self):
+ subject = Header(u"test_002_nonascii_addresses")
+ body = "This is a test message"
+ msg = MIMEBase("text", "plain")
+ msg = self.message_standard_params(subject, msg)
+
+ msg.set_payload(body)
+
+ self.send_message(msg)
+
+ if not self.check_message_delivered(subject):
+ raise Exception
+
+ def test_003_send_nonascii_subject(self):
+ subject = Header(u"test_003_nonascii_subject Тест")
+ body = "This is a test message"
+ msg = MIMEBase("text", "plain")
+ msg = self.message_standard_params(subject, msg)
+
+ msg.set_payload(body)
+
+ self.send_message(msg)
+
+ if not self.check_message_delivered(subject):
+ raise Exception
+
diff --git a/tests/unit/test-010-transliterate.py b/tests/unit/test-010-transliterate.py
index 3c98a1a..e6b9000 100644
--- a/tests/unit/test-010-transliterate.py
+++ b/tests/unit/test-010-transliterate.py
@@ -99,5 +99,12 @@ class TestTransliteration(unittest.TestCase):
self.assertEqual('Yuliya', utils.translate(givenname, preferredlanguage))
self.assertEqual('Yolkina', utils.translate(surname, preferredlanguage))
+ def test_009_raw_decode(self):
+ raw_str = r"Николай"
+ self.assertEqual('Николай', raw_str.decode("string_escape"))
+
+ raw_str = r"raw"
+ self.assertEqual('raw', raw_str.decode("string_escape"))
+
if __name__ == '__main__':
unittest.main()