test_timezone.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # -*- coding: utf-8 -*-
  2. """
  3. Integration tests for timezone module
  4. Linux and Solaris are supported
  5. """
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. import pytest
  8. import salt.utils.platform
  9. from tests.support.case import ModuleCase
  10. from tests.support.unit import skipIf
  11. try:
  12. import tzlocal # pylint: disable=unused-import
  13. HAS_TZLOCAL = True
  14. except ImportError:
  15. HAS_TZLOCAL = False
  16. class TimezoneLinuxModuleTest(ModuleCase):
  17. def setUp(self):
  18. """
  19. Set up Linux test environment
  20. """
  21. ret_grain = self.run_function("grains.item", ["kernel"])
  22. if "Linux" not in ret_grain["kernel"]:
  23. self.skipTest("For Linux only")
  24. super(TimezoneLinuxModuleTest, self).setUp()
  25. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  26. def test_get_hwclock(self):
  27. timescale = ["UTC", "localtime"]
  28. ret = self.run_function("timezone.get_hwclock")
  29. self.assertIn(ret, timescale)
  30. class TimezoneSolarisModuleTest(ModuleCase):
  31. def setUp(self):
  32. """
  33. Set up Solaris test environment
  34. """
  35. ret_grain = self.run_function("grains.item", ["os_family"])
  36. if "Solaris" not in ret_grain["os_family"]:
  37. self.skipTest("For Solaris only")
  38. super(TimezoneSolarisModuleTest, self).setUp()
  39. def test_get_hwclock(self):
  40. timescale = ["UTC", "localtime"]
  41. ret = self.run_function("timezone.get_hwclock")
  42. self.assertIn(ret, timescale)
  43. @skipIf(not salt.utils.platform.is_windows(), "windows test only")
  44. class TimezoneWindowsModuleTest(ModuleCase):
  45. def setUp(self):
  46. self.pre = self.run_function("timezone.get_zone")
  47. def tearDown(self):
  48. post = self.run_function("timezone.get_zone")
  49. if self.pre != post:
  50. self.run_function("timezone.set_zone", [self.pre])
  51. def test_get_hwclock(self):
  52. timescale = ["UTC", "localtime"]
  53. ret = self.run_function("timezone.get_hwclock")
  54. self.assertIn(ret, timescale)
  55. @pytest.mark.destructive_test
  56. def test_get_zone(self):
  57. """
  58. test timezone.set_zone, get_zone and zone_compare
  59. """
  60. zone = "America/Inuvik" if not HAS_TZLOCAL else "America/Denver"
  61. # first set the zone
  62. assert self.run_function("timezone.set_zone", [zone])
  63. # check it set the correct zone
  64. ret = self.run_function("timezone.get_zone")
  65. assert zone in ret
  66. # compare zones
  67. assert self.run_function("timezone.zone_compare", [zone])
  68. def test_get_offset(self):
  69. """
  70. test timezone.get_offset
  71. """
  72. ret = self.run_function("timezone.get_offset")
  73. self.assertIn("-", ret)