migrate test_extfs to pytest

This commit is contained in:
Frode Gundersen 2022-12-01 16:34:44 +00:00 committed by Megan Wilhite
parent 11078a4338
commit efdb0722ce
2 changed files with 80 additions and 74 deletions

View file

@ -0,0 +1,80 @@
"""
:codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
"""
import pytest
import salt.modules.extfs as extfs
from tests.support.mock import MagicMock, patch
@pytest.fixture
def configure_loader_modules():
return {extfs: {}}
# 'mkfs' function tests: 1
def test_mkfs():
"""
Tests if a file system created on the specified device
"""
mock = MagicMock()
with patch.dict(extfs.__salt__, {"cmd.run": mock}):
assert [] == extfs.mkfs("/dev/sda1", "ext4")
# 'tune' function tests: 1
def test_tune():
"""
Tests if specified group was added
"""
mock = MagicMock()
with patch.dict(extfs.__salt__, {"cmd.run": mock}), patch(
"salt.modules.extfs.tune", MagicMock(return_value="")
):
assert "" == extfs.tune("/dev/sda1")
# 'dump' function tests: 1
def test_dump():
"""
Tests if specified group was added
"""
mock = MagicMock()
with patch.dict(extfs.__salt__, {"cmd.run": mock}):
assert {"attributes": {}, "blocks": {}} == extfs.dump("/dev/sda1")
# 'attributes' function tests: 1
def test_attributes():
"""
Tests if specified group was added
"""
with patch(
"salt.modules.extfs.dump",
MagicMock(return_value={"attributes": {}, "blocks": {}}),
):
assert {} == extfs.attributes("/dev/sda1")
# 'blocks' function tests: 1
def test_blocks():
"""
Tests if specified group was added
"""
with patch(
"salt.modules.extfs.dump",
MagicMock(return_value={"attributes": {}, "blocks": {}}),
):
assert {} == extfs.blocks("/dev/sda1")

View file

@ -1,74 +0,0 @@
"""
:codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
"""
import salt.modules.extfs as extfs
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.mock import MagicMock, patch
from tests.support.unit import TestCase
class ExtfsTestCase(TestCase, LoaderModuleMockMixin):
"""
TestCase for salt.modules.extfs
"""
def setup_loader_modules(self):
return {extfs: {}}
# 'mkfs' function tests: 1
def test_mkfs(self):
"""
Tests if a file system created on the specified device
"""
mock = MagicMock()
with patch.dict(extfs.__salt__, {"cmd.run": mock}):
self.assertListEqual([], extfs.mkfs("/dev/sda1", "ext4"))
# 'tune' function tests: 1
def test_tune(self):
"""
Tests if specified group was added
"""
mock = MagicMock()
with patch.dict(extfs.__salt__, {"cmd.run": mock}), patch(
"salt.modules.extfs.tune", MagicMock(return_value="")
):
self.assertEqual("", extfs.tune("/dev/sda1"))
# 'dump' function tests: 1
def test_dump(self):
"""
Tests if specified group was added
"""
mock = MagicMock()
with patch.dict(extfs.__salt__, {"cmd.run": mock}):
self.assertEqual({"attributes": {}, "blocks": {}}, extfs.dump("/dev/sda1"))
# 'attributes' function tests: 1
def test_attributes(self):
"""
Tests if specified group was added
"""
with patch(
"salt.modules.extfs.dump",
MagicMock(return_value={"attributes": {}, "blocks": {}}),
):
self.assertEqual({}, extfs.attributes("/dev/sda1"))
# 'blocks' function tests: 1
def test_blocks(self):
"""
Tests if specified group was added
"""
with patch(
"salt.modules.extfs.dump",
MagicMock(return_value={"attributes": {}, "blocks": {}}),
):
self.assertEqual({}, extfs.blocks("/dev/sda1"))