test_localemod.py 2.3 KB

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