1
0

test_arguments.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # -*- coding: utf-8 -*-
  2. '''
  3. Test Salt's argument parser
  4. '''
  5. # Import Python libs
  6. from __future__ import absolute_import
  7. import pytest
  8. # Import Salt Testing libs
  9. from tests.support.case import ModuleCase
  10. # Import Salt libs
  11. import salt.utils.args
  12. @pytest.mark.requires_salt_modules('test.ping', 'test.arg')
  13. @pytest.mark.windows_whitelisted
  14. class ArgumentTestCase(ModuleCase):
  15. def test_unsupported_kwarg(self):
  16. '''
  17. Test passing a non-supported keyword argument. The relevant code that
  18. checks for invalid kwargs is located in salt/minion.py, within the
  19. 'load_args_and_kwargs' function.
  20. '''
  21. self.assertIn(
  22. ("ERROR executing 'test.ping': The following keyword arguments"),
  23. self.run_function('test.ping', foo='bar')
  24. )
  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(
  36. 'test.arg', salt.utils.args.parse_input(['foo-bar=baz'])
  37. ).get('kwargs', {}).get('foo-bar'),
  38. 'baz'
  39. )
  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(
  48. self.run_function('test.echo', [arg]),
  49. arg
  50. )