test_mac_timezone.py 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. # -*- coding: utf-8 -*-
  2. """
  3. Integration tests for mac_timezone
  4. If using parallels, make sure Time sync is turned off. Otherwise, parallels will
  5. keep changing your date/time settings while the tests are running. To turn off
  6. Time sync do the following:
  7. - Go to actions -> configure
  8. - Select options at the top and 'More Options' on the left
  9. - Set time to 'Do not sync'
  10. """
  11. from __future__ import absolute_import, print_function, unicode_literals
  12. import datetime
  13. from salt.ext import six
  14. from tests.support.case import ModuleCase
  15. from tests.support.helpers import (
  16. destructiveTest,
  17. flaky,
  18. runs_on,
  19. skip_if_binaries_missing,
  20. skip_if_not_root,
  21. slowTest,
  22. )
  23. from tests.support.unit import skipIf
  24. @skip_if_not_root
  25. @flaky
  26. @runs_on(kernel="Darwin")
  27. @skip_if_binaries_missing("systemsetup")
  28. class MacTimezoneModuleTest(ModuleCase):
  29. """
  30. Validate the mac_timezone module
  31. """
  32. USE_NETWORK_TIME = False
  33. TIME_SERVER = "time.apple.com"
  34. TIME_ZONE = ""
  35. CURRENT_DATE = ""
  36. CURRENT_TIME = ""
  37. def setUp(self):
  38. """
  39. Get current settings
  40. """
  41. self.USE_NETWORK_TIME = self.run_function("timezone.get_using_network_time")
  42. self.TIME_SERVER = self.run_function("timezone.get_time_server")
  43. self.TIME_ZONE = self.run_function("timezone.get_zone")
  44. self.CURRENT_DATE = self.run_function("timezone.get_date")
  45. self.CURRENT_TIME = self.run_function("timezone.get_time")
  46. self.run_function("timezone.set_using_network_time", [False])
  47. self.run_function("timezone.set_zone", ["America/Denver"])
  48. def tearDown(self):
  49. """
  50. Reset to original settings
  51. """
  52. self.run_function("timezone.set_time_server", [self.TIME_SERVER])
  53. self.run_function("timezone.set_using_network_time", [self.USE_NETWORK_TIME])
  54. self.run_function("timezone.set_zone", [self.TIME_ZONE])
  55. if not self.USE_NETWORK_TIME:
  56. self.run_function("timezone.set_date", [self.CURRENT_DATE])
  57. self.run_function("timezone.set_time", [self.CURRENT_TIME])
  58. @skipIf(
  59. True,
  60. "Skip until we can figure out why modifying the system clock causes ZMQ errors",
  61. )
  62. @destructiveTest
  63. def test_get_set_date(self):
  64. """
  65. Test timezone.get_date
  66. Test timezone.set_date
  67. """
  68. # Correct Functionality
  69. self.assertTrue(self.run_function("timezone.set_date", ["2/20/2011"]))
  70. self.assertEqual(self.run_function("timezone.get_date"), "2/20/2011")
  71. # Test bad date format
  72. self.assertEqual(
  73. self.run_function("timezone.set_date", ["13/12/2014"]),
  74. "ERROR executing 'timezone.set_date': "
  75. "Invalid Date/Time Format: 13/12/2014",
  76. )
  77. @slowTest
  78. def test_get_time(self):
  79. """
  80. Test timezone.get_time
  81. """
  82. text_time = self.run_function("timezone.get_time")
  83. self.assertNotEqual(text_time, "Invalid Timestamp")
  84. obj_date = datetime.datetime.strptime(text_time, "%H:%M:%S")
  85. self.assertIsInstance(obj_date, datetime.date)
  86. @skipIf(
  87. True,
  88. "Skip until we can figure out why modifying the system clock causes ZMQ errors",
  89. )
  90. @destructiveTest
  91. def test_set_time(self):
  92. """
  93. Test timezone.set_time
  94. """
  95. # Correct Functionality
  96. self.assertTrue(self.run_function("timezone.set_time", ["3:14"]))
  97. # Test bad time format
  98. self.assertEqual(
  99. self.run_function("timezone.set_time", ["3:71"]),
  100. "ERROR executing 'timezone.set_time': " "Invalid Date/Time Format: 3:71",
  101. )
  102. @skipIf(
  103. True,
  104. "Skip until we can figure out why modifying the system clock causes ZMQ errors",
  105. )
  106. @destructiveTest
  107. def test_get_set_zone(self):
  108. """
  109. Test timezone.get_zone
  110. Test timezone.set_zone
  111. """
  112. # Correct Functionality
  113. self.assertTrue(self.run_function("timezone.set_zone", ["Pacific/Wake"]))
  114. self.assertEqual(self.run_function("timezone.get_zone"), "Pacific/Wake")
  115. # Test bad time zone
  116. self.assertEqual(
  117. self.run_function("timezone.set_zone", ["spongebob"]),
  118. "ERROR executing 'timezone.set_zone': " "Invalid Timezone: spongebob",
  119. )
  120. @skipIf(
  121. True,
  122. "Skip until we can figure out why modifying the system clock causes ZMQ errors",
  123. )
  124. @destructiveTest
  125. def test_get_offset(self):
  126. """
  127. Test timezone.get_offset
  128. """
  129. self.assertTrue(self.run_function("timezone.set_zone", ["Pacific/Wake"]))
  130. self.assertIsInstance(
  131. self.run_function("timezone.get_offset"), six.string_types
  132. )
  133. self.assertEqual(self.run_function("timezone.get_offset"), "+1200")
  134. self.assertTrue(self.run_function("timezone.set_zone", ["America/Los_Angeles"]))
  135. self.assertIsInstance(
  136. self.run_function("timezone.get_offset"), six.string_types
  137. )
  138. self.assertEqual(self.run_function("timezone.get_offset"), "-0700")
  139. @skipIf(
  140. True,
  141. "Skip until we can figure out why modifying the system clock causes ZMQ errors",
  142. )
  143. @destructiveTest
  144. def test_get_set_zonecode(self):
  145. """
  146. Test timezone.get_zonecode
  147. Test timezone.set_zonecode
  148. """
  149. self.assertTrue(self.run_function("timezone.set_zone", ["America/Los_Angeles"]))
  150. self.assertIsInstance(
  151. self.run_function("timezone.get_zonecode"), six.string_types
  152. )
  153. self.assertEqual(self.run_function("timezone.get_zonecode"), "PDT")
  154. self.assertTrue(self.run_function("timezone.set_zone", ["Pacific/Wake"]))
  155. self.assertIsInstance(
  156. self.run_function("timezone.get_zonecode"), six.string_types
  157. )
  158. self.assertEqual(self.run_function("timezone.get_zonecode"), "WAKT")
  159. @slowTest
  160. def test_list_zones(self):
  161. """
  162. Test timezone.list_zones
  163. """
  164. zones = self.run_function("timezone.list_zones")
  165. self.assertIsInstance(self.run_function("timezone.list_zones"), list)
  166. self.assertIn("America/Denver", self.run_function("timezone.list_zones"))
  167. self.assertIn("America/Los_Angeles", self.run_function("timezone.list_zones"))
  168. @skipIf(
  169. True,
  170. "Skip until we can figure out why modifying the system clock causes ZMQ errors",
  171. )
  172. @destructiveTest
  173. def test_zone_compare(self):
  174. """
  175. Test timezone.zone_compare
  176. """
  177. self.assertTrue(self.run_function("timezone.set_zone", ["America/Denver"]))
  178. self.assertTrue(self.run_function("timezone.zone_compare", ["America/Denver"]))
  179. self.assertFalse(self.run_function("timezone.zone_compare", ["Pacific/Wake"]))
  180. @skipIf(
  181. True,
  182. "Skip until we can figure out why modifying the system clock causes ZMQ errors",
  183. )
  184. @destructiveTest
  185. def test_get_set_using_network_time(self):
  186. """
  187. Test timezone.get_using_network_time
  188. Test timezone.set_using_network_time
  189. """
  190. self.assertTrue(self.run_function("timezone.set_using_network_time", [True]))
  191. self.assertTrue(self.run_function("timezone.get_using_network_time"))
  192. self.assertTrue(self.run_function("timezone.set_using_network_time", [False]))
  193. self.assertFalse(self.run_function("timezone.get_using_network_time"))
  194. @skipIf(
  195. True,
  196. "Skip until we can figure out why modifying the system clock causes ZMQ errors",
  197. )
  198. @destructiveTest
  199. def test_get_set_time_server(self):
  200. """
  201. Test timezone.get_time_server
  202. Test timezone.set_time_server
  203. """
  204. self.assertTrue(
  205. self.run_function("timezone.set_time_server", ["spongebob.com"])
  206. )
  207. self.assertEqual(self.run_function("timezone.get_time_server"), "spongebob.com")