test_localemod.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. @skipIf(salt.utils.platform.is_windows(), "minion is windows")
  7. @skipIf(salt.utils.platform.is_darwin(), "locale method is not supported on mac")
  8. @skipIf(
  9. salt.utils.platform.is_freebsd(),
  10. "locale method is supported only within login classes or environment variables",
  11. )
  12. @requires_salt_modules("locale")
  13. @pytest.mark.windows_whitelisted
  14. class LocaleModuleTest(ModuleCase):
  15. def _find_new_locale(self, current_locale):
  16. test_locales = ["en_US.UTF-8", "de_DE.UTF-8", "fr_FR.UTF-8", "en_AU.UTF-8"]
  17. for locale in test_locales:
  18. if locale != current_locale and self.run_function("locale.avail", [locale]):
  19. return locale
  20. self.skipTest(
  21. "The test locals: {} do not exist on the host. Skipping test.".format(
  22. ",".join(test_locales)
  23. )
  24. )
  25. def test_get_locale(self):
  26. locale = self.run_function("locale.get_locale")
  27. self.assertNotIn("Unsupported platform!", locale)
  28. @destructiveTest
  29. @slowTest
  30. def test_gen_locale(self):
  31. # Make sure charmaps are available on test system before attempting
  32. # call gen_locale. We log this error to the user in the function, but
  33. # we don't want to fail this test if this is missing on the test system.
  34. char_maps = self.run_function("cmd.run_all", ["locale -m"])
  35. if char_maps["stdout"] == "":
  36. self.skipTest("locale charmaps not available. Skipping test.")
  37. if char_maps["retcode"] and char_maps["stderr"]:
  38. self.skipTest(
  39. "{}. Cannot generate locale. Skipping test.".format(char_maps["stderr"])
  40. )
  41. locale = self.run_function("locale.get_locale")
  42. new_locale = self._find_new_locale(locale)
  43. ret = self.run_function("locale.gen_locale", [new_locale])
  44. self.assertTrue(ret)
  45. @destructiveTest
  46. @slowTest
  47. def test_set_locale(self):
  48. original_locale = self.run_function("locale.get_locale")
  49. locale_to_set = self._find_new_locale(original_locale)
  50. self.run_function("locale.gen_locale", [locale_to_set])
  51. ret = self.run_function("locale.set_locale", [locale_to_set])
  52. new_locale = self.run_function("locale.get_locale")
  53. self.assertTrue(ret)
  54. self.assertEqual(locale_to_set, new_locale)
  55. self.run_function("locale.set_locale", [original_locale])