test_arguments.py 2.0 KB

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