1
0

test_localemod.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # -*- coding: utf-8 -*-
  2. # Import Python libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. import pytest
  5. # Import Salt Testing libs
  6. from tests.support.case import ModuleCase
  7. from tests.support.unit import skipIf
  8. # Import Salt libs
  9. import salt.utils.platform
  10. def _find_new_locale(current_locale):
  11. for locale in ['en_US.UTF-8', 'de_DE.UTF-8', 'fr_FR.UTF-8']:
  12. if locale != current_locale:
  13. return locale
  14. @skipIf(salt.utils.platform.is_windows(), 'minion is windows')
  15. @skipIf(salt.utils.platform.is_darwin(), 'locale method is not supported on mac')
  16. @pytest.mark.requires_salt_modules('locale')
  17. @pytest.mark.windows_whitelisted
  18. class LocaleModuleTest(ModuleCase):
  19. def test_get_locale(self):
  20. locale = self.run_function('locale.get_locale')
  21. self.assertNotIn('Unsupported platform!', locale)
  22. @pytest.mark.destructive_test
  23. def test_gen_locale(self):
  24. # Make sure charmaps are available on test system before attempting
  25. # call gen_locale. We log this error to the user in the function, but
  26. # we don't want to fail this test if this is missing on the test system.
  27. char_maps = self.run_function('cmd.run_all', ['locale -m'])
  28. if char_maps['stdout'] == '':
  29. self.skipTest('locale charmaps not available. Skipping test.')
  30. if char_maps['retcode'] and char_maps['stderr']:
  31. self.skipTest('{0}. Cannot generate locale. Skipping test.'.format(
  32. char_maps['stderr'])
  33. )
  34. locale = self.run_function('locale.get_locale')
  35. new_locale = _find_new_locale(locale)
  36. ret = self.run_function('locale.gen_locale', [new_locale])
  37. self.assertTrue(ret)
  38. @pytest.mark.destructive_test
  39. def test_set_locale(self):
  40. original_locale = self.run_function('locale.get_locale')
  41. locale_to_set = _find_new_locale(original_locale)
  42. self.run_function('locale.gen_locale', [locale_to_set])
  43. ret = self.run_function('locale.set_locale', [locale_to_set])
  44. new_locale = self.run_function('locale.get_locale')
  45. self.assertTrue(ret)
  46. self.assertEqual(locale_to_set, new_locale)
  47. self.run_function('locale.set_locale', [original_locale])