1
0

test_localemod.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import pytest
  2. import salt.utils.platform
  3. from tests.support.case import ModuleCase
  4. from tests.support.helpers import destructiveTest, requires_salt_modules, slowTest
  5. from tests.support.unit import skipIf
  6. def _find_new_locale(current_locale):
  7. for locale in ["en_US.UTF-8", "de_DE.UTF-8", "fr_FR.UTF-8"]:
  8. if locale != current_locale:
  9. return locale
  10. @skipIf(salt.utils.platform.is_windows(), "minion is windows")
  11. @skipIf(salt.utils.platform.is_darwin(), "locale method is not supported on mac")
  12. @skipIf(
  13. salt.utils.platform.is_freebsd(),
  14. "locale method is supported only within login classes or environment variables",
  15. )
  16. @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. @destructiveTest
  23. @slowTest
  24. def test_gen_locale(self):
  25. # Make sure charmaps are available on test system before attempting
  26. # call gen_locale. We log this error to the user in the function, but
  27. # we don't want to fail this test if this is missing on the test system.
  28. char_maps = self.run_function("cmd.run_all", ["locale -m"])
  29. if char_maps["stdout"] == "":
  30. self.skipTest("locale charmaps not available. Skipping test.")
  31. if char_maps["retcode"] and char_maps["stderr"]:
  32. self.skipTest(
  33. "{}. Cannot generate locale. Skipping test.".format(char_maps["stderr"])
  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])