class TimezoneInterfaceTestCase(unittest.TestCase): """Test DBus interface for the timezone module.""" def setUp(self): """Set up the timezone module.""" # Set up the timezone module. self.timezone_module = TimezoneService() self.timezone_interface = TimezoneInterface(self.timezone_module) # Connect to the properties changed signal. self.callback = Mock() self.timezone_interface.PropertiesChanged.connect(self.callback) def kickstart_properties_test(self): """Test kickstart properties.""" self.assertEqual(self.timezone_interface.KickstartCommands, ["timezone"]) self.assertEqual(self.timezone_interface.KickstartSections, []) self.assertEqual(self.timezone_interface.KickstartAddons, []) self.callback.assert_not_called() def timezone_property_test(self): """Test the Timezone property.""" self.timezone_interface.SetTimezone("Europe/Prague") self.assertEqual(self.timezone_interface.Timezone, "Europe/Prague") self.callback.assert_called_once_with(TIMEZONE.interface_name, {'Timezone': 'Europe/Prague'}, []) def utc_property_test(self): """Test the IsUtc property.""" self.timezone_interface.SetIsUTC(True) self.assertEqual(self.timezone_interface.IsUTC, True) self.callback.assert_called_once_with(TIMEZONE.interface_name, {'IsUTC': True}, []) def ntp_property_test(self): """Test the NTPEnabled property.""" self.timezone_interface.SetNTPEnabled(False) self.assertEqual(self.timezone_interface.NTPEnabled, False) self.callback.assert_called_once_with(TIMEZONE.interface_name, {'NTPEnabled': False}, []) def ntp_servers_property_test(self): """Test the NTPServers property.""" self.timezone_interface.SetNTPServers(["ntp.cesnet.cz"]) self.assertEqual(self.timezone_interface.NTPServers, ["ntp.cesnet.cz"]) self.callback.assert_called_once_with( TIMEZONE.interface_name, {'NTPServers': ["ntp.cesnet.cz"]}, []) def _test_kickstart(self, ks_in, ks_out): check_kickstart_interface(self, self.timezone_interface, ks_in, ks_out) def no_kickstart_test(self): """Test with no kickstart.""" ks_in = None ks_out = """ # System timezone timezone America/New_York """ self._test_kickstart(ks_in, ks_out) def kickstart_empty_test(self): """Test with empty string.""" ks_in = "" ks_out = "" self._test_kickstart(ks_in, ks_out) def kickstart_test(self): """Test the timezone command.""" ks_in = """ timezone Europe/Prague """ ks_out = """ # System timezone timezone Europe/Prague """ self._test_kickstart(ks_in, ks_out) def kickstart2_test(self): """Test the timezone command with flags.""" ks_in = """ timezone --utc --nontp Europe/Prague """ ks_out = """ # System timezone timezone Europe/Prague --isUtc --nontp """ self._test_kickstart(ks_in, ks_out) def kickstart3_test(self): """Test the timezone command with ntp servers..""" ks_in = """ timezone --ntpservers ntp.cesnet.cz Europe/Prague """ ks_out = """ # System timezone timezone Europe/Prague --ntpservers=ntp.cesnet.cz """ self._test_kickstart(ks_in, ks_out)
class TimezoneInterfaceTestCase(unittest.TestCase): """Test DBus interface for the timezone module.""" def setUp(self): """Set up the timezone module.""" # Set up the timezone module. self.timezone_module = TimezoneService() self.timezone_interface = TimezoneInterface(self.timezone_module) # Connect to the properties changed signal. self.callback = PropertiesChangedCallback() self.timezone_interface.PropertiesChanged.connect(self.callback) def kickstart_properties_test(self): """Test kickstart properties.""" self.assertEqual(self.timezone_interface.KickstartCommands, ["timezone"]) self.assertEqual(self.timezone_interface.KickstartSections, []) self.assertEqual(self.timezone_interface.KickstartAddons, []) self.callback.assert_not_called() def timezone_property_test(self): """Test the Timezone property.""" self.timezone_interface.SetTimezone("Europe/Prague") self.assertEqual(self.timezone_interface.Timezone, "Europe/Prague") self.callback.assert_called_once_with(TIMEZONE.interface_name, {'Timezone': 'Europe/Prague'}, []) def utc_property_test(self): """Test the IsUtc property.""" self.timezone_interface.SetIsUTC(True) self.assertEqual(self.timezone_interface.IsUTC, True) self.callback.assert_called_once_with(TIMEZONE.interface_name, {'IsUTC': True}, []) def ntp_property_test(self): """Test the NTPEnabled property.""" self.timezone_interface.SetNTPEnabled(False) self.assertEqual(self.timezone_interface.NTPEnabled, False) self.callback.assert_called_once_with(TIMEZONE.interface_name, {'NTPEnabled': False}, []) def ntp_servers_property_test(self): """Test the NTPServers property.""" self.timezone_interface.SetNTPServers(["ntp.cesnet.cz"]) self.assertEqual(self.timezone_interface.NTPServers, ["ntp.cesnet.cz"]) self.callback.assert_called_once_with( TIMEZONE.interface_name, {'NTPServers': ["ntp.cesnet.cz"]}, []) def _test_kickstart(self, ks_in, ks_out): check_kickstart_interface(self, self.timezone_interface, ks_in, ks_out) def no_kickstart_test(self): """Test with no kickstart.""" ks_in = None ks_out = """ # System timezone timezone America/New_York """ self._test_kickstart(ks_in, ks_out) def kickstart_empty_test(self): """Test with empty string.""" ks_in = "" ks_out = "" self._test_kickstart(ks_in, ks_out) def kickstart_test(self): """Test the timezone command.""" ks_in = """ timezone Europe/Prague """ ks_out = """ # System timezone timezone Europe/Prague """ self._test_kickstart(ks_in, ks_out) def kickstart2_test(self): """Test the timezone command with flags.""" ks_in = """ timezone --utc --nontp Europe/Prague """ ks_out = """ # System timezone timezone Europe/Prague --utc --nontp """ self._test_kickstart(ks_in, ks_out) def kickstart3_test(self): """Test the timezone command with ntp servers..""" ks_in = """ timezone --ntpservers ntp.cesnet.cz Europe/Prague """ ks_out = """ # System timezone timezone Europe/Prague --ntpservers=ntp.cesnet.cz """ self._test_kickstart(ks_in, ks_out) @patch_dbus_publish_object def install_with_tasks_default_test(self, publisher): """Test install tasks - module in default state.""" tasks = self.timezone_interface.InstallWithTasks() timezone_task_path = tasks[0] ntp_task_path = tasks[1] publisher.assert_called() # timezone configuration timezone_object_path = publisher.call_args_list[0][0][0] tz_obj = publisher.call_args_list[0][0][1] self.assertEqual(timezone_task_path, timezone_object_path) self.assertIsInstance(tz_obj, TaskInterface) self.assertIsInstance(tz_obj.implementation, ConfigureTimezoneTask) self.assertEqual(tz_obj.implementation._timezone, "America/New_York") self.assertEqual(tz_obj.implementation._is_utc, False) # NTP configuration ntp_object_path = publisher.call_args_list[1][0][0] ntp_obj = publisher.call_args_list[1][0][1] self.assertEqual(ntp_task_path, ntp_object_path) self.assertIsInstance(ntp_obj, TaskInterface) self.assertIsInstance(ntp_obj.implementation, ConfigureNTPTask) self.assertEqual(ntp_obj.implementation._ntp_enabled, True) @patch_dbus_publish_object def install_with_tasks_configured_test(self, publisher): """Test install tasks - module in configured state.""" self.timezone_interface.SetNTPEnabled(False) self.timezone_interface.SetIsUTC(True) self.timezone_interface.SetTimezone("Asia/Tokyo") tasks = self.timezone_interface.InstallWithTasks() timezone_task_path = tasks[0] ntp_task_path = tasks[1] publisher.assert_called() # timezone configuration timezone_object_path = publisher.call_args_list[0][0][0] tz_obj = publisher.call_args_list[0][0][1] self.assertEqual(timezone_task_path, timezone_object_path) self.assertIsInstance(tz_obj, TaskInterface) self.assertIsInstance(tz_obj.implementation, ConfigureTimezoneTask) self.assertEqual(tz_obj.implementation._timezone, "Asia/Tokyo") self.assertEqual(tz_obj.implementation._is_utc, True) # NTP configuration ntp_object_path = publisher.call_args_list[1][0][0] ntp_obj = publisher.call_args_list[1][0][1] self.assertEqual(ntp_task_path, ntp_object_path) self.assertIsInstance(ntp_obj, TaskInterface) self.assertIsInstance(ntp_obj.implementation, ConfigureNTPTask) self.assertEqual(ntp_obj.implementation._ntp_enabled, False)
class TimezoneInterfaceTestCase(unittest.TestCase): """Test DBus interface for the timezone module.""" def setUp(self): """Set up the timezone module.""" # Set up the timezone module. self.timezone_module = TimezoneService() self.timezone_interface = TimezoneInterface(self.timezone_module) # Connect to the properties changed signal. self.callback = PropertiesChangedCallback() self.timezone_interface.PropertiesChanged.connect(self.callback) def kickstart_properties_test(self): """Test kickstart properties.""" self.assertEqual(self.timezone_interface.KickstartCommands, ["timezone"]) self.assertEqual(self.timezone_interface.KickstartSections, []) self.assertEqual(self.timezone_interface.KickstartAddons, []) self.callback.assert_not_called() def timezone_property_test(self): """Test the Timezone property.""" self.timezone_interface.SetTimezone("Europe/Prague") self.assertEqual(self.timezone_interface.Timezone, "Europe/Prague") self.callback.assert_called_once_with(TIMEZONE.interface_name, {'Timezone': 'Europe/Prague'}, []) def utc_property_test(self): """Test the IsUtc property.""" self.timezone_interface.SetIsUTC(True) self.assertEqual(self.timezone_interface.IsUTC, True) self.callback.assert_called_once_with(TIMEZONE.interface_name, {'IsUTC': True}, []) def ntp_property_test(self): """Test the NTPEnabled property.""" self.timezone_interface.SetNTPEnabled(False) self.assertEqual(self.timezone_interface.NTPEnabled, False) self.callback.assert_called_once_with(TIMEZONE.interface_name, {'NTPEnabled': False}, []) def ntp_servers_property_test(self): """Test the NTPServers property.""" self.timezone_interface.SetNTPServers(["ntp.cesnet.cz"]) self.assertEqual(self.timezone_interface.NTPServers, ["ntp.cesnet.cz"]) self.callback.assert_called_once_with( TIMEZONE.interface_name, {'NTPServers': ["ntp.cesnet.cz"]}, []) def _test_kickstart(self, ks_in, ks_out): check_kickstart_interface(self, self.timezone_interface, ks_in, ks_out) def no_kickstart_test(self): """Test with no kickstart.""" ks_in = None ks_out = """ # System timezone timezone America/New_York """ self._test_kickstart(ks_in, ks_out) def kickstart_empty_test(self): """Test with empty string.""" ks_in = "" ks_out = "" self._test_kickstart(ks_in, ks_out) def kickstart_test(self): """Test the timezone command.""" ks_in = """ timezone Europe/Prague """ ks_out = """ # System timezone timezone Europe/Prague """ self._test_kickstart(ks_in, ks_out) def kickstart2_test(self): """Test the timezone command with flags.""" ks_in = """ timezone --utc --nontp Europe/Prague """ ks_out = """ # System timezone timezone Europe/Prague --utc --nontp """ self._test_kickstart(ks_in, ks_out) def kickstart3_test(self): """Test the timezone command with ntp servers..""" ks_in = """ timezone --ntpservers ntp.cesnet.cz Europe/Prague """ ks_out = """ # System timezone timezone Europe/Prague --ntpservers=ntp.cesnet.cz """ self._test_kickstart(ks_in, ks_out) @patch_dbus_publish_object def install_with_tasks_default_test(self, publisher): """Test install tasks - module in default state.""" task_classes = [ ConfigureTimezoneTask, ConfigureNTPTask, ] task_paths = self.timezone_interface.InstallWithTasks() task_objs = check_task_creation_list(self, task_paths, publisher, task_classes) # ConfigureTimezoneTask obj = task_objs[0] self.assertEqual(obj.implementation._timezone, "America/New_York") self.assertEqual(obj.implementation._is_utc, False) # ConfigureNTPTask obj = task_objs[1] self.assertEqual(obj.implementation._ntp_enabled, True) self.assertEqual(obj.implementation._ntp_servers, []) @patch_dbus_publish_object def install_with_tasks_configured_test(self, publisher): """Test install tasks - module in configured state.""" self.timezone_interface.SetIsUTC(True) self.timezone_interface.SetTimezone("Asia/Tokyo") self.timezone_interface.SetNTPEnabled(False) # --nontp and --ntpservers are mutually exclusive in kicstart but # there is no such enforcement in the module so for testing this is ok self.timezone_interface.SetNTPServers([ "clock1.example.com", "clock2.example.com", ]) task_classes = [ ConfigureTimezoneTask, ConfigureNTPTask, ] task_paths = self.timezone_interface.InstallWithTasks() task_objs = check_task_creation_list(self, task_paths, publisher, task_classes) # ConfigureTimezoneTask obj = task_objs[0] self.assertEqual(obj.implementation._timezone, "Asia/Tokyo") self.assertEqual(obj.implementation._is_utc, True) # ConfigureNTPTask obj = task_objs[1] self.assertEqual(obj.implementation._ntp_enabled, False) self.assertEqual(obj.implementation._ntp_servers, [ "clock1.example.com", "clock2.example.com", ]) @patch_dbus_publish_object def configure_ntp_service_enablement_default_test(self, publisher): """Test ntp service enablement with default module state.""" ntp_excluded = True task_path = self.timezone_interface.ConfigureNTPServiceEnablementWithTask( ntp_excluded) obj = check_task_creation(self, task_path, publisher, ConfigureNTPServiceEnablementTask) self.assertEqual(obj.implementation._ntp_enabled, True) self.assertEqual(obj.implementation._ntp_excluded, ntp_excluded) @patch_dbus_publish_object def configure_ntp_service_enablement_configured_test(self, publisher): """Test ntp service enablement with configured module state.""" ntp_excluded = False self.timezone_interface.SetNTPEnabled(False) task_path = self.timezone_interface.ConfigureNTPServiceEnablementWithTask( ntp_excluded) obj = check_task_creation(self, task_path, publisher, ConfigureNTPServiceEnablementTask) self.assertEqual(obj.implementation._ntp_enabled, False) self.assertEqual(obj.implementation._ntp_excluded, ntp_excluded) def deprecated_warnings_test(self): response = self.timezone_interface.ReadKickstart( "timezone --isUtc Europe/Bratislava") report = KickstartReport.from_structure(response) warning = "The option --isUtc will be deprecated in future releases. " \ "Please modify your kickstart file to replace this option with " \ "its preferred alias --utc." self.assertEqual(len(report.warning_messages), 1) self.assertEqual(report.warning_messages[0].message, warning)
class TimezoneInterfaceTestCase(unittest.TestCase): """Test DBus interface for the timezone module.""" def setUp(self): """Set up the timezone module.""" # Set up the timezone module. self.timezone_module = TimezoneModule() self.timezone_interface = TimezoneInterface(self.timezone_module) # Connect to the properties changed signal. self.callback = Mock() self.timezone_interface.PropertiesChanged.connect(self.callback) def kickstart_properties_test(self): """Test kickstart properties.""" self.assertEqual(self.timezone_interface.KickstartCommands, ["timezone"]) self.assertEqual(self.timezone_interface.KickstartSections, []) self.assertEqual(self.timezone_interface.KickstartAddons, []) self.callback.assert_not_called() def timezone_property_test(self): """Test the Timezone property.""" self.timezone_interface.SetTimezone("Europe/Prague") self.assertEqual(self.timezone_interface.Timezone, "Europe/Prague") self.callback.assert_called_once_with(MODULE_TIMEZONE_NAME, {'Timezone': 'Europe/Prague'}, []) def utc_property_test(self): """Test the IsUtc property.""" self.timezone_interface.SetIsUTC(True) self.assertEqual(self.timezone_interface.IsUTC, True) self.callback.assert_called_once_with(MODULE_TIMEZONE_NAME, {'IsUTC': True}, []) def ntp_property_test(self): """Test the NTPEnabled property.""" self.timezone_interface.SetNTPEnabled(False) self.assertEqual(self.timezone_interface.NTPEnabled, False) self.callback.assert_called_once_with(MODULE_TIMEZONE_NAME, {'NTPEnabled': False}, []) def ntp_servers_property_test(self): """Test the NTPServers property.""" self.timezone_interface.SetNTPServers(["ntp.cesnet.cz"]) self.assertEqual(self.timezone_interface.NTPServers, ["ntp.cesnet.cz"]) self.callback.assert_called_once_with( MODULE_TIMEZONE_NAME, {'NTPServers': ["ntp.cesnet.cz"]}, []) def _test_kickstart(self, ks_in, ks_out): """Test the kickstart string.""" # Remove extra spaces from the expected output. ks_output = "\n".join("".join(line.strip()) for line in ks_out.strip("\n").splitlines()) # Read a kickstart, result = self.timezone_interface.ReadKickstart(ks_in) self.assertEqual({k: v.unpack() for k, v in result.items()}, {"success": True}) # Generate a kickstart. self.assertEqual(ks_output, self.timezone_interface.GenerateKickstart()) # Test the properties changed callback. self.callback.assert_any_call(DBUS_MODULE_NAMESPACE, {'Kickstarted': True}, []) def kickstart_test(self): """Test the timezone command.""" ks_in = """ timezone Europe/Prague """ ks_out = """ #version=DEVEL # System timezone timezone Europe/Prague """ self._test_kickstart(ks_in, ks_out) def kickstart2_test(self): """Test the timezone command with flags.""" ks_in = """ timezone --utc --nontp Europe/Prague """ ks_out = """ #version=DEVEL # System timezone timezone Europe/Prague --isUtc --nontp """ self._test_kickstart(ks_in, ks_out) def kickstart3_test(self): """Test the timezone command with ntp servers..""" ks_in = """ timezone --ntpservers ntp.cesnet.cz Europe/Prague """ ks_out = """ #version=DEVEL # System timezone timezone Europe/Prague --ntpservers=ntp.cesnet.cz """ self._test_kickstart(ks_in, ks_out)