1
0

test_arguments.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. class ArgumentTestCase(ModuleCase):
  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. 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(
  35. 'test.arg', salt.utils.args.parse_input(['foo-bar=baz'])
  36. ).get('kwargs', {}).get('foo-bar'),
  37. 'baz'
  38. )
  39. def test_argument_containing_pound_sign(self):
  40. '''
  41. Tests the argument parsing to ensure that a CLI argument with a pound
  42. sign doesn't have the pound sign interpreted as a comment and removed.
  43. See https://github.com/saltstack/salt/issues/8585 for more info.
  44. '''
  45. arg = 'foo bar #baz'
  46. self.assertEqual(
  47. self.run_function('test.echo', [arg]),
  48. arg
  49. )