test_retcodes_none_none.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # -*- coding: utf-8 -*-
  2. # Import Python Libraries
  3. from __future__ import print_function, unicode_literals, absolute_import
  4. import sys
  5. # Import Pepper Libraries
  6. import pepper
  7. from mock import patch, MagicMock
  8. PAYLOAD = {
  9. "return": [
  10. {
  11. "saltstack.ezh.msk.ru": {
  12. "jid": "20180414193904158892",
  13. "ret": "Hello from SaltStack",
  14. },
  15. "ezh.msk.ru": {
  16. "jid": "20180414193904158892",
  17. "ret": "Hello from SaltStack",
  18. }
  19. }
  20. ]
  21. }
  22. @patch('pepper.cli.PepperCli.login', MagicMock(side_effect=lambda arg: None))
  23. @patch('pepper.cli.PepperCli.low', MagicMock(side_effect=lambda api, load: PAYLOAD))
  24. def test_default():
  25. sys.argv = ['pepper', 'minion_id', 'request']
  26. ret_code = pepper.script.Pepper()()
  27. assert ret_code == 0
  28. @patch('pepper.cli.PepperCli.login', MagicMock(side_effect=lambda arg: None))
  29. @patch('pepper.cli.PepperCli.low', MagicMock(side_effect=lambda api, load: PAYLOAD))
  30. def test_fail_any():
  31. sys.argv = ['pepper', '--fail-any', 'minion_id', 'request']
  32. ret_code = pepper.script.Pepper()()
  33. assert ret_code == 0
  34. @patch('pepper.cli.PepperCli.login', MagicMock(side_effect=lambda arg: None))
  35. @patch('pepper.cli.PepperCli.low', MagicMock(side_effect=lambda api, load: PAYLOAD))
  36. def test_fail_any_none():
  37. sys.argv = ['pepper', '--fail-any-none', 'minion_id', 'request']
  38. ret_code = pepper.script.Pepper()()
  39. assert ret_code == -1
  40. @patch('pepper.cli.PepperCli.login', MagicMock(side_effect=lambda arg: None))
  41. @patch('pepper.cli.PepperCli.low', MagicMock(side_effect=lambda api, load: PAYLOAD))
  42. def test_fail_all():
  43. sys.argv = ['pepper', '--fail-all', 'minion_id', 'request']
  44. ret_code = pepper.script.Pepper()()
  45. assert ret_code == 0
  46. @patch('pepper.cli.PepperCli.login', MagicMock(side_effect=lambda arg: None))
  47. @patch('pepper.cli.PepperCli.low', MagicMock(side_effect=lambda api, load: PAYLOAD))
  48. def test_fail_all_none():
  49. sys.argv = ['pepper', '--fail-all-none', 'minion_id', 'request']
  50. ret_code = pepper.script.Pepper()()
  51. assert ret_code == -1