summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-07-20 10:34:05 +0100
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-07-20 10:34:05 +0100
commitefaef7e429879c34d30c12c4561ab201f2dec27e (patch)
tree44de15339b707afc13f75d36e9c6575d8c6c8dfe
parentc3cb7ec328dfac4579a246753455fa592e0dcd46 (diff)
parentbde1f6b4d468c6f9e9f7586280c79736ca07ca91 (diff)
downloadpykolab-efaef7e429879c34d30c12c4561ab201f2dec27e.tar.gz
Merge branch 'master' of ssh://git.kolabsys.com/git/pykolab
-rwxr-xr-xkolabd.py2
-rw-r--r--pykolab/auth/ldap/__init__.py4
-rw-r--r--pykolab/wap_client/__init__.py35
-rw-r--r--tests/__init__.py4
-rw-r--r--tests/functional/__init__.py4
-rw-r--r--tests/functional/test_auth/__init__.py0
-rw-r--r--tests/functional/test_auth/test_001_ldap.py0
-rw-r--r--tests/functional/test_auth/test_002_sql.py0
-rw-r--r--tests/functional/test_auth/test_003_pam.py0
-rw-r--r--tests/functional/test_auth/test_004_saslauthd.py0
-rw-r--r--tests/functional/test_kolabd/__init__.py6
-rw-r--r--tests/functional/test_kolabd/test_001_user_sync.py97
-rw-r--r--tests/functional/test_postfix/__init__.py6
-rw-r--r--tests/functional/test_wap_client/__init__.py6
-rw-r--r--tests/functional/test_wap_client/test_001_connect.py38
-rw-r--r--tests/functional/test_wap_client/test_002_user_add.py101
-rw-r--r--tests/functional/user_add.py68
-rw-r--r--tests/unit/__init__.py4
-rw-r--r--tests/unit/test-000-imports.py (renamed from tests/test-000-imports.py)0
-rw-r--r--tests/unit/test-001-contact_reference.py (renamed from tests/test-001-contact_reference.py)0
-rw-r--r--tests/unit/test-002-attendee.py (renamed from tests/test-002-attendee.py)0
-rw-r--r--tests/unit/test-003-event.py (renamed from tests/test-003-event.py)0
-rw-r--r--tests/unit/test-004-icalendar.py (renamed from tests/test-004-icalendar.py)0
-rw-r--r--tests/unit/test-005-timezone.py (renamed from tests/test-005-timezone.py)0
24 files changed, 357 insertions, 18 deletions
diff --git a/kolabd.py b/kolabd.py
index ec77767..a4acb4a 100755
--- a/kolabd.py
+++ b/kolabd.py
@@ -21,7 +21,7 @@
import sys
# For development purposes
-sys.path.extend(['.', '..'])
+sys.path = [ '.' ] + sys.path
from pykolab.translate import _
diff --git a/pykolab/auth/ldap/__init__.py b/pykolab/auth/ldap/__init__.py
index 26b4438..71f16ce 100644
--- a/pykolab/auth/ldap/__init__.py
+++ b/pykolab/auth/ldap/__init__.py
@@ -1069,6 +1069,7 @@ class LDAP(pykolab.base.Base):
the entry was - user, group, role or sharedfolder.
"""
result_attribute = conf.get('cyrus-sasl', 'result_attribute')
+
if not entry.has_key(result_attribute):
return None
@@ -1078,7 +1079,7 @@ class LDAP(pykolab.base.Base):
success = True
for _type in ['user','group','role','sharedfolder']:
try:
- eval("_change_delete_%s(entry, change)" % (_type))
+ eval("self._change_delete_%s(entry, change)" % (_type))
except:
success = False
@@ -1089,7 +1090,6 @@ class LDAP(pykolab.base.Base):
"""
An entry of type user was deleted.
"""
-
result_attribute = conf.get('cyrus-sasl', 'result_attribute')
if not entry.has_key(result_attribute):
diff --git a/pykolab/wap_client/__init__.py b/pykolab/wap_client/__init__.py
index 381e946..d5b0f50 100644
--- a/pykolab/wap_client/__init__.py
+++ b/pykolab/wap_client/__init__.py
@@ -41,9 +41,8 @@ session_id = None
conn = None
from connect import connect
-from request import request
-def authenticate(username=None, password=None):
+def authenticate(username=None, password=None, domain=None):
global session_id
conf_username = conf.get('ldap', 'service_bind_dn')
@@ -61,10 +60,14 @@ def authenticate(username=None, password=None):
if password == None:
password = utils.ask_question("Password", default=conf_password, password=True)
+ if domain == None:
+ domain = conf.get('kolab', 'primary_domain')
+
params = json.dumps(
{
'username': username,
- 'password': password
+ 'password': password,
+ 'domain': domain
}
)
@@ -123,6 +126,11 @@ def domains_capabilities():
def domains_list():
return request('GET', 'domains.list')
+def form_value_generate(params):
+ params = json.dumps(params)
+
+ return request('POST', 'form_value.generate', params)
+
def get_group_input():
group_types = group_types_list()
@@ -231,6 +239,15 @@ def groups_list():
return request('GET', 'groups.list')
def request(method, api_uri, params=None, headers={}):
+ response_data = request_raw(method, api_uri, params, headers)
+
+ if response_data['status'] == "OK":
+ del response_data['status']
+ return response_data['result']
+ else:
+ return response_data['result']
+
+def request_raw(method, api_uri, params=None, headers={}):
global session_id
if not session_id == None:
@@ -249,13 +266,8 @@ def request(method, api_uri, params=None, headers={}):
except ValueError, e:
# Some data is not JSON
log.error(_("Response data is not JSON"))
- sys.exit(1)
- if response_data['status'] == "OK":
- del response_data['status']
- return response_data['result']
- else:
- return response_data['result']
+ return response_data
def role_capabilities():
return request('GET', 'role.capabilities')
@@ -410,8 +422,9 @@ def user_form_value_generate_userpassword(*args, **kw):
result = form_value_generate_password()
return { 'userpassword': result['password'] }
-def user_info():
- user = utils.ask_question("User email address")
+def user_info(user=None):
+ if user == None:
+ user = utils.ask_question("User email address")
user = request('GET', 'user.info?user=%s' % (user))
return user
diff --git a/tests/__init__.py b/tests/__init__.py
index b5e7094..e69de29 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -1,4 +0,0 @@
-import sys
-
-sys.path = [ '.', '..' ] + sys.path
-
diff --git a/tests/functional/__init__.py b/tests/functional/__init__.py
new file mode 100644
index 0000000..1020893
--- /dev/null
+++ b/tests/functional/__init__.py
@@ -0,0 +1,4 @@
+import sys
+
+def setup_module():
+ sys.path = ['.'] + sys.path
diff --git a/tests/functional/test_auth/__init__.py b/tests/functional/test_auth/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/functional/test_auth/__init__.py
diff --git a/tests/functional/test_auth/test_001_ldap.py b/tests/functional/test_auth/test_001_ldap.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/functional/test_auth/test_001_ldap.py
diff --git a/tests/functional/test_auth/test_002_sql.py b/tests/functional/test_auth/test_002_sql.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/functional/test_auth/test_002_sql.py
diff --git a/tests/functional/test_auth/test_003_pam.py b/tests/functional/test_auth/test_003_pam.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/functional/test_auth/test_003_pam.py
diff --git a/tests/functional/test_auth/test_004_saslauthd.py b/tests/functional/test_auth/test_004_saslauthd.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/functional/test_auth/test_004_saslauthd.py
diff --git a/tests/functional/test_kolabd/__init__.py b/tests/functional/test_kolabd/__init__.py
new file mode 100644
index 0000000..d7bf27f
--- /dev/null
+++ b/tests/functional/test_kolabd/__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_kolabd/test_001_user_sync.py b/tests/functional/test_kolabd/test_001_user_sync.py
new file mode 100644
index 0000000..2c3a144
--- /dev/null
+++ b/tests/functional/test_kolabd/test_001_user_sync.py
@@ -0,0 +1,97 @@
+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 TestKolabDaemon(unittest.TestCase):
+ @classmethod
+ def setup_class(self, *args, **kw):
+ self.user = {
+ 'local': 'john.doe',
+ 'domain': 'example.org'
+ }
+
+ from tests.functional.user_add import user_add
+ user_add("John", "Doe")
+
+ def test_001_user_recipient_policy(self):
+ auth = Auth()
+ auth.connect()
+ recipient = auth.find_recipient("%(local)s@%(domain)s" % (self.user))
+ if hasattr(self, 'assertIsInstance'):
+ self.assertIsInstance(recipient, str)
+
+ 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'])
+
+ def test_002_user_mailbox_created(self):
+ time.sleep(2)
+ imap = IMAP()
+ imap.connect()
+
+ folders = imap.lm('user/%(local)s@%(domain)s' % (self.user))
+ self.assertEqual(len(folders), 1)
+
+ def test_003_user_additional_folders_created(self):
+ time.sleep(2)
+ imap = IMAP()
+ imap.connect()
+
+ exec("ac_folders = %s" % (conf.get_raw(conf.get('kolab', 'primary_domain'), 'autocreate_folders')))
+
+ folders = imap.lm('user/%(local)s/*@%(domain)s' % (self.user))
+
+ self.assertEqual(len(folders), len(ac_folders.keys()))
+
+ def test_004_user_folder_annotations_set(self):
+ imap = IMAP()
+ imap.connect()
+
+ exec("ac_folders = %s" % (conf.get_raw(conf.get('kolab', 'primary_domain'), 'autocreate_folders')))
+
+ folders = []
+ folders.extend(imap.lm('user/%(local)s@%(domain)s' % (self.user)))
+ folders.extend(imap.lm('user/%(local)s/*@%(domain)s' % (self.user)))
+
+ for folder in folders:
+ annotation = imap.getannotation(folder)
+ print annotation
+
+ 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])
+
+ def test_005_user_subscriptions(self):
+ imap = IMAP()
+ imap.connect(login=False)
+ login = conf.get('cyrus-imap', 'admin_login')
+ password = conf.get('cyrus-imap', 'admin_password')
+ imap.login_plain(login, password, 'john.doe@example.org')
+
+ folders = imap.lm()
+ self.assertTrue("INBOX" in folders)
+
+ #folders = imap.imap.lsub()
+ #self.assertTrue("Calendar" in folders)
+
+ def test_011_resource_add(self):
+ pass
+
+ def test_012_resource_mailbox_created(self):
+ pass
+
+ def test_013_resource_mailbox_annotation(self):
+ pass
+
diff --git a/tests/functional/test_postfix/__init__.py b/tests/functional/test_postfix/__init__.py
new file mode 100644
index 0000000..d7bf27f
--- /dev/null
+++ b/tests/functional/test_postfix/__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_wap_client/__init__.py b/tests/functional/test_wap_client/__init__.py
new file mode 100644
index 0000000..d7bf27f
--- /dev/null
+++ b/tests/functional/test_wap_client/__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_wap_client/test_001_connect.py b/tests/functional/test_wap_client/test_001_connect.py
new file mode 100644
index 0000000..42b8aa3
--- /dev/null
+++ b/tests/functional/test_wap_client/test_001_connect.py
@@ -0,0 +1,38 @@
+import unittest
+
+import pykolab
+from pykolab import wap_client
+
+class TestConnect(unittest.TestCase):
+ @classmethod
+ def setup_class(self, *args, **kw):
+ conf = pykolab.getConf()
+ 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')
+
+ def test_001_authenticate(self):
+ result = wap_client.authenticate(self.login, self.password, self.domain)
+
+ def test_002_response_ok(self):
+ result = wap_client.request_raw('POST', 'domains.list')
+ self.assertTrue(result.has_key('status'))
+ self.assertTrue(result.has_key('result'))
+ self.assertEqual(result['status'], "OK")
+
+ def test_003_response_fail(self):
+ result = wap_client.request_raw('POST', 'service.method')
+ self.assertTrue(result.has_key('status'))
+ self.assertTrue(result.has_key('reason'))
+ self.assertTrue(result.has_key('code'))
+ self.assertEqual(result['status'], "ERROR")
+ self.assertEqual(result['reason'], "Unknown service")
+ self.assertEqual(result['code'], 400)
+
+ def test_003_domains_list(self):
+ result = wap_client.domains_list()
+ self.assertTrue(result.has_key('count'))
+ self.assertTrue(result.has_key('list'))
+ self.assertEqual(result['count'], len(result['list']))
diff --git a/tests/functional/test_wap_client/test_002_user_add.py b/tests/functional/test_wap_client/test_002_user_add.py
new file mode 100644
index 0000000..84eeeb2
--- /dev/null
+++ b/tests/functional/test_wap_client/test_002_user_add.py
@@ -0,0 +1,101 @@
+import time
+import unittest
+
+import pykolab
+from pykolab import wap_client
+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')
+
+ self.user = {
+ 'local': 'john.doe',
+ 'domain': 'example.org'
+ }
+
+ from tests.functional.user_add import user_add
+ user_add("John", "Doe")
+
+ def test_001_inbox_created(self):
+ time.sleep(2)
+ imap = IMAP()
+ imap.connect()
+
+ folders = imap.lm('user/%(local)s@%(domain)s' % (self.user))
+ self.assertEqual(len(folders), 1)
+
+ def test_002_autocreate_folders_created(self):
+ time.sleep(2)
+ imap = IMAP()
+ imap.connect()
+
+ exec("ac_folders = %s" % (conf.get_raw(conf.get('kolab', 'primary_domain'), 'autocreate_folders')))
+
+ folders = imap.lm('user/%(local)s/*@%(domain)s' % (self.user))
+
+ print folders
+ print ac_folders.keys()
+
+ self.assertEqual(len(folders), len(ac_folders.keys()))
+
+ def test_003_folder_types_set(self):
+ imap = IMAP()
+ imap.connect()
+
+ exec("ac_folders = %s" % (conf.get_raw(conf.get('kolab', 'primary_domain'), 'autocreate_folders')))
+
+ folders = []
+ folders.extend(imap.lm('user/%(local)s@%(domain)s' % (self.user)))
+ folders.extend(imap.lm('user/%(local)s/*@%(domain)s' % (self.user)))
+
+ for folder in folders:
+ annotation = imap.getannotation(folder)
+ print annotation
+
+ 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')
+
+ 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)))
+
+ # Expect folders length to be 0
+
diff --git a/tests/functional/user_add.py b/tests/functional/user_add.py
new file mode 100644
index 0000000..0271d43
--- /dev/null
+++ b/tests/functional/user_add.py
@@ -0,0 +1,68 @@
+import pykolab
+
+from pykolab import wap_client
+
+conf = pykolab.getConf()
+
+def user_add(givenname, sn, preferredlanguage='en_US'):
+ if givenname == None:
+ raise Exception
+
+ if givenname == '':
+ raise Exception
+
+ if sn == None:
+ raise Exception
+
+ if sn == '':
+ raise Exception
+
+ user_details = {
+ 'givenname': givenname,
+ 'sn': sn,
+ 'preferredlanguage': preferredlanguage,
+ 'ou': 'ou=People,dc=example,dc=org',
+ 'userpassword': 'Welcome2KolabSystems'
+ }
+
+ login = conf.get('ldap', 'bind_dn')
+ password = conf.get('ldap', 'bind_pw')
+ domain = conf.get('kolab', 'primary_domain')
+
+ user_type_id = 0
+
+ result = wap_client.authenticate(login, password, domain)
+
+ user_types = wap_client.user_types_list()
+
+ for key in user_types['list'].keys():
+ if user_types['list'][key]['key'] == 'kolab':
+ user_type_id = key
+
+ user_type_info = user_types['list'][user_type_id]['attributes']
+
+ params = {
+ 'user_type_id': user_type_id,
+ }
+
+ for attribute in user_type_info['form_fields'].keys():
+ attr_details = user_type_info['form_fields'][attribute]
+
+ if isinstance(attr_details, dict):
+ if not attr_details.has_key('optional') or attr_details['optional'] == False:
+ params[attribute] = user_details[attribute]
+ elif isinstance(attr_details, list):
+ params[attribute] = user_details[attribute]
+
+ fvg_params = params
+ fvg_params['object_type'] = 'user'
+ fvg_params['type_id'] = user_type_id
+ fvg_params['attributes'] = [attr for attr in user_type_info['auto_form_fields'].keys() if not attr in params.keys()]
+
+ exec("retval = wap_client.form_value_generate(%r)" % (params))
+
+ for attribute in user_type_info['auto_form_fields'].keys():
+ params[attribute] = retval[attribute]
+
+ result = wap_client.user_add(params)
+
diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py
new file mode 100644
index 0000000..b5e7094
--- /dev/null
+++ b/tests/unit/__init__.py
@@ -0,0 +1,4 @@
+import sys
+
+sys.path = [ '.', '..' ] + sys.path
+
diff --git a/tests/test-000-imports.py b/tests/unit/test-000-imports.py
index 17e1c57..17e1c57 100644
--- a/tests/test-000-imports.py
+++ b/tests/unit/test-000-imports.py
diff --git a/tests/test-001-contact_reference.py b/tests/unit/test-001-contact_reference.py
index 7c8f128..7c8f128 100644
--- a/tests/test-001-contact_reference.py
+++ b/tests/unit/test-001-contact_reference.py
diff --git a/tests/test-002-attendee.py b/tests/unit/test-002-attendee.py
index 4298761..4298761 100644
--- a/tests/test-002-attendee.py
+++ b/tests/unit/test-002-attendee.py
diff --git a/tests/test-003-event.py b/tests/unit/test-003-event.py
index 8f76397..8f76397 100644
--- a/tests/test-003-event.py
+++ b/tests/unit/test-003-event.py
diff --git a/tests/test-004-icalendar.py b/tests/unit/test-004-icalendar.py
index 6033a33..6033a33 100644
--- a/tests/test-004-icalendar.py
+++ b/tests/unit/test-004-icalendar.py
diff --git a/tests/test-005-timezone.py b/tests/unit/test-005-timezone.py
index 8110e30..8110e30 100644
--- a/tests/test-005-timezone.py
+++ b/tests/unit/test-005-timezone.py