summaryrefslogtreecommitdiffstats
path: root/tests/functional/user_add.py
blob: 35e2b6ba356fcfddb052f17df5e873a697e7a4a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import pykolab

from pykolab import wap_client

conf = pykolab.getConf()


def user_add(givenname, sn, preferredlanguage='en_US', **kw):
    if givenname is None or givenname == '':
        raise Exception

    if sn is None or sn == '':
        raise Exception

    user_details = {
            'givenname': givenname,
            'sn': sn,
            'preferredlanguage': preferredlanguage,
            'ou': 'ou=People,dc=example,dc=org',
            'userpassword': 'Welcome2KolabSystems'
        }

    user_details.update(kw)

    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 'optional' not in attr_details or attr_details['optional'] is False or attribute in user_details:
                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 attr not in params]

    result = wap_client.user_add(params)