test_process.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # -*- coding: utf-8 -*-
  2. """
  3. :codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
  4. """
  5. # Import Python libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. # Import Salt Libs
  8. import salt.states.process as process
  9. # Import Salt Testing Libs
  10. from tests.support.mixins import LoaderModuleMockMixin
  11. from tests.support.mock import MagicMock, patch
  12. from tests.support.unit import TestCase
  13. class ProcessTestCase(TestCase, LoaderModuleMockMixin):
  14. """
  15. Test cases for salt.states.process
  16. """
  17. def setup_loader_modules(self):
  18. return {process: {}}
  19. # 'absent' function tests: 1
  20. def test_absent(self):
  21. """
  22. Test to ensures that the named command is not running.
  23. """
  24. name = "apache2"
  25. ret = {"name": name, "changes": {}, "result": None, "comment": ""}
  26. mock = MagicMock(return_value="")
  27. with patch.dict(process.__salt__, {"ps.pgrep": mock, "ps.pkill": mock}):
  28. with patch.dict(process.__opts__, {"test": True}):
  29. comt = "No matching processes running"
  30. ret.update({"comment": comt})
  31. self.assertDictEqual(process.absent(name), ret)
  32. with patch.dict(process.__opts__, {"test": False}):
  33. ret.update({"result": True})
  34. self.assertDictEqual(process.absent(name), ret)