summaryrefslogtreecommitdiffstats
path: root/tests
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
parent75a9dfa0bd9a892fb89c04b7affa8a0e4b318f96 (diff)
downloadpykolab-e2fe4e32e8864cde22c4e38adb5cd1058aca2f89.tar.gz
Write and rebase a couple more tests
Diffstat (limited to 'tests')
-rw-r--r--tests/functional/test_kolabd/test_001_user_sync.py65
-rw-r--r--tests/functional/test_wallace/__init__.py6
-rw-r--r--tests/functional/test_wallace/test_001_user_add.py96
-rw-r--r--tests/functional/test_wap_client/test_002_user_add.py59
4 files changed, 175 insertions, 51 deletions
diff --git a/tests/functional/test_kolabd/test_001_user_sync.py b/tests/functional/test_kolabd/test_001_user_sync.py
index 2c3a144..e8e31bf 100644
--- a/tests/functional/test_kolabd/test_001_user_sync.py
+++ b/tests/functional/test_kolabd/test_001_user_sync.py
@@ -11,6 +11,9 @@ conf = pykolab.getConf()
class TestKolabDaemon(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'
@@ -19,6 +22,11 @@ class TestKolabDaemon(unittest.TestCase):
from tests.functional.user_add import user_add
user_add("John", "Doe")
+ @classmethod
+ def teardown_class(self, *args, **kw):
+ from tests.functional.purge_users import purge_users
+ purge_users()
+
def test_001_user_recipient_policy(self):
auth = Auth()
auth.connect()
@@ -28,11 +36,43 @@ class TestKolabDaemon(unittest.TestCase):
self.assertEqual(recipient, "uid=doe,ou=People,dc=example,dc=org")
- result = wap_client.user_info(recipient)
- self.assertEqual(result['mail'], 'john.doe@example.org')
- self.assertEqual(result['alias'], ['doe@example.org', 'j.doe@example.org'])
+ result_before = wap_client.user_info(recipient)
+
+ # Ensure the synchronization is run even without a kolab daemon running.
+ auth.synchronize(mode='_paged_search')
+
+ result_after = wap_client.user_info(recipient)
+ self.assertEqual(result_after['mail'], 'john.doe@example.org')
+ self.assertEqual(result_before['alias'], ['doe@example.org', 'j.doe@example.org', 'john.doe@example.org'])
+ self.assertEqual(result_after['alias'], ['doe@example.org', 'j.doe@example.org'])
- def test_002_user_mailbox_created(self):
+ def test_002_user_recipient_policy_duplicate(self):
+ from tests.functional.user_add import user_add
+ user = {
+ 'local': 'jane.doe',
+ 'domain': 'example.org'
+ }
+ user_add("Jane", "Doe")
+
+ auth = Auth()
+ auth.connect()
+ recipient = auth.find_recipient("%(local)s@%(domain)s" % (user))
+ if hasattr(self, 'assertIsInstance'):
+ self.assertIsInstance(recipient, str)
+
+ self.assertEqual(recipient, "uid=doe2,ou=People,dc=example,dc=org")
+
+ result_before = wap_client.user_info(recipient)
+
+ # Ensure the synchronization is run even without a kolab daemon running.
+ auth.synchronize(mode='_paged_search')
+
+ result_after = wap_client.user_info(recipient)
+ self.assertEqual(result_after['mail'], 'jane.doe@example.org')
+ self.assertEqual(result_before['alias'], ['doe2@example.org', 'j.doe2@example.org', 'jane.doe@example.org'])
+ self.assertEqual(result_after['alias'], ['doe2@example.org', 'j.doe2@example.org'])
+
+ def test_003_user_mailbox_created(self):
time.sleep(2)
imap = IMAP()
imap.connect()
@@ -40,7 +80,7 @@ class TestKolabDaemon(unittest.TestCase):
folders = imap.lm('user/%(local)s@%(domain)s' % (self.user))
self.assertEqual(len(folders), 1)
- def test_003_user_additional_folders_created(self):
+ def test_004_user_additional_folders_created(self):
time.sleep(2)
imap = IMAP()
imap.connect()
@@ -51,7 +91,7 @@ class TestKolabDaemon(unittest.TestCase):
self.assertEqual(len(folders), len(ac_folders.keys()))
- def test_004_user_folder_annotations_set(self):
+ def test_005_user_folders_metadata_set(self):
imap = IMAP()
imap.connect()
@@ -62,18 +102,21 @@ class TestKolabDaemon(unittest.TestCase):
folders.extend(imap.lm('user/%(local)s/*@%(domain)s' % (self.user)))
for folder in folders:
- annotation = imap.getannotation(folder)
- print annotation
+ metadata = imap.get_metadata(folder)
+ print metadata
folder_name = '/'.join(folder.split('/')[2:]).split('@')[0]
if ac_folders.has_key(folder_name):
if ac_folders[folder_name].has_key('annotations'):
for _annotation in ac_folders[folder_name]['annotations'].keys():
+ if _annotation.startswith('/private'):
+ continue
+
_annotation_value = ac_folders[folder_name]['annotations'][_annotation]
- self.assertTrue(annotation[annotation.keys().pop()].has_key(_annotation))
- self.assertEqual(_annotation_value, annotation[annotation.keys().pop()][_annotation])
+ self.assertTrue(metadata[metadata.keys().pop()].has_key(_annotation))
+ self.assertEqual(_annotation_value, metadata[metadata.keys().pop()][_annotation])
- def test_005_user_subscriptions(self):
+ def test_006_user_subscriptions(self):
imap = IMAP()
imap.connect(login=False)
login = conf.get('cyrus-imap', 'admin_login')
diff --git a/tests/functional/test_wallace/__init__.py b/tests/functional/test_wallace/__init__.py
new file mode 100644
index 0000000..d7bf27f
--- /dev/null
+++ b/tests/functional/test_wallace/__init__.py
@@ -0,0 +1,6 @@
+import pykolab
+
+def setup_package():
+ conf = pykolab.getConf()
+ conf.finalize_conf(fatal=False)
+
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
diff --git a/tests/functional/test_wap_client/test_002_user_add.py b/tests/functional/test_wap_client/test_002_user_add.py
index 84eeeb2..96c3de1 100644
--- a/tests/functional/test_wap_client/test_002_user_add.py
+++ b/tests/functional/test_wap_client/test_002_user_add.py
@@ -3,18 +3,17 @@ 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):
- conf.finalize_conf(fatal=False)
-
- self.login = conf.get('ldap', 'bind_dn')
- self.password = conf.get('ldap', 'bind_pw')
- self.domain = conf.get('kolab', 'primary_domain')
+ from tests.functional.purge_users import purge_users
+ purge_users()
self.user = {
'local': 'john.doe',
@@ -23,8 +22,16 @@ class TestUserAdd(unittest.TestCase):
from tests.functional.user_add import user_add
user_add("John", "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):
+
time.sleep(2)
imap = IMAP()
imap.connect()
@@ -46,7 +53,7 @@ class TestUserAdd(unittest.TestCase):
self.assertEqual(len(folders), len(ac_folders.keys()))
- def test_003_folder_types_set(self):
+ def test_003_folders_metadata_set(self):
imap = IMAP()
imap.connect()
@@ -57,45 +64,17 @@ class TestUserAdd(unittest.TestCase):
folders.extend(imap.lm('user/%(local)s/*@%(domain)s' % (self.user)))
for folder in folders:
- annotation = imap.getannotation(folder)
- print annotation
+ metadata = imap.get_metadata(folder)
folder_name = '/'.join(folder.split('/')[2:]).split('@')[0]
if ac_folders.has_key(folder_name):
if ac_folders[folder_name].has_key('annotations'):
for _annotation in ac_folders[folder_name]['annotations'].keys():
- _annotation_value = ac_folders[folder_name]['annotations'][_annotation]
- self.assertTrue(annotation[annotation.keys().pop()].has_key(_annotation))
- self.assertEqual(_annotation_value, annotation[annotation.keys().pop()][_annotation])
-
- @classmethod
- def teardown_class(self):
- time.sleep(2)
-
- res_attr = conf.get('cyrus-sasl', 'result_attribute')
+ if _annotation.startswith('/private/'):
+ continue
- exec("ac_folders = %s" % (conf.get_raw(conf.get('kolab', 'primary_domain'), 'autocreate_folders')))
- expected_number_of_folders = len(ac_folders.keys()) + 1
-
- users = []
-
- result = wap_client.users_list()
- for user in result['list'].keys():
- user_info = wap_client.user_info(user)
- users.append(user_info)
- result = wap_client.user_delete({'user': user})
-
- imap = IMAP()
- imap.connect()
-
- for user in users:
- if len(user[res_attr].split('@')) > 1:
- localpart = user[res_attr].split('@')[0]
- domain = user[res_attr].split('@')[1]
-
- folders = []
- folders.extend(imap.lm('user/%s' % (user[res_attr])))
- folders.extend(imap.lm('user/%s/*@%s' % (localpart,domain)))
+ _annotation_value = ac_folders[folder_name]['annotations'][_annotation]
+ self.assertTrue(metadata[metadata.keys().pop()].has_key(_annotation))
+ self.assertEqual(_annotation_value, metadata[metadata.keys().pop()][_annotation])
- # Expect folders length to be 0