mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
migrate test_uwsgi to pytest
This commit is contained in:
parent
ad06fc09d3
commit
9a7efbbc00
2 changed files with 27 additions and 23 deletions
27
tests/pytests/unit/modules/test_uwsgi.py
Normal file
27
tests/pytests/unit/modules/test_uwsgi.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
"""
|
||||
Test cases for salt.modules.uswgi
|
||||
"""
|
||||
|
||||
|
||||
import pytest
|
||||
|
||||
import salt.modules.uwsgi as uwsgi
|
||||
from tests.support.mock import MagicMock, Mock, patch
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def configure_loader_modules():
|
||||
with patch("salt.utils.path.which", Mock(return_value="/usr/bin/uwsgi")):
|
||||
return {uwsgi: {}}
|
||||
|
||||
|
||||
def test_uwsgi_stats():
|
||||
socket = "127.0.0.1:5050"
|
||||
mock = MagicMock(return_value='{"a": 1, "b": 2}')
|
||||
with patch.dict(uwsgi.__salt__, {"cmd.run": mock}):
|
||||
result = uwsgi.stats(socket)
|
||||
mock.assert_called_once_with(
|
||||
["uwsgi", "--connect-and-read", "{}".format(socket)],
|
||||
python_shell=False,
|
||||
)
|
||||
assert result == {"a": 1, "b": 2}
|
|
@ -1,23 +0,0 @@
|
|||
import salt.modules.uwsgi as uwsgi
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
from tests.support.mock import MagicMock, Mock, patch
|
||||
from tests.support.unit import TestCase
|
||||
|
||||
|
||||
class UwsgiTestCase(TestCase, LoaderModuleMockMixin):
|
||||
def setup_loader_modules(self):
|
||||
patcher = patch("salt.utils.path.which", Mock(return_value="/usr/bin/uwsgi"))
|
||||
patcher.start()
|
||||
self.addCleanup(patcher.stop)
|
||||
return {uwsgi: {}}
|
||||
|
||||
def test_uwsgi_stats(self):
|
||||
socket = "127.0.0.1:5050"
|
||||
mock = MagicMock(return_value='{"a": 1, "b": 2}')
|
||||
with patch.dict(uwsgi.__salt__, {"cmd.run": mock}):
|
||||
result = uwsgi.stats(socket)
|
||||
mock.assert_called_once_with(
|
||||
["uwsgi", "--connect-and-read", "{}".format(socket)],
|
||||
python_shell=False,
|
||||
)
|
||||
self.assertEqual(result, {"a": 1, "b": 2})
|
Loading…
Add table
Reference in a new issue