Changeset View
Changeset View
Standalone View
Standalone View
tests/functional/resource_func.py
Show All 24 Lines | def resource_add(type, cn, members=None, owner=None, **kw): | ||||
bind_dn = conf.get('ldap', 'bind_dn') | bind_dn = conf.get('ldap', 'bind_dn') | ||||
bind_pw = conf.get('ldap', 'bind_pw') | bind_pw = conf.get('ldap', 'bind_pw') | ||||
domain = conf.get('kolab', 'primary_domain') | domain = conf.get('kolab', 'primary_domain') | ||||
result = wap_client.authenticate(bind_dn, bind_pw, domain) | result = wap_client.authenticate(bind_dn, bind_pw, domain) | ||||
type_id = 0 | type_id = 0 | ||||
resource_types = wap_client.resource_types_list() | resource_types = wap_client.resource_types_list() | ||||
for key in resource_types['list'].keys(): | for key in resource_types['list']: | ||||
if resource_types['list'][key]['key'] == type: | if resource_types['list'][key]['key'] == type: | ||||
type_id = key | type_id = key | ||||
if type_id == 0: | if type_id == 0: | ||||
raise Exception | raise Exception | ||||
resource_type_info = resource_types['list'][type_id]['attributes'] | resource_type_info = resource_types['list'][type_id]['attributes'] | ||||
params = {} | params = {} | ||||
for attribute in resource_type_info['form_fields'].keys(): | for attribute in resource_type_info['form_fields']: | ||||
attr_details = resource_type_info['form_fields'][attribute] | attr_details = resource_type_info['form_fields'][attribute] | ||||
if isinstance(attr_details, dict): | if isinstance(attr_details, dict): | ||||
if 'optional' not in attr_details or attr_details['optional'] is False or attribute in resource_details: | if 'optional' not in attr_details or attr_details['optional'] is False or attribute in resource_details: | ||||
params[attribute] = resource_details[attribute] | params[attribute] = resource_details[attribute] | ||||
elif isinstance(attr_details, list): | elif isinstance(attr_details, list): | ||||
params[attribute] = resource_details[attribute] | params[attribute] = resource_details[attribute] | ||||
fvg_params = params | fvg_params = params | ||||
fvg_params['object_type'] = 'resource' | fvg_params['object_type'] = 'resource' | ||||
fvg_params['type_id'] = type_id | fvg_params['type_id'] = type_id | ||||
fvg_params['attributes'] = [attr for attr in resource_type_info['auto_form_fields'].keys() if attr not in params] | fvg_params['attributes'] = [attr for attr in resource_type_info['auto_form_fields'] if attr not in params] | ||||
result = wap_client.resource_add(params) | result = wap_client.resource_add(params) | ||||
result['dn'] = "cn=" + result['cn'] + ",ou=Resources,dc=example,dc=org" | result['dn'] = "cn=" + result['cn'] + ",ou=Resources,dc=example,dc=org" | ||||
return result | return result | ||||
def purge_resources(): | def purge_resources(): | ||||
bind_dn = conf.get('ldap', 'bind_dn') | bind_dn = conf.get('ldap', 'bind_dn') | ||||
Show All 11 Lines |