test_uwsgi.py 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. # -*- coding: utf-8 -*-
  2. # Import Python libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. # Import Salt Testing libs
  5. from tests.support.mixins import LoaderModuleMockMixin
  6. from tests.support.unit import TestCase
  7. from tests.support.mock import MagicMock, Mock, patch
  8. # Import salt libs
  9. import salt.modules.uwsgi as uwsgi
  10. class UwsgiTestCase(TestCase, LoaderModuleMockMixin):
  11. def setup_loader_modules(self):
  12. patcher = patch('salt.utils.path.which', Mock(return_value='/usr/bin/uwsgi'))
  13. patcher.start()
  14. self.addCleanup(patcher.stop)
  15. return {uwsgi: {}}
  16. def test_uwsgi_stats(self):
  17. socket = "127.0.0.1:5050"
  18. mock = MagicMock(return_value='{"a": 1, "b": 2}')
  19. with patch.dict(uwsgi.__salt__, {'cmd.run': mock}):
  20. result = uwsgi.stats(socket)
  21. mock.assert_called_once_with(
  22. ['uwsgi', '--connect-and-read', '{0}'.format(socket)],
  23. python_shell=False)
  24. self.assertEqual(result, {'a': 1, 'b': 2})