mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
migrate test_pam to pytest
This commit is contained in:
parent
1830881388
commit
14e31a6641
2 changed files with 36 additions and 38 deletions
36
tests/pytests/unit/modules/test_pam.py
Normal file
36
tests/pytests/unit/modules/test_pam.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
"""
|
||||
:codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
|
||||
|
||||
Test cases for salt.modules.pam
|
||||
"""
|
||||
import pytest
|
||||
|
||||
import salt.modules.pam as pam
|
||||
from tests.support.mock import mock_open, patch
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def MOCK_FILE():
|
||||
return "ok ok ignore"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def configure_loader_modules():
|
||||
return {pam: {}}
|
||||
|
||||
|
||||
def test_read_file(MOCK_FILE):
|
||||
"""
|
||||
Test if the parsing function works
|
||||
"""
|
||||
with patch("os.path.exists", return_value=True), patch(
|
||||
"salt.utils.files.fopen", mock_open(read_data=MOCK_FILE)
|
||||
):
|
||||
assert pam.read_file("/etc/pam.d/login") == [
|
||||
{
|
||||
"arguments": [],
|
||||
"control_flag": "ok",
|
||||
"interface": "ok",
|
||||
"module": "ignore",
|
||||
}
|
||||
]
|
|
@ -1,38 +0,0 @@
|
|||
"""
|
||||
:codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
|
||||
"""
|
||||
import pytest
|
||||
|
||||
import salt.modules.pam as pam
|
||||
from tests.support.mock import mock_open, patch
|
||||
from tests.support.unit import TestCase
|
||||
|
||||
MOCK_FILE = "ok ok ignore "
|
||||
|
||||
|
||||
@pytest.mark.skip_on_openbsd(reason="OpenBSD does not use PAM")
|
||||
class PamTestCase(TestCase):
|
||||
"""
|
||||
Test cases for salt.modules.pam
|
||||
"""
|
||||
|
||||
# 'read_file' function tests: 1
|
||||
|
||||
def test_read_file(self):
|
||||
"""
|
||||
Test if the parsing function works
|
||||
"""
|
||||
with patch("os.path.exists", return_value=True), patch(
|
||||
"salt.utils.files.fopen", mock_open(read_data=MOCK_FILE)
|
||||
):
|
||||
self.assertListEqual(
|
||||
pam.read_file("/etc/pam.d/login"),
|
||||
[
|
||||
{
|
||||
"arguments": [],
|
||||
"control_flag": "ok",
|
||||
"interface": "ok",
|
||||
"module": "ignore",
|
||||
}
|
||||
],
|
||||
)
|
Loading…
Add table
Reference in a new issue