test: add comprehensive unit tests for all managers
This commit is contained in:
parent
2d9e1bc06e
commit
2382e17830
3 changed files with 137 additions and 0 deletions
36
tests/unit/test_samba_logic.py
Normal file
36
tests/unit/test_samba_logic.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue