Пример #1
0
def test_users_update(mocker):
    """
    Given a user dictionary, `users.update(...)` should utilize `usermod` to set the groups and password for the user.
    """
    mocker.patch('subprocess.call')
    users.update(user_dict)
    subprocess.call.assert_called_with(
        ['usermod', '-p', password, '-G', 'wheel,dev', 'raminder'])
Пример #2
0
def test_users_update(mocker):
    """
    Update user based on the user dictionary
    utilize `usermod` to set the groups and password for the user
    """
    mocker.patch('subprocess.call')
    users.update(user_dict)
    subprocess.call.assert_called_with(
        ['usermod', '-p', password, '-G', 'wheel,dev', 'kevin'])
Пример #3
0
def test_users_update(mocker):
    """
    Given  a user dictionary `users.update(...)` should
    utilize `usermod` to create a user with the password
    and groups
    """
    mocker.patch('subprocess.call')
    users.update(user_dict)
    subprocess.call.assert_called_with(
        ['usermod', '-p', password, '-G', 'wheel,dev', 'kevin'])
Пример #4
0
def test_users_update(mocker):
    """
    Given a user dictionary. 'user.update(...)' should 
    update a user on the system using the 'usermod' linux command.
    """
    mocker.patch('subprocess.call')
    users.update(user_dict)
    subprocess.call.assert_called_with([
        'usermod',
        '-p',
        password,
        '-G',
        'wheel,dev',
        'kevin',
    ])
Пример #5
0
def test_users_update(mocker):
    """
    users.update should call usermod with the correct parameters
    """
    mocker.patch('subprocess.run')
    assert users.update(user_dict)
    subprocess.run.assert_called_with(update_command, check=True)
Пример #6
0
def test_users_update(mocker):
    """
    Given a user dictionary, `users.update(...)` should
    utilize `usermod` to set the groups and password for the
    user.
    """
    mocker.patch(subprocess_call)
    users.update(user_dict)
    subprocess.call.assert_called_with([
        'usermod',
        '-p',
        password,
        '-G',
        wheel_div,
        'kevin',
    ])
Пример #7
0
        if index == 0:
            group_str += group
        else:
            group_str += ",%s" % group
        index+=1

# To manually test this you’ll need to (temporarily) run the following from within your project’s directory:

    sudo pip3.6 install -e .

# Then you will be able to run the following to be able to use your module in a REPL without getting permissions
# errors for calling out to usermod, userdel, and useradd:

    sudo python3.6
    >>> from hr import users
    >>> password = '******'
    >>> user_dict = {
    ...     'name': 'kevin',
    ...     'groups': ['wheel'],
    ...     'password': password
    ... }
    >>> users.add(user_dict)
    Adding user 'kevin'
    >>> user_dict['groups'] = []
    >>> users.update(user_dict)
    Updating user 'kevin'
    >>> users.remove(user_dict)
    Removing user 'kevin'
    >>>