test_ret.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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.loader
  8. # Import Salt Libs
  9. import salt.modules.ret as ret
  10. # Import Salt Testing Libs
  11. from tests.support.mixins import LoaderModuleMockMixin
  12. from tests.support.mock import MagicMock, patch
  13. from tests.support.unit import TestCase
  14. class RetTestCase(TestCase, LoaderModuleMockMixin):
  15. """
  16. Test cases for salt.modules.ret
  17. """
  18. def setup_loader_modules(self):
  19. return {ret: {}}
  20. # 'get_jid' function tests: 1
  21. def test_get_jid(self):
  22. """
  23. Test if it return the information for a specified job id
  24. """
  25. mock_ret = MagicMock(return_value="DB")
  26. with patch.object(
  27. salt.loader,
  28. "returners",
  29. MagicMock(return_value={"redis.get_jid": mock_ret}),
  30. ):
  31. self.assertEqual(ret.get_jid("redis", "net"), "DB")
  32. # 'get_fun' function tests: 1
  33. def test_get_fun(self):
  34. """
  35. Test if it return info about last time fun was called on each minion
  36. """
  37. mock_ret = MagicMock(return_value="DB")
  38. with patch.object(
  39. salt.loader,
  40. "returners",
  41. MagicMock(return_value={"mysql.get_fun": mock_ret}),
  42. ):
  43. self.assertEqual(ret.get_fun("mysql", "net"), "DB")
  44. # 'get_jids' function tests: 1
  45. def test_get_jids(self):
  46. """
  47. Test if it return a list of all job ids
  48. """
  49. mock_ret = MagicMock(return_value="DB")
  50. with patch.object(
  51. salt.loader,
  52. "returners",
  53. MagicMock(return_value={"mysql.get_jids": mock_ret}),
  54. ):
  55. self.assertEqual(ret.get_jids("mysql"), "DB")
  56. # 'get_minions' function tests: 1
  57. def test_get_minions(self):
  58. """
  59. Test if it return a list of all minions
  60. """
  61. mock_ret = MagicMock(return_value="DB")
  62. with patch.object(
  63. salt.loader,
  64. "returners",
  65. MagicMock(return_value={"mysql.get_minions": mock_ret}),
  66. ):
  67. self.assertEqual(ret.get_minions("mysql"), "DB")