test_kwarg.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import, print_function, unicode_literals
  3. import pytest
  4. import salt.utils.platform
  5. from salt.ext import six
  6. from tests.support.case import ModuleCase
  7. from tests.support.unit import skipIf
  8. @pytest.mark.windows_whitelisted
  9. class StdTest(ModuleCase):
  10. """
  11. Test standard client calls
  12. """
  13. def setUp(self):
  14. self.TIMEOUT = 600 if salt.utils.platform.is_windows() else 10
  15. @skipIf(True, "SLOWTEST skip")
  16. def test_cli(self):
  17. """
  18. Test cli function
  19. """
  20. cmd_iter = self.client.cmd_cli(
  21. "minion", "test.arg", ["foo", "bar", "baz"], kwarg={"qux": "quux"}
  22. )
  23. for ret in cmd_iter:
  24. data = ret["minion"]["ret"]
  25. self.assertEqual(data["args"], ["foo", "bar", "baz"])
  26. self.assertEqual(data["kwargs"]["qux"], "quux")
  27. @skipIf(True, "SLOWTEST skip")
  28. def test_iter(self):
  29. """
  30. test cmd_iter
  31. """
  32. cmd_iter = self.client.cmd_iter(
  33. "minion", "test.arg", ["foo", "bar", "baz"], kwarg={"qux": "quux"}
  34. )
  35. for ret in cmd_iter:
  36. data = ret["minion"]["ret"]
  37. self.assertEqual(data["args"], ["foo", "bar", "baz"])
  38. self.assertEqual(data["kwargs"]["qux"], "quux")
  39. @skipIf(True, "SLOWTEST skip")
  40. def test_iter_no_block(self):
  41. """
  42. test cmd_iter_no_block
  43. """
  44. cmd_iter = self.client.cmd_iter_no_block(
  45. "minion", "test.arg", ["foo", "bar", "baz"], kwarg={"qux": "quux"}
  46. )
  47. for ret in cmd_iter:
  48. if ret is None:
  49. continue
  50. data = ret["minion"]["ret"]
  51. self.assertEqual(data["args"], ["foo", "bar", "baz"])
  52. self.assertEqual(data["kwargs"]["qux"], "quux")
  53. @skipIf(True, "SLOWTEST skip")
  54. def test_full_returns(self):
  55. """
  56. test cmd_iter
  57. """
  58. ret = self.client.cmd_full_return(
  59. "minion",
  60. "test.arg",
  61. ["foo", "bar", "baz"],
  62. timeout=self.TIMEOUT,
  63. kwarg={"qux": "quux"},
  64. )
  65. data = ret["minion"]["ret"]
  66. self.assertEqual(data["args"], ["foo", "bar", "baz"])
  67. self.assertEqual(data["kwargs"]["qux"], "quux")
  68. @skipIf(True, "SLOWTEST skip")
  69. def test_kwarg_type(self):
  70. """
  71. Test that kwargs end up on the client as the same type
  72. """
  73. terrible_yaml_string = 'foo: ""\n# \''
  74. ret = self.client.cmd_full_return(
  75. "minion",
  76. "test.arg_type",
  77. ["a", 1],
  78. kwarg={"outer": {"a": terrible_yaml_string}, "inner": "value"},
  79. timeout=self.TIMEOUT,
  80. )
  81. data = ret["minion"]["ret"]
  82. self.assertIn(six.text_type.__name__, data["args"][0])
  83. self.assertIn("int", data["args"][1])
  84. self.assertIn("dict", data["kwargs"]["outer"])
  85. self.assertIn(six.text_type.__name__, data["kwargs"]["inner"])
  86. @skipIf(True, "SLOWTEST skip")
  87. def test_full_return_kwarg(self):
  88. ret = self.client.cmd(
  89. "minion", "test.ping", full_return=True, timeout=self.TIMEOUT,
  90. )
  91. for mid, data in ret.items():
  92. self.assertIn("retcode", data)
  93. @skipIf(True, "SLOWTEST skip")
  94. def test_cmd_arg_kwarg_parsing(self):
  95. ret = self.client.cmd(
  96. "minion",
  97. "test.arg_clean",
  98. arg=["foo", "bar=off", "baz={qux: 123}"],
  99. kwarg={"quux": "Quux"},
  100. timeout=self.TIMEOUT,
  101. )
  102. self.assertEqual(
  103. ret["minion"],
  104. {
  105. "args": ["foo"],
  106. "kwargs": {"bar": False, "baz": {"qux": 123}, "quux": "Quux"},
  107. },
  108. )