Changeset View
Changeset View
Standalone View
Standalone View
tests/functional/user_add.py
import pykolab | import pykolab | ||||
from pykolab import wap_client | from pykolab import wap_client | ||||
conf = pykolab.getConf() | conf = pykolab.getConf() | ||||
def user_add(givenname, sn, preferredlanguage='en_US', **kw): | |||||
if givenname == None: | |||||
raise Exception | |||||
if givenname == '': | |||||
raise Exception | |||||
if sn == None: | def user_add(givenname, sn, preferredlanguage='en_US', **kw): | ||||
if givenname is None or givenname == '': | |||||
raise Exception | raise Exception | ||||
if sn == '': | if sn is None or sn == '': | ||||
raise Exception | raise Exception | ||||
user_details = { | user_details = { | ||||
'givenname': givenname, | 'givenname': givenname, | ||||
'sn': sn, | 'sn': sn, | ||||
'preferredlanguage': preferredlanguage, | 'preferredlanguage': preferredlanguage, | ||||
'ou': 'ou=People,dc=example,dc=org', | 'ou': 'ou=People,dc=example,dc=org', | ||||
'userpassword': 'Welcome2KolabSystems' | 'userpassword': 'Welcome2KolabSystems' | ||||
Show All 20 Lines | def user_add(givenname, sn, preferredlanguage='en_US', **kw): | ||||
params = { | params = { | ||||
'user_type_id': user_type_id, | 'user_type_id': user_type_id, | ||||
} | } | ||||
for attribute in user_type_info['form_fields'].keys(): | for attribute in user_type_info['form_fields'].keys(): | ||||
attr_details = user_type_info['form_fields'][attribute] | attr_details = user_type_info['form_fields'][attribute] | ||||
if isinstance(attr_details, dict): | if isinstance(attr_details, dict): | ||||
if not attr_details.has_key('optional') or attr_details['optional'] == False or user_details.has_key(attribute): | if 'optional' not in attr_details or attr_details['optional'] is False or attribute in user_details: | ||||
params[attribute] = user_details[attribute] | params[attribute] = user_details[attribute] | ||||
elif isinstance(attr_details, list): | elif isinstance(attr_details, list): | ||||
params[attribute] = user_details[attribute] | params[attribute] = user_details[attribute] | ||||
fvg_params = params | fvg_params = params | ||||
fvg_params['object_type'] = 'user' | fvg_params['object_type'] = 'user' | ||||
fvg_params['type_id'] = user_type_id | 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()] | fvg_params['attributes'] = [attr for attr in user_type_info['auto_form_fields'].keys() if attr not in params] | ||||
result = wap_client.user_add(params) | result = wap_client.user_add(params) | ||||