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 60
|
from unittest.mock import patch
from kiwi.system.users import Users
class TestUsers:
def setup(self):
self.users = Users('root_dir')
def setup_method(self, cls):
self.setup()
@patch('kiwi.system.users.Command.run')
def test_user_exists(self, mock_command):
assert self.users.user_exists('user') is True
mock_command.assert_called_once_with(
['chroot', 'root_dir', 'grep', '-q', '^user:', '/etc/passwd']
)
@patch('kiwi.system.users.Command.run')
def test_user_exists_return_value(self, mock_command):
assert self.users.user_exists('user') is True
mock_command.side_effect = Exception
assert self.users.user_exists('user') is False
@patch('kiwi.system.users.Command.run')
def test_group_exists(self, mock_command):
assert self.users.group_exists('group') is True
mock_command.assert_called_once_with(
['chroot', 'root_dir', 'grep', '-q', '^group:', '/etc/group']
)
@patch('kiwi.system.users.Command.run')
def test_group_add(self, mock_command):
assert self.users.group_add('group', ['--option', 'value']) is None
mock_command.assert_called_once_with(
['chroot', 'root_dir', 'groupadd', '--option', 'value', 'group']
)
@patch('kiwi.system.users.Command.run')
def test_user_add(self, mock_command):
assert self.users.user_add('user', ['--option', 'value']) is None
mock_command.assert_called_once_with(
['chroot', 'root_dir', 'useradd', '--option', 'value', 'user']
)
@patch('kiwi.system.users.Command.run')
def test_user_modify(self, mock_command):
assert self.users.user_modify('user', ['--option', 'value']) is None
mock_command.assert_called_once_with(
['chroot', 'root_dir', 'usermod', '--option', 'value', 'user']
)
@patch('kiwi.system.users.Command.run')
def test_setup_home_for_user(self, mock_command):
assert self.users.setup_home_for_user('user', 'group', '/home/path') \
is None
mock_command.assert_called_once_with(
['chroot', 'root_dir', 'chown', '-R', 'user:group', '/home/path']
)
|