1
0

test_arguments.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # -*- coding: utf-8 -*-
  2. """
  3. Test Salt's argument parser
  4. """
  5. from __future__ import absolute_import
  6. import pytest
  7. import salt.utils.args
  8. from tests.support.case import ModuleCase
  9. from tests.support.helpers import requires_salt_modules, slowTest
  10. @requires_salt_modules("test.ping", "test.arg")
  11. @pytest.mark.windows_whitelisted
  12. class ArgumentTestCase(ModuleCase):
  13. @slowTest
  14. def test_unsupported_kwarg(self):
  15. """
  16. Test passing a non-supported keyword argument. The relevant code that
  17. checks for invalid kwargs is located in salt/minion.py, within the
  18. 'load_args_and_kwargs' function.
  19. """
  20. self.assertIn(
  21. ("ERROR executing 'test.ping': The following keyword arguments"),
  22. self.run_function("test.ping", foo="bar"),
  23. )
  24. @slowTest
  25. def test_kwarg_name_containing_dashes(self):
  26. """
  27. Tests the arg parser to ensure that kwargs with dashes in the arg name
  28. are properly identified as kwargs. If this fails, then the KWARG_REGEX
  29. variable in salt/utils/__init__.py needs to be fixed.
  30. """
  31. # We need to use parse_input here because run_function now requires
  32. # kwargs to be passed in as *actual* kwargs, and dashes are not valid
  33. # characters in Python kwargs.
  34. self.assertEqual(
  35. self.run_function("test.arg", salt.utils.args.parse_input(["foo-bar=baz"]))
  36. .get("kwargs", {})
  37. .get("foo-bar"),
  38. "baz",
  39. )
  40. @slowTest
  41. def test_argument_containing_pound_sign(self):
  42. """
  43. Tests the argument parsing to ensure that a CLI argument with a pound
  44. sign doesn't have the pound sign interpreted as a comment and removed.
  45. See https://github.com/saltstack/salt/issues/8585 for more info.
  46. """
  47. arg = "foo bar #baz"
  48. self.assertEqual(self.run_function("test.echo", [arg]), arg)