mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
migrate test_znc to pytest
This commit is contained in:
parent
689882d2d3
commit
a3a69cfa6d
2 changed files with 81 additions and 74 deletions
81
tests/pytests/unit/modules/test_znc.py
Normal file
81
tests/pytests/unit/modules/test_znc.py
Normal file
|
@ -0,0 +1,81 @@
|
|||
"""
|
||||
:codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
|
||||
|
||||
TestCase for salt.modules.znc
|
||||
"""
|
||||
|
||||
|
||||
import pytest
|
||||
|
||||
import salt.modules.znc as znc
|
||||
from tests.support.mock import MagicMock, patch
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def configure_loader_modules():
|
||||
return {znc: {}}
|
||||
|
||||
|
||||
# 'buildmod' function tests: 1
|
||||
|
||||
|
||||
def test_buildmod():
|
||||
"""
|
||||
Tests build module using znc-buildmod
|
||||
"""
|
||||
with patch("os.path.exists", MagicMock(return_value=False)):
|
||||
assert (
|
||||
znc.buildmod("modules.cpp")
|
||||
== "Error: The file (modules.cpp) does not exist."
|
||||
)
|
||||
|
||||
|
||||
def test_buildmod_module():
|
||||
"""
|
||||
Tests build module using znc-buildmod
|
||||
"""
|
||||
mock = MagicMock(return_value="SALT")
|
||||
with patch.dict(znc.__salt__, {"cmd.run": mock}), patch(
|
||||
"os.path.exists", MagicMock(return_value=True)
|
||||
):
|
||||
assert znc.buildmod("modules.cpp") == "SALT"
|
||||
|
||||
|
||||
# 'dumpconf' function tests: 1
|
||||
|
||||
|
||||
def test_dumpconf():
|
||||
"""
|
||||
Tests write the active configuration state to config file
|
||||
"""
|
||||
mock = MagicMock(return_value="SALT")
|
||||
with patch.dict(znc.__salt__, {"ps.pkill": mock}), patch.object(
|
||||
znc, "signal", MagicMock()
|
||||
):
|
||||
assert znc.dumpconf() == "SALT"
|
||||
|
||||
|
||||
# 'rehashconf' function tests: 1
|
||||
|
||||
|
||||
def test_rehashconf():
|
||||
"""
|
||||
Tests rehash the active configuration state from config file
|
||||
"""
|
||||
mock = MagicMock(return_value="SALT")
|
||||
with patch.dict(znc.__salt__, {"ps.pkill": mock}), patch.object(
|
||||
znc, "signal", MagicMock()
|
||||
):
|
||||
assert znc.rehashconf() == "SALT"
|
||||
|
||||
|
||||
# 'version' function tests: 1
|
||||
|
||||
|
||||
def test_version():
|
||||
"""
|
||||
Tests return server version from znc --version
|
||||
"""
|
||||
mock = MagicMock(return_value="ZNC 1.2 - http://znc.in")
|
||||
with patch.dict(znc.__salt__, {"cmd.run": mock}):
|
||||
assert znc.version() == "ZNC 1.2"
|
|
@ -1,74 +0,0 @@
|
|||
"""
|
||||
:codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
|
||||
"""
|
||||
|
||||
|
||||
import salt.modules.znc as znc
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
from tests.support.mock import MagicMock, patch
|
||||
from tests.support.unit import TestCase
|
||||
|
||||
|
||||
class ZncTestCase(TestCase, LoaderModuleMockMixin):
|
||||
"""
|
||||
TestCase for salt.modules.znc
|
||||
"""
|
||||
|
||||
def setup_loader_modules(self):
|
||||
return {znc: {}}
|
||||
|
||||
# 'buildmod' function tests: 1
|
||||
|
||||
def test_buildmod(self):
|
||||
"""
|
||||
Tests build module using znc-buildmod
|
||||
"""
|
||||
with patch("os.path.exists", MagicMock(return_value=False)):
|
||||
self.assertEqual(
|
||||
znc.buildmod("modules.cpp"),
|
||||
"Error: The file (modules.cpp) does not exist.",
|
||||
)
|
||||
|
||||
def test_buildmod_module(self):
|
||||
"""
|
||||
Tests build module using znc-buildmod
|
||||
"""
|
||||
mock = MagicMock(return_value="SALT")
|
||||
with patch.dict(znc.__salt__, {"cmd.run": mock}), patch(
|
||||
"os.path.exists", MagicMock(return_value=True)
|
||||
):
|
||||
self.assertEqual(znc.buildmod("modules.cpp"), "SALT")
|
||||
|
||||
# 'dumpconf' function tests: 1
|
||||
|
||||
def test_dumpconf(self):
|
||||
"""
|
||||
Tests write the active configuration state to config file
|
||||
"""
|
||||
mock = MagicMock(return_value="SALT")
|
||||
with patch.dict(znc.__salt__, {"ps.pkill": mock}), patch.object(
|
||||
znc, "signal", MagicMock()
|
||||
):
|
||||
self.assertEqual(znc.dumpconf(), "SALT")
|
||||
|
||||
# 'rehashconf' function tests: 1
|
||||
|
||||
def test_rehashconf(self):
|
||||
"""
|
||||
Tests rehash the active configuration state from config file
|
||||
"""
|
||||
mock = MagicMock(return_value="SALT")
|
||||
with patch.dict(znc.__salt__, {"ps.pkill": mock}), patch.object(
|
||||
znc, "signal", MagicMock()
|
||||
):
|
||||
self.assertEqual(znc.rehashconf(), "SALT")
|
||||
|
||||
# 'version' function tests: 1
|
||||
|
||||
def test_version(self):
|
||||
"""
|
||||
Tests return server version from znc --version
|
||||
"""
|
||||
mock = MagicMock(return_value="ZNC 1.2 - http://znc.in")
|
||||
with patch.dict(znc.__salt__, {"cmd.run": mock}):
|
||||
self.assertEqual(znc.version(), "ZNC 1.2")
|
Loading…
Add table
Reference in a new issue