summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pykolab/wap_client/__init__.py25
-rw-r--r--tests/functional/resource_func.py65
-rw-r--r--tests/functional/test_wap_client/test_008_resource_add.py51
3 files changed, 141 insertions, 0 deletions
diff --git a/pykolab/wap_client/__init__.py b/pykolab/wap_client/__init__.py
index 674673c..54ef541 100644
--- a/pykolab/wap_client/__init__.py
+++ b/pykolab/wap_client/__init__.py
@@ -524,3 +524,28 @@ def user_types_list():
def users_list():
return request('GET', 'users.list')
+def resource_types_list():
+ return request('GET', 'resource_types.list')
+
+def resources_list():
+ return request('GET', 'resources.list')
+
+def resource_info(resource=None):
+ if resource == None:
+ resource = utils.ask_question("Resource DN")
+ return request('GET', 'resource.info', get={ 'id': resource })
+
+def resource_add(params=None):
+ if params == None:
+ params = get_user_input()
+
+ return request('POST', 'resource.add', post=json.dumps(params))
+
+def resource_delete(params=None):
+ if params == None:
+ params = {
+ 'id': utils.ask_question("Resource DN to delete", "resource")
+ }
+
+ return request('POST', 'resource.delete', post=json.dumps(params))
+
diff --git a/tests/functional/resource_func.py b/tests/functional/resource_func.py
new file mode 100644
index 0000000..e3519d1
--- /dev/null
+++ b/tests/functional/resource_func.py
@@ -0,0 +1,65 @@
+import pykolab
+
+from pykolab import wap_client
+
+conf = pykolab.getConf()
+
+def resource_add(type, cn, members=None):
+ if type == None or type == '':
+ raise Exception
+
+ if cn == None or cn == '':
+ raise Exception
+
+ resource_details = {
+ 'cn': cn,
+ 'kolabtargetfolder': "shared/Resources/" + cn + "@example.org",
+ 'uniquemember': members
+ }
+
+ result = wap_client.authenticate(conf.get('ldap', 'bind_dn'), conf.get('ldap', 'bind_pw'), conf.get('kolab', 'primary_domain'))
+
+ type_id = 0
+ resource_types = wap_client.resource_types_list()
+
+ for key in resource_types['list'].keys():
+ if resource_types['list'][key]['key'] == type:
+ type_id = key
+
+ if type_id == 0:
+ raise Exception
+
+ resource_type_info = resource_types['list'][type_id]['attributes']
+
+ params = {}
+
+ for attribute in resource_type_info['form_fields'].keys():
+ attr_details = resource_type_info['form_fields'][attribute]
+
+ if isinstance(attr_details, dict):
+ if not attr_details.has_key('optional') or attr_details['optional'] == False or resource_details.has_key(attribute):
+ params[attribute] = resource_details[attribute]
+ elif isinstance(attr_details, list):
+ params[attribute] = resource_details[attribute]
+
+ fvg_params = params
+ fvg_params['object_type'] = 'resource'
+ fvg_params['type_id'] = type_id
+ fvg_params['attributes'] = [attr for attr in resource_type_info['auto_form_fields'].keys() if not attr in params.keys()]
+
+ result = wap_client.resource_add(params)
+ result['dn'] = "cn=" + result['cn'] + ",ou=Resources,dc=example,dc=org"
+ return result
+
+
+def purge_resources():
+ wap_client.authenticate(conf.get("ldap", "bind_dn"), conf.get("ldap", "bind_pw"), conf.get('kolab', 'primary_domain'))
+
+ resources = wap_client.resources_list()
+
+ for resource in resources['list']:
+ wap_client.resource_delete({'id': resource})
+
+ #from tests.functional.purge_imap import purge_imap
+ #purge_imap()
+
diff --git a/tests/functional/test_wap_client/test_008_resource_add.py b/tests/functional/test_wap_client/test_008_resource_add.py
new file mode 100644
index 0000000..5647d0c
--- /dev/null
+++ b/tests/functional/test_wap_client/test_008_resource_add.py
@@ -0,0 +1,51 @@
+import time
+import pykolab
+
+from pykolab import wap_client
+from pykolab.auth import Auth
+from pykolab.imap import IMAP
+from twisted.trial import unittest
+
+import tests.functional.resource_func as funcs
+
+conf = pykolab.getConf()
+
+class TestResourceAdd(unittest.TestCase):
+
+ @classmethod
+ def setUp(self):
+ from tests.functional.purge_users import purge_users
+ purge_users()
+
+ self.john = {
+ 'local': 'john.doe',
+ 'domain': 'example.org'
+ }
+
+ from tests.functional.user_add import user_add
+ user_add("John", "Doe")
+
+ funcs.purge_resources()
+ self.audi = funcs.resource_add("car", "Audi A4")
+ self.passat = funcs.resource_add("car", "VW Passat")
+ self.boxter = funcs.resource_add("car", "Porsche Boxter S")
+ self.cars = funcs.resource_add("collection", "Company Cars", [ self.audi['dn'], self.passat['dn'], self.boxter['dn'] ])
+
+ from tests.functional.synchronize import synchronize_once
+ synchronize_once()
+
+ def test_001_resource_created(self):
+ auth = Auth()
+ auth.connect()
+ resource = auth.find_resource(self.audi['mail'])
+ self.assertEqual(resource, self.audi['dn'])
+
+ collection = auth.find_resource(self.cars['mail'])
+ self.assertEqual(collection, self.cars['dn'])
+
+ def test_002_resource_collection(self):
+ auth = Auth()
+ auth.connect()
+ attrs = auth.get_entry_attributes(None, self.cars['dn'], ['*'])
+ self.assertIn('groupofuniquenames', attrs['objectclass'])
+ self.assertEqual(len(attrs['uniquemember']), 3)