| 1 |
from unittest.mock import patch |
| 2 |
|
| 3 |
from kiwi.system.users import Users |
| 4 |
|
| 5 |
|
| 6 |
class TestUsers: |
| 7 |
def setup(self): |
| 8 |
self.users = Users('root_dir') |
| 9 |
|
| 10 |
def setup_method(self, cls): |
| 11 |
self.setup() |
| 12 |
|
| 13 |
@patch('kiwi.system.users.Command.run') |
| 14 |
def test_user_exists(self, mock_command): |
| 15 |
assert self.users.user_exists('user') is True |
| 16 |
mock_command.assert_called_once_with( |
| 17 |
['chroot', 'root_dir', 'grep', '-q', '^user:', '/etc/passwd'] |
| 18 |
) |
| 19 |
|
| 20 |
@patch('kiwi.system.users.Command.run') |
| 21 |
def test_user_exists_return_value(self, mock_command): |
| 22 |
assert self.users.user_exists('user') is True |
| 23 |
mock_command.side_effect = Exception |
| 24 |
assert self.users.user_exists('user') is False |
| 25 |
|
| 26 |
@patch('kiwi.system.users.Command.run') |
| 27 |
def test_group_exists(self, mock_command): |
| 28 |
assert self.users.group_exists('group') is True |
| 29 |
mock_command.assert_called_once_with( |
| 30 |
['chroot', 'root_dir', 'grep', '-q', '^group:', '/etc/group'] |
| 31 |
) |
| 32 |
|
| 33 |
@patch('kiwi.system.users.Command.run') |
| 34 |
def test_group_add(self, mock_command): |
| 35 |
assert self.users.group_add('group', ['--option', 'value']) is None |
| 36 |
mock_command.assert_called_once_with( |
| 37 |
['chroot', 'root_dir', 'groupadd', '--option', 'value', 'group'] |
| 38 |
) |
| 39 |
|
| 40 |
@patch('kiwi.system.users.Command.run') |
| 41 |
def test_user_add(self, mock_command): |
| 42 |
assert self.users.user_add('user', ['--option', 'value']) is None |
| 43 |
mock_command.assert_called_once_with( |
| 44 |
['chroot', 'root_dir', 'useradd', '--option', 'value', 'user'] |
| 45 |
) |
| 46 |
|
| 47 |
@patch('kiwi.system.users.Command.run') |
| 48 |
def test_user_modify(self, mock_command): |
| 49 |
assert self.users.user_modify('user', ['--option', 'value']) is None |
| 50 |
mock_command.assert_called_once_with( |
| 51 |
['chroot', 'root_dir', 'usermod', '--option', 'value', 'user'] |
| 52 |
) |
| 53 |
|
| 54 |
@patch('kiwi.system.users.Command.run') |
| 55 |
def test_setup_home_for_user(self, mock_command): |
| 56 |
assert self.users.setup_home_for_user('user', 'group', '/home/path') \ |
| 57 |
is None |
| 58 |
mock_command.assert_called_once_with( |
| 59 |
['chroot', 'root_dir', 'chown', '-R', 'user:group', '/home/path'] |
| 60 |
) |