1
0

test_timezone.py 2.7 KB

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