1
0

test_mac_timezone.py 7.6 KB

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