migrate test_pam to pytest

This commit is contained in:
Frode Gundersen 2023-01-10 22:27:38 +00:00 committed by Megan Wilhite
parent 1830881388
commit 14e31a6641
2 changed files with 36 additions and 38 deletions

View 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",
}
]

View file

@ -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",
}
],
)