mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
migrate test_devmap to pytest
This commit is contained in:
parent
6c2b2f94ad
commit
58162c369b
2 changed files with 40 additions and 42 deletions
40
tests/pytests/unit/modules/test_devmap.py
Normal file
40
tests/pytests/unit/modules/test_devmap.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
"""
|
||||
:codeauthor: Rupesh Tare <rupesht@saltstack.com>
|
||||
"""
|
||||
|
||||
|
||||
import os.path
|
||||
|
||||
import pytest
|
||||
|
||||
import salt.modules.devmap as devmap
|
||||
from tests.support.mock import MagicMock, patch
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def configure_loader_modules():
|
||||
return {devmap: {}}
|
||||
|
||||
|
||||
def test_multipath_list():
|
||||
"""
|
||||
Test for Device-Mapper Multipath list
|
||||
"""
|
||||
mock = MagicMock(return_value="A")
|
||||
with patch.dict(devmap.__salt__, {"cmd.run": mock}):
|
||||
assert devmap.multipath_list() == ["A"]
|
||||
|
||||
|
||||
def test_multipath_flush():
|
||||
"""
|
||||
Test for Device-Mapper Multipath flush
|
||||
"""
|
||||
mock = MagicMock(return_value=False)
|
||||
with patch.object(os.path, "exists", mock):
|
||||
assert devmap.multipath_flush("device") == "device does not exist"
|
||||
|
||||
mock = MagicMock(return_value=True)
|
||||
with patch.object(os.path, "exists", mock):
|
||||
mock = MagicMock(return_value="A")
|
||||
with patch.dict(devmap.__salt__, {"cmd.run": mock}):
|
||||
assert devmap.multipath_flush("device") == ["A"]
|
|
@ -1,42 +0,0 @@
|
|||
"""
|
||||
:codeauthor: Rupesh Tare <rupesht@saltstack.com>
|
||||
"""
|
||||
|
||||
|
||||
import os.path
|
||||
|
||||
import salt.modules.devmap as devmap
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
from tests.support.mock import MagicMock, patch
|
||||
from tests.support.unit import TestCase
|
||||
|
||||
|
||||
class DevMapTestCase(TestCase, LoaderModuleMockMixin):
|
||||
"""
|
||||
Test cases for salt.modules.devmap
|
||||
"""
|
||||
|
||||
def setup_loader_modules(self):
|
||||
return {devmap: {}}
|
||||
|
||||
def test_multipath_list(self):
|
||||
"""
|
||||
Test for Device-Mapper Multipath list
|
||||
"""
|
||||
mock = MagicMock(return_value="A")
|
||||
with patch.dict(devmap.__salt__, {"cmd.run": mock}):
|
||||
self.assertEqual(devmap.multipath_list(), ["A"])
|
||||
|
||||
def test_multipath_flush(self):
|
||||
"""
|
||||
Test for Device-Mapper Multipath flush
|
||||
"""
|
||||
mock = MagicMock(return_value=False)
|
||||
with patch.object(os.path, "exists", mock):
|
||||
self.assertEqual(devmap.multipath_flush("device"), "device does not exist")
|
||||
|
||||
mock = MagicMock(return_value=True)
|
||||
with patch.object(os.path, "exists", mock):
|
||||
mock = MagicMock(return_value="A")
|
||||
with patch.dict(devmap.__salt__, {"cmd.run": mock}):
|
||||
self.assertEqual(devmap.multipath_flush("device"), ["A"])
|
Loading…
Add table
Reference in a new issue