From ca51e73448cf8fcbdd357c98ae47eb22730facfb Mon Sep 17 00:00:00 2001 From: Frode Gundersen Date: Thu, 19 Jan 2023 21:03:14 +0000 Subject: [PATCH] migrate test_uwsgi to pytest --- tests/pytests/unit/modules/test_uwsgi.py | 27 ++++++++++++++++++++++++ tests/unit/modules/test_uwsgi.py | 23 -------------------- 2 files changed, 27 insertions(+), 23 deletions(-) create mode 100644 tests/pytests/unit/modules/test_uwsgi.py delete mode 100644 tests/unit/modules/test_uwsgi.py diff --git a/tests/pytests/unit/modules/test_uwsgi.py b/tests/pytests/unit/modules/test_uwsgi.py new file mode 100644 index 000000000000..5c97c191ce88 --- /dev/null +++ b/tests/pytests/unit/modules/test_uwsgi.py @@ -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} diff --git a/tests/unit/modules/test_uwsgi.py b/tests/unit/modules/test_uwsgi.py deleted file mode 100644 index 2f5a735f10df..000000000000 --- a/tests/unit/modules/test_uwsgi.py +++ /dev/null @@ -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})