36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
|
|
import pytest
|
||
|
|
from unittest.mock import MagicMock, patch
|
||
|
|
from infra_cli.samba import SambaManager
|
||
|
|
|
||
|
|
class MockConfig:
|
||
|
|
def get_node(self, name):
|
||
|
|
return {"host": "10.32.2.1", "pass": "secret"}
|
||
|
|
def get(self, key, default=None):
|
||
|
|
mapping = {
|
||
|
|
'samba.host': '10.32.1.101',
|
||
|
|
'samba.user': 'Administrator',
|
||
|
|
'samba.domain': 'FE.LOOPAWARE.COM'
|
||
|
|
}
|
||
|
|
return mapping.get(key, default)
|
||
|
|
|
||
|
|
@patch('infra_cli.samba.SSHClient')
|
||
|
|
def test_samba_add_user_logic(mock_ssh):
|
||
|
|
mock_instance = mock_ssh.return_value
|
||
|
|
mock_instance.run.return_value.returncode = 0
|
||
|
|
|
||
|
|
mgr = SambaManager(MockConfig())
|
||
|
|
mgr.add_user("testuser", "testpass")
|
||
|
|
|
||
|
|
assert any("samba-tool user create testuser testpass" in str(call)
|
||
|
|
for call in mock_instance.run.call_args_list)
|
||
|
|
|
||
|
|
@patch('infra_cli.samba.SSHClient')
|
||
|
|
def test_samba_add_to_group_logic(mock_ssh):
|
||
|
|
mock_instance = mock_ssh.return_value
|
||
|
|
mock_instance.run.return_value.returncode = 0
|
||
|
|
|
||
|
|
mgr = SambaManager(MockConfig())
|
||
|
|
mgr.add_to_group("testgroup", "testuser")
|
||
|
|
|
||
|
|
assert any("samba-tool group addmembers testgroup testuser" in str(call)
|
||
|
|
for call in mock_instance.run.call_args_list)
|