salt/tests/unit/modules/test_uwsgi.py

33 lines
1.1 KiB
Python
Raw Normal View History

2014-01-29 21:40:23 +00:00
# -*- coding: utf-8 -*-
# Import Python libs
from __future__ import absolute_import
2014-01-29 21:40:23 +00:00
# Import Salt Testing libs
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import skipIf, TestCase
from tests.support.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, Mock, patch
2014-01-29 21:40:23 +00:00
# Import salt libs
import salt.modules.uwsgi as uwsgi
2014-01-29 21:40:23 +00:00
2014-01-29 22:07:45 +00:00
2014-01-29 21:40:23 +00:00
@skipIf(NO_MOCK, NO_MOCK_REASON)
class UwsgiTestCase(TestCase, LoaderModuleMockMixin):
def setup_loader_modules(self):
2017-04-10 13:00:57 +00:00
patcher = patch('salt.utils.which', Mock(return_value='/usr/bin/uwsgi'))
patcher.start()
self.addCleanup(patcher.stop)
return {uwsgi: {}}
2014-01-29 21:40:23 +00:00
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)
2014-01-29 22:03:17 +00:00
mock.assert_called_once_with(
2015-01-07 18:50:41 +00:00
['uwsgi', '--connect-and-read', '{0}'.format(socket)],
python_shell=False)
2014-01-29 21:40:23 +00:00
self.assertEqual(result, {'a': 1, 'b': 2})