Exemple #1
0
def add():
    opts = get_opts(
        'add_user', 'Adds User to a muam', {
            'username': '******',
            'email': 'email',
            'first_name': 'first_name',
            'full_name': 'full_name',
            'last_name': 'last_name',
            'phone': 'phone',
            'create_users': 'create_users',
            'create_groups': 'create_groups',
            'grant_privs': 'grant_privs',
        })

    session = get_session(opts)
    if not session:
        sys.exit('Invalid username/password.')

    add_item = User(**vars(opts))
    success, resp = add_item.save_new(session)

    if success:
        print('Added User with id: {}'.format(','.join(add_item.get_ids())))
    else:
        print('Add failed with code {} and message: {}'.format(
            resp.status_code, resp.text))
Exemple #2
0
def import_csv():
    opts = get_opts('import_user', 'Adds list of User to a muam',
                    {'f': 'filename'})

    if not opts.filename or not os.path.isfile(opts.filename):
        sys.exit('Filename {} does not exist or is not a file.'.format(
            opts.filename))

    session = get_session(opts)

    field_map = {}

    with open(opts.filename, "r") as csvfile:
        tagreader = csv.reader(csvfile)
        rowcount = 0
        for row in tagreader:
            rowcount += 1
            if rowcount == 1:
                fieldcount = 0
                for field in row:
                    field_map[field] = fieldcount
                    fieldcount += 1
                continue
            obj_data = {}
            for field in field_map:
                if field == 'authorizations':
                    obj_data['authorizations'] = []
                    auth_list = row[field_map[field]].split(', ')
                    for auth_item in auth_list:
                        auth_data = auth_item.split(':')
                        auth_gid = get_id_from_name(session, auth_data[0])
                        obj_data['authorizations'].append({
                            'group_id': auth_gid,
                            'role': auth_data[1]
                        })
                else:
                    lookup_res = get_id(session, field, row[field_map[field]])
                    obj_data[field] = lookup_res if lookup_res else row[
                        field_map[field]]
            new_obj = User(**obj_data)
            success, resp = new_obj.save_new(session)
            if success:
                print('row {} id: {}'.format(str(rowcount), new_obj.get_ids()))
            else:
                sys.exit('Add failed, code: {}, text: {}'.format(
                    resp.status_code, resp.text))
Exemple #3
0
def setUp():

    global added_group
    added_group = Group(
        **{
            'description': 'This is a really long description of a group',
            'profiles': {
                'muam': {
                    'test': 'value'
                }
            },
            'gid': 104,
            'name': 'app-users'
        })
    success, resp = added_group.save_new(TEST_SESSION)
    if not success: log_response_error(resp)
    assert success

    global added_user
    added_user = User(
        **{
            'username': '******',
            'email': '*****@*****.**',
            'password': '******',
            'first_name': 'Tester',
            'full_name': 'Tester, Unit X',
            'last_name': 'Unit',
            'phone': '+1 (919) 999-9999',
            'profiles': {
                'muam': {
                    'test': 'value'
                }
            },
            'create_users': False,
            'create_groups': True,
            'grant_privs': False
        })
    success, resp = added_user.save_new(TEST_SESSION)
    if not success: log_response_error(resp)
    assert success
Exemple #4
0
def search():
    opts = get_opts('search_user', 'Searches for Users in a muam',
                    {'search_text': 'search_text'})

    session = get_session(opts)
    if not session:
        sys.exit('Invalid username/password.')

    success, resp_list = User.search(session, opts.search_text)

    if success:
        for resp in resp_list:
            print('{} - {}'.format(resp.get_ids(), resp.full_name))
    else:
        print('Search failed with code {} and message: {}'.format(
            resp.status_code, resp.text))
def test_user_put():
    """--> put updates object """
    global added_obj
    
    # Change a value
    added_obj.first_name = 'Tester - edited'
    # Save the change a value
    success, resp = added_obj.save_update(TEST_SESSION)
    if not success: log_response_error(resp)
    assert success
    # Read the object again
    success, resp = User.get(TEST_SESSION, added_obj.user_id)
    if not success: log_response_error(resp)
    assert success
    # Confirm the values we read match what we wrote
    assert resp.first_name == added_obj.first_name
def test_user_get():
    """--> get returns details """
    global added_obj
    assert added_obj
    
    success, resp = User.get(TEST_SESSION, added_obj.user_id)
    if not success: log_response_error(resp)
    assert success
    assert resp.username == 'testing'
    assert resp.email == '*****@*****.**'
    assert resp.first_name == 'Tester'
    assert resp.full_name == 'Tester, Unit X'
    assert resp.last_name == 'Unit'
    assert resp.phone == '+1 (919) 999-9999'
    assert resp.profiles == {"muam": {"test": "value"}}
    assert resp.create_users == False
    assert resp.create_groups == True
    assert resp.grant_privs == False
def test_user_search():
    """--> tests search """
    
    success, resp_list = User.search(TEST_SESSION, '')
    if not success: log_response_error(resp_list)
    assert success
    LOGGER.debug('search result: {}'.format(str(resp_list)))
    assert len(resp_list) == 1
    resp = resp_list[0]
    assert resp.username == 'testing'
    assert resp.email == '*****@*****.**'
    assert resp.first_name == 'Tester'
    assert resp.full_name == 'Tester, Unit X'
    assert resp.last_name == 'Unit'
    assert resp.phone == '+1 (919) 999-9999'
    assert resp.profiles == {"muam": {"test": "value"}}
    assert resp.create_users == False
    assert resp.create_groups == True
    assert resp.grant_privs == False
def test_user_create():
    """UserAPIs: Test create API"""
    #pylint: disable=W0603
    global added_obj
    test_obj = User()
    test_obj.username = '******'
    test_obj.email = '*****@*****.**'
    test_obj.password = '******'
    test_obj.first_name = 'Tester'
    test_obj.full_name = 'Tester, Unit X'
    test_obj.last_name = 'Unit'
    test_obj.phone = '+1 (919) 999-9999'
    test_obj.profiles = {"muam": {"test": "value"}}
    test_obj.create_users = False
    test_obj.create_groups = True
    test_obj.grant_privs = False
    
    success, resp = test_obj.save_new(TEST_SESSION)
    if not success: log_response_error(resp)
    assert success
    added_obj = test_obj
def setUp():
    global added_obj, member_user, user_session
    added_obj = User()
    added_obj.first_name = 'firstname'
    added_obj.last_name = 'lastname'
    added_obj.username = '******'
    added_obj.email = '*****@*****.**'
    added_obj.password = '******'
    success, resp = added_obj.save_new(TEST_SESSION)
    assert success
    assert added_obj.user_id
    user_session = login('testuser', 'testing0')
    assert user_session
    member_user = User()
    member_user.first_name = 'firstname2'
    member_user.last_name = 'lastname2'
    member_user.username = '******'
    member_user.email = '*****@*****.**'
    member_user.password = '******'
    success, resp = member_user.save_new(TEST_SESSION)
    assert success
    assert member_user.user_id