summaryrefslogtreecommitdiffstats
path: root/tests/functional/test_wallace/test_001_user_add.py
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-12-24 17:15:48 +0100
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-12-24 17:15:48 +0100
commite2fe4e32e8864cde22c4e38adb5cd1058aca2f89 (patch)
treed796c70327f834a8c45cde35fbb2f5be222f12d9 /tests/functional/test_wallace/test_001_user_add.py
parent75a9dfa0bd9a892fb89c04b7affa8a0e4b318f96 (diff)
downloadpykolab-e2fe4e32e8864cde22c4e38adb5cd1058aca2f89.tar.gz
Write and rebase a couple more tests
Diffstat (limited to 'tests/functional/test_wallace/test_001_user_add.py')
-rw-r--r--tests/functional/test_wallace/test_001_user_add.py96
1 files changed, 96 insertions, 0 deletions
diff --git a/tests/functional/test_wallace/test_001_user_add.py b/tests/functional/test_wallace/test_001_user_add.py
new file mode 100644
index 0000000..9a2c587
--- /dev/null
+++ b/tests/functional/test_wallace/test_001_user_add.py
@@ -0,0 +1,96 @@
+
+from email import message_from_string
+
+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 TestUserAdd(unittest.TestCase):
+
+ @classmethod
+ def setup_class(self, *args, **kw):
+ from tests.functional.purge_users import purge_users
+ purge_users()
+
+ self.john = {
+ 'local': 'john.doe',
+ 'domain': 'example.org'
+ }
+
+ self.jane = {
+ 'local': 'john.doe',
+ 'domain': 'example.org'
+ }
+
+ from tests.functional.user_add import user_add
+ user_add("John", "Doe")
+ user_add("Jane", "Doe")
+ 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 test_001_inbox_created(self):
+ imap = IMAP()
+ imap.connect()
+
+ folders = imap.lm('user/%(local)s@%(domain)s' % (self.john))
+ self.assertEqual(len(folders), 1)
+
+ folders = imap.lm('user/%(local)s@%(domain)s' % (self.jane))
+ self.assertEqual(len(folders), 1)
+
+ def test_002_send_forwarded_email(self):
+ import smtplib
+ from email.MIMEMultipart import MIMEMultipart
+ from email.MIMEBase import MIMEBase
+ from email.MIMEText import MIMEText
+ from email.Utils import COMMASPACE, formatdate
+ from email import Encoders
+
+ smtp = smtplib.SMTP('localhost', 10026)
+ subject = "%s" % (time.time())
+ body = "This is a test message"
+ msg = MIMEMultipart()
+ msg['From'] = '"Doe, Jane" <jane.doe@example.org>'
+ msg['To'] = '"Doe, John" <john.doe@example.org>'
+ msg['Subject'] = subject
+ msg['Date'] = formatdate(localtime=True)
+ msg.attach(MIMEText(body))
+
+ send_to = 'jane.doe@example.org'
+ send_from = 'john.doe@example.org'
+
+ smtp.sendmail(send_from, send_to, msg.as_string())
+
+ imap = IMAP()
+ imap.connect()
+ imap.set_acl("user/jane.doe@example.org", "cyrus-admin", "lrs")
+ imap.imap.m.select("user/jane.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)
+
+ if not found:
+ raise Exception