Esempio n. 1
0
class LocalizationInterfaceTestCase(unittest.TestCase):
    """Test DBus interface for the localization module."""
    def setUp(self):
        """Set up the localization module."""
        # Set up the localization module.
        self.localization_module = LocalizationService()
        self.localization_interface = LocalizationInterface(
            self.localization_module)

        # Connect to the properties changed signal.
        self.callback = PropertiesChangedCallback()
        self.localization_interface.PropertiesChanged.connect(self.callback)

    def test_kickstart_properties(self):
        """Test kickstart properties."""
        assert self.localization_interface.KickstartCommands == [
            "keyboard", "lang"
        ]
        assert self.localization_interface.KickstartSections == []
        assert self.localization_interface.KickstartAddons == []
        self.callback.assert_not_called()

    def test_language_property(self):
        """Test the Language property."""
        self.localization_interface.SetLanguage("cs_CZ.UTF-8")
        assert self.localization_interface.Language == "cs_CZ.UTF-8"
        self.callback.assert_called_once_with(LOCALIZATION.interface_name,
                                              {'Language': 'cs_CZ.UTF-8'}, [])

    def test_language_support_property(self):
        """Test the LanguageSupport property."""
        self.localization_interface.SetLanguageSupport(["fr_FR"])
        assert self.localization_interface.LanguageSupport == ["fr_FR"]
        self.callback.assert_called_once_with(LOCALIZATION.interface_name,
                                              {'LanguageSupport': ["fr_FR"]},
                                              [])

    def test_vc_keymap_property(self):
        """Test the VirtualConsoleKeymap property."""
        self.localization_interface.SetVirtualConsoleKeymap("cz")
        assert self.localization_interface.VirtualConsoleKeymap == "cz"
        self.callback.assert_called_once_with(LOCALIZATION.interface_name,
                                              {'VirtualConsoleKeymap': 'cz'},
                                              [])

    def test_x_layouts_property(self):
        """Test the XLayouts property."""
        self.localization_interface.SetXLayouts(["en", "cz(querty)"])
        assert self.localization_interface.XLayouts == ["en", "cz(querty)"]
        self.callback.assert_called_once_with(
            LOCALIZATION.interface_name, {'XLayouts': ["en", "cz(querty)"]},
            [])

    def test_switch_options_property(self):
        """Test the LayoutSwitchOptions property."""
        self.localization_interface.SetLayoutSwitchOptions(
            ["grp:alt_shift_toggle"])
        assert self.localization_interface.LayoutSwitchOptions == [
            "grp:alt_shift_toggle"
        ]
        self.callback.assert_called_once_with(
            LOCALIZATION.interface_name,
            {'LayoutSwitchOptions': ["grp:alt_shift_toggle"]}, [])

    def test_keyboard_seen(self):
        """Test the KeyboardKickstarted property."""
        assert self.localization_interface.KeyboardKickstarted == False
        ks_in = """
        lang cs_CZ.UTF-8
        """
        ks_in = dedent(ks_in).strip()
        self.localization_interface.ReadKickstart(ks_in)
        assert self.localization_interface.KeyboardKickstarted == False
        ks_in = """
        lang cs_CZ.UTF-8
        keyboard cz
        """
        ks_in = dedent(ks_in).strip()
        self.localization_interface.ReadKickstart(ks_in)
        assert self.localization_interface.KeyboardKickstarted == True

    def test_language_seen(self):
        """Test the LanguageKickstarted property."""
        assert self.localization_interface.LanguageKickstarted == False
        ks_in = """
        keyboard cz
        """
        ks_in = dedent(ks_in).strip()
        self.localization_interface.ReadKickstart(ks_in)
        assert self.localization_interface.LanguageKickstarted == False
        ks_in = """
        keyboard cz
        lang cs_CZ.UTF-8
        """
        ks_in = dedent(ks_in).strip()
        self.localization_interface.ReadKickstart(ks_in)
        assert self.localization_interface.LanguageKickstarted == True

    def test_set_language_kickstarted(self):
        """Test SetLanguageKickstarted."""
        self.localization_interface.SetLanguageKickstarted(True)
        assert self.localization_interface.LanguageKickstarted == True
        self.callback.assert_called_once_with(LOCALIZATION.interface_name,
                                              {'LanguageKickstarted': True},
                                              [])

    def test_set_keyboard_kickstarted(self):
        """Test SetLanguageKickstarted."""
        self.localization_interface.SetKeyboardKickstarted(True)
        assert self.localization_interface.KeyboardKickstarted == True
        self.callback.assert_called_once_with(LOCALIZATION.interface_name,
                                              {'KeyboardKickstarted': True},
                                              [])

    @patch("pyanaconda.modules.localization.runtime.try_to_load_keymap")
    def test_set_keyboard(self, mocked_load_keymap):
        """Test SetKeyboard."""
        # Makes sure VirtualConsoleKeymap setting will be used no matter the
        # conf.system.can_activate_keyboard value is.
        mocked_load_keymap.return_value = True
        self.localization_interface.SetKeyboard("us")
        assert self.localization_interface.VirtualConsoleKeymap == "us"

    def test_collect_requirements(self):
        """Test the CollectRequirements method."""
        # No default requirements.
        assert self.localization_interface.CollectRequirements() == []

        # No additional support for ascii keyboard layouts.
        self.localization_interface.SetVirtualConsoleKeymap("en")
        assert self.localization_interface.CollectRequirements() == []

        # Additional support for non-ascii keyboard layouts.
        self.localization_interface.SetVirtualConsoleKeymap("ru")

        requirements = Requirement.from_structure_list(
            self.localization_interface.CollectRequirements())

        assert len(requirements) == 1
        assert requirements[0].type == "package"
        assert requirements[0].name == "kbd-legacy"

        # "fi" keyboard layout is in kbd-legacy too (#1955793)
        self.localization_interface.SetVirtualConsoleKeymap("fi")

        requirements = Requirement.from_structure_list(
            self.localization_interface.CollectRequirements())

        assert len(requirements) == 1
        assert requirements[0].type == "package"
        assert requirements[0].name == "kbd-legacy"

    @patch_dbus_publish_object
    def test_install_with_task(self, publisher):
        """Test InstallWithTask."""
        self.localization_interface.SetLanguage("cs_CZ.UTF-8")
        self.localization_interface.SetVirtualConsoleKeymap('us')
        self.localization_interface.SetXLayouts(['cz', 'cz (qwerty)'])
        self.localization_interface.SetLayoutSwitchOptions(
            ["grp:alt_shift_toggle"])

        tasks = self.localization_interface.InstallWithTasks()
        language_installation_task_path = tasks[0]
        keyboard_installation_task_path = tasks[1]

        publisher.assert_called()

        object_path = publisher.call_args_list[0][0][0]
        obj = publisher.call_args_list[0][0][1]

        assert language_installation_task_path == object_path
        assert isinstance(obj, TaskInterface)
        assert isinstance(obj.implementation, LanguageInstallationTask)
        assert obj.implementation._lang == "cs_CZ.UTF-8"

        object_path = publisher.call_args_list[1][0][0]
        obj = publisher.call_args_list[1][0][1]

        assert keyboard_installation_task_path == object_path
        assert isinstance(obj, TaskInterface)
        assert isinstance(obj.implementation, KeyboardInstallationTask)
        assert obj.implementation._x_layouts == ['cz', 'cz (qwerty)']
        assert obj.implementation._vc_keymap == 'us'
        assert obj.implementation._switch_options == ["grp:alt_shift_toggle"]

    @patch_dbus_publish_object
    def test_populate_missing_keyboard_configuration_with_task(
            self, publisher):
        """Test PopulateMissingKeyboardConfigurationWithTask."""
        self.localization_interface.SetVirtualConsoleKeymap('us')
        self.localization_interface.SetXLayouts(['cz', 'cz (qwerty)'])

        task_path = self.localization_interface.PopulateMissingKeyboardConfigurationWithTask(
        )

        obj = check_task_creation(task_path, publisher,
                                  GetMissingKeyboardConfigurationTask)
        assert obj.implementation._vc_keymap == 'us'
        assert obj.implementation._x_layouts == ['cz', 'cz (qwerty)']

    @patch_dbus_publish_object
    def test_apply_keyboard_with_task(self, publisher):
        """Test ApplyKeyboardWithTask."""
        self.localization_interface.SetVirtualConsoleKeymap('us')
        self.localization_interface.SetXLayouts(['cz', 'cz (qwerty)'])
        self.localization_interface.SetLayoutSwitchOptions(
            ["grp:alt_shift_toggle"])

        task_path = self.localization_interface.ApplyKeyboardWithTask()

        obj = check_task_creation(task_path, publisher, ApplyKeyboardTask)
        assert obj.implementation._vc_keymap == 'us'
        assert obj.implementation._x_layouts == ['cz', 'cz (qwerty)']
        assert obj.implementation._switch_options == ["grp:alt_shift_toggle"]

    def _test_kickstart(self, ks_in, ks_out):
        check_kickstart_interface(self.localization_interface, ks_in, ks_out)

    def test_no_kickstart(self):
        """Test with no kickstart."""
        ks_in = None
        ks_out = ""
        self._test_kickstart(ks_in, ks_out)

    def test_kickstart_empty(self):
        """Test with empty string."""
        ks_in = ""
        ks_out = ""
        self._test_kickstart(ks_in, ks_out)

    def test_lang_kickstart(self):
        """Test the lang command."""
        ks_in = """
        lang cs_CZ.UTF-8
        """
        ks_out = """
        # System language
        lang cs_CZ.UTF-8
        """
        self._test_kickstart(ks_in, ks_out)

    def test_lang_kickstart2(self):
        """Test the lang command with added language support.."""
        ks_in = """
        lang en_US.UTF-8 --addsupport=cs_CZ.UTF-8
        """
        ks_out = """
        # System language
        lang en_US.UTF-8 --addsupport=cs_CZ.UTF-8
        """
        self._test_kickstart(ks_in, ks_out)

    def test_keyboard_kickstart1(self):
        """Test the keyboard command."""
        ks_in = """
        keyboard --vckeymap=us --xlayouts='us','cz (qwerty)'
        """
        ks_out = """
        # Keyboard layouts
        keyboard --vckeymap=us --xlayouts='us','cz (qwerty)'
        """
        self._test_kickstart(ks_in, ks_out)

    def test_keyboard_kickstart2(self):
        """Test the keyboard command."""
        ks_in = """
        keyboard us
        """
        ks_out = """
        # Keyboard layouts
        keyboard --vckeymap=us
        """
        self._test_kickstart(ks_in, ks_out)

    def test_keyboard_kickstart_ignore_generic_keyboard(self):
        """Test that keyboard argument is ignored if there is specific option."""
        ks_in = """
        keyboard --vckeymap cz us
        """
        ks_out = """
        # Keyboard layouts
        keyboard --vckeymap=cz
        """
        self._test_kickstart(ks_in, ks_out)

    @patch("pyanaconda.modules.localization.runtime.conf")
    @patch("pyanaconda.modules.localization.runtime.try_to_load_keymap")
    def test_keyboard_kickstart_keyboard_assign(self, mocked_load_keymap,
                                                mocked_conf):
        """Test the keyboard command assignment to proper setting (running a task with try_to_load_keymap)."""
        mocked_conf.system.can_activate_keyboard = True

        mocked_load_keymap.return_value = True
        ks_in = """
        keyboard us
        """
        ks_out = """
        # Keyboard layouts
        keyboard --vckeymap=us
        """
        self._test_kickstart(ks_in, ks_out)

        mocked_load_keymap.return_value = False
        ks_in = """
        keyboard us
        """
        ks_out = """
        # Keyboard layouts
        keyboard --xlayouts='us'
        """
        self._test_kickstart(ks_in, ks_out)

    def test_keyboard_kickstart3(self):
        """Test the keyboard command."""
        ks_in = """
        keyboard --xlayouts=cz,'cz (qwerty)' --switch=grp:alt_shift_toggle
        """
        ks_out = """
        # Keyboard layouts
        keyboard --xlayouts='cz','cz (qwerty)' --switch='grp:alt_shift_toggle'
        """
        self._test_kickstart(ks_in, ks_out)

    def test_keyboard_kickstart4(self):
        """Test the keyboard command."""
        ks_in = """
        keyboard --xlayouts='cz (qwerty)','en' en
        """
        ks_out = """
        # Keyboard layouts
        keyboard --xlayouts='cz (qwerty)','en'
        """
        self._test_kickstart(ks_in, ks_out)
Esempio n. 2
0
class LocalizationInterfaceTestCase(unittest.TestCase):
    """Test DBus interface for the localization module."""

    def setUp(self):
        """Set up the localization module."""
        # Set up the localization module.
        self.localization_module = LocalizationModule()
        self.localization_interface = LocalizationInterface(self.localization_module)

        # Connect to the properties changed signal.
        self.callback = Mock()
        self.localization_interface.PropertiesChanged.connect(self.callback)

    def kickstart_properties_test(self):
        """Test kickstart properties."""
        self.assertEqual(self.localization_interface.KickstartCommands, ["keyboard", "lang"])
        self.assertEqual(self.localization_interface.KickstartSections, [])
        self.assertEqual(self.localization_interface.KickstartAddons, [])
        self.callback.assert_not_called()

    def language_property_test(self):
        """Test the Language property."""
        self.localization_interface.SetLanguage("cs_CZ.UTF-8")
        self.assertEqual(self.localization_interface.Language, "cs_CZ.UTF-8")
        self.callback.assert_called_once_with(LOCALIZATION.interface_name, {'Language': 'cs_CZ.UTF-8'}, [])

    def language_support_property_test(self):
        """Test the LanguageSupport property."""
        self.localization_interface.SetLanguageSupport(["fr_FR"])
        self.assertEqual(self.localization_interface.LanguageSupport, ["fr_FR"])
        self.callback.assert_called_once_with(LOCALIZATION.interface_name, {'LanguageSupport': ["fr_FR"]}, [])

    def keyboard_property_test(self):
        """Test the Keyboard property."""
        self.localization_interface.SetKeyboard("cz")
        self.assertEqual(self.localization_interface.Keyboard, "cz")
        self.callback.assert_called_once_with(LOCALIZATION.interface_name, {'Keyboard': 'cz'}, [])

    def vc_keymap_property_test(self):
        """Test the VirtualConsoleKeymap property."""
        self.localization_interface.SetVirtualConsoleKeymap("cz")
        self.assertEqual(self.localization_interface.VirtualConsoleKeymap, "cz")
        self.callback.assert_called_once_with(LOCALIZATION.interface_name, {'VirtualConsoleKeymap': 'cz'}, [])

    def x_layouts_property_test(self):
        """Test the XLayouts property."""
        self.localization_interface.SetXLayouts(["en", "cz(querty)"])
        self.assertEqual(self.localization_interface.XLayouts, ["en", "cz(querty)"])
        self.callback.assert_called_once_with(LOCALIZATION.interface_name, {'XLayouts': ["en", "cz(querty)"]}, [])

    def switch_options_property_test(self):
        """Test the LayoutSwitchOptions property."""
        self.localization_interface.SetLayoutSwitchOptions(["grp:alt_shift_toggle"])
        self.assertEqual(self.localization_interface.LayoutSwitchOptions, ["grp:alt_shift_toggle"])
        self.callback.assert_called_once_with(LOCALIZATION.interface_name, {'LayoutSwitchOptions': ["grp:alt_shift_toggle"]}, [])

    def keyboard_seen_test(self):
        """Test the KeyboardKickstarted property."""
        self.assertEqual(self.localization_interface.KeyboardKickstarted, False)
        ks_in = """
        lang cs_CZ.UTF-8
        """
        ks_in = dedent(ks_in).strip()
        self.localization_interface.ReadKickstart(ks_in)
        self.assertEqual(self.localization_interface.KeyboardKickstarted, False)
        ks_in = """
        lang cs_CZ.UTF-8
        keyboard cz
        """
        ks_in = dedent(ks_in).strip()
        self.localization_interface.ReadKickstart(ks_in)
        self.assertEqual(self.localization_interface.KeyboardKickstarted, True)

    def language_seen_test(self):
        """Test the LanguageKickstarted property."""
        self.assertEqual(self.localization_interface.LanguageKickstarted, False)
        ks_in = """
        keyboard cz
        """
        ks_in = dedent(ks_in).strip()
        self.localization_interface.ReadKickstart(ks_in)
        self.assertEqual(self.localization_interface.LanguageKickstarted, False)
        ks_in = """
        keyboard cz
        lang cs_CZ.UTF-8
        """
        ks_in = dedent(ks_in).strip()
        self.localization_interface.ReadKickstart(ks_in)
        self.assertEqual(self.localization_interface.LanguageKickstarted, True)

    def set_language_kickstarted_test(self):
        """Test SetLanguageKickstart."""
        self.localization_interface.SetLanguageKickstarted(True)
        self.assertEqual(self.localization_interface.LanguageKickstarted, True)
        self.callback.assert_called_once_with(LOCALIZATION.interface_name, {'LanguageKickstarted': True}, [])

    @patch('pyanaconda.dbus.DBus.publish_object')
    def install_language_with_task_test(self, publisher):
        """Test InstallLanguageWithTask."""
        self.localization_interface.SetLanguage("cs_CZ.UTF-8")
        task_path = self.localization_interface.InstallWithTasks("/")[0]

        publisher.assert_called_once()
        object_path, obj = publisher.call_args[0]

        self.assertEqual(task_path, object_path)
        self.assertIsInstance(obj, TaskInterface)
        self.assertIsInstance(obj.implementation, LanguageInstallationTask)
        self.assertEqual(obj.implementation._sysroot, "/")
        self.assertEqual(obj.implementation._lang, "cs_CZ.UTF-8")

    def _test_kickstart(self, ks_in, ks_out):
        check_kickstart_interface(self, self.localization_interface, ks_in, ks_out)

    def no_kickstart_test(self):
        """Test with no kickstart."""
        ks_in = None
        ks_out = ""
        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 lang_kickstart_test(self):
        """Test the lang command."""
        ks_in = """
        lang cs_CZ.UTF-8
        """
        ks_out = """
        # System language
        lang cs_CZ.UTF-8
        """
        self._test_kickstart(ks_in, ks_out)

    def lang_kickstart2_test(self):
        """Test the lang command with added language support.."""
        ks_in = """
        lang en_US.UTF-8 --addsupport=cs_CZ.UTF-8
        """
        ks_out = """
        # System language
        lang en_US.UTF-8 --addsupport=cs_CZ.UTF-8
        """
        self._test_kickstart(ks_in, ks_out)

    def keyboard_kickstart1_test(self):
        """Test the keyboard command."""
        ks_in = """
        keyboard --vckeymap=us --xlayouts='us','cz (qwerty)'
        """
        ks_out = """
        # Keyboard layouts
        keyboard --vckeymap=us --xlayouts='us','cz (qwerty)'
        """
        self._test_kickstart(ks_in, ks_out)

    def keyboard_kickstart2_test(self):
        """Test the keyboard command."""
        ks_in = """
        keyboard us
        """
        ks_out = """
        # Keyboard layouts
        keyboard 'us'
        """
        self._test_kickstart(ks_in, ks_out)

    def keyboard_kickstart3_test(self):
        """Test the keyboard command."""
        ks_in = """
        keyboard --xlayouts=cz,'cz (qwerty)' --switch=grp:alt_shift_toggle
        """
        ks_out = """
        # Keyboard layouts
        keyboard --xlayouts='cz','cz (qwerty)' --switch='grp:alt_shift_toggle'
        """
        self._test_kickstart(ks_in, ks_out)

    def keyboard_kickstart4_test(self):
        """Test the keyboard command."""
        ks_in = """
        keyboard --xlayouts='cz (qwerty)','en' en
        """
        ks_out = """
        # Keyboard layouts
        # old format: keyboard en
        # new format:
        keyboard --xlayouts='cz (qwerty)','en'
        """
        self._test_kickstart(ks_in, ks_out)
Esempio n. 3
0
class LocalizationInterfaceTestCase(unittest.TestCase):
    """Test DBus interface for the localization module."""
    def setUp(self):
        """Set up the localization module."""
        # Set up the localization module.
        self.localization_module = LocalizationService()
        self.localization_interface = LocalizationInterface(
            self.localization_module)

        # Connect to the properties changed signal.
        self.callback = PropertiesChangedCallback()
        self.localization_interface.PropertiesChanged.connect(self.callback)

    def kickstart_properties_test(self):
        """Test kickstart properties."""
        self.assertEqual(self.localization_interface.KickstartCommands,
                         ["keyboard", "lang"])
        self.assertEqual(self.localization_interface.KickstartSections, [])
        self.assertEqual(self.localization_interface.KickstartAddons, [])
        self.callback.assert_not_called()

    def language_property_test(self):
        """Test the Language property."""
        self.localization_interface.SetLanguage("cs_CZ.UTF-8")
        self.assertEqual(self.localization_interface.Language, "cs_CZ.UTF-8")
        self.callback.assert_called_once_with(LOCALIZATION.interface_name,
                                              {'Language': 'cs_CZ.UTF-8'}, [])

    def language_support_property_test(self):
        """Test the LanguageSupport property."""
        self.localization_interface.SetLanguageSupport(["fr_FR"])
        self.assertEqual(self.localization_interface.LanguageSupport,
                         ["fr_FR"])
        self.callback.assert_called_once_with(LOCALIZATION.interface_name,
                                              {'LanguageSupport': ["fr_FR"]},
                                              [])

    def vc_keymap_property_test(self):
        """Test the VirtualConsoleKeymap property."""
        self.localization_interface.SetVirtualConsoleKeymap("cz")
        self.assertEqual(self.localization_interface.VirtualConsoleKeymap,
                         "cz")
        self.callback.assert_called_once_with(LOCALIZATION.interface_name,
                                              {'VirtualConsoleKeymap': 'cz'},
                                              [])

    def x_layouts_property_test(self):
        """Test the XLayouts property."""
        self.localization_interface.SetXLayouts(["en", "cz(querty)"])
        self.assertEqual(self.localization_interface.XLayouts,
                         ["en", "cz(querty)"])
        self.callback.assert_called_once_with(
            LOCALIZATION.interface_name, {'XLayouts': ["en", "cz(querty)"]},
            [])

    def switch_options_property_test(self):
        """Test the LayoutSwitchOptions property."""
        self.localization_interface.SetLayoutSwitchOptions(
            ["grp:alt_shift_toggle"])
        self.assertEqual(self.localization_interface.LayoutSwitchOptions,
                         ["grp:alt_shift_toggle"])
        self.callback.assert_called_once_with(
            LOCALIZATION.interface_name,
            {'LayoutSwitchOptions': ["grp:alt_shift_toggle"]}, [])

    def keyboard_seen_test(self):
        """Test the KeyboardKickstarted property."""
        self.assertEqual(self.localization_interface.KeyboardKickstarted,
                         False)
        ks_in = """
        lang cs_CZ.UTF-8
        """
        ks_in = dedent(ks_in).strip()
        self.localization_interface.ReadKickstart(ks_in)
        self.assertEqual(self.localization_interface.KeyboardKickstarted,
                         False)
        ks_in = """
        lang cs_CZ.UTF-8
        keyboard cz
        """
        ks_in = dedent(ks_in).strip()
        self.localization_interface.ReadKickstart(ks_in)
        self.assertEqual(self.localization_interface.KeyboardKickstarted, True)

    def language_seen_test(self):
        """Test the LanguageKickstarted property."""
        self.assertEqual(self.localization_interface.LanguageKickstarted,
                         False)
        ks_in = """
        keyboard cz
        """
        ks_in = dedent(ks_in).strip()
        self.localization_interface.ReadKickstart(ks_in)
        self.assertEqual(self.localization_interface.LanguageKickstarted,
                         False)
        ks_in = """
        keyboard cz
        lang cs_CZ.UTF-8
        """
        ks_in = dedent(ks_in).strip()
        self.localization_interface.ReadKickstart(ks_in)
        self.assertEqual(self.localization_interface.LanguageKickstarted, True)

    def set_language_kickstarted_test(self):
        """Test SetLanguageKickstarted."""
        self.localization_interface.SetLanguageKickstarted(True)
        self.assertEqual(self.localization_interface.LanguageKickstarted, True)
        self.callback.assert_called_once_with(LOCALIZATION.interface_name,
                                              {'LanguageKickstarted': True},
                                              [])

    def set_keyboard_kickstarted_test(self):
        """Test SetLanguageKickstarted."""
        self.localization_interface.SetKeyboardKickstarted(True)
        self.assertEqual(self.localization_interface.KeyboardKickstarted, True)
        self.callback.assert_called_once_with(LOCALIZATION.interface_name,
                                              {'KeyboardKickstarted': True},
                                              [])

    @patch("pyanaconda.modules.localization.runtime.try_to_load_keymap")
    def set_keyboard_test(self, mocked_load_keymap):
        """Test SetKeyboard."""
        # Makes sure VirtualConsoleKeymap setting will be used no matter the
        # conf.system.can_activate_keyboard value is.
        mocked_load_keymap.return_value = True
        self.localization_interface.SetKeyboard("us")
        self.assertEqual(self.localization_interface.VirtualConsoleKeymap,
                         "us")

    @patch_dbus_publish_object
    def install_with_task_test(self, publisher):
        """Test InstallWithTask."""
        self.localization_interface.SetLanguage("cs_CZ.UTF-8")
        self.localization_interface.SetVirtualConsoleKeymap('us')
        self.localization_interface.SetXLayouts(['cz', 'cz (qwerty)'])
        self.localization_interface.SetLayoutSwitchOptions(
            ["grp:alt_shift_toggle"])

        tasks = self.localization_interface.InstallWithTasks()
        language_installation_task_path = tasks[0]
        keyboard_installation_task_path = tasks[1]

        publisher.assert_called()

        object_path = publisher.call_args_list[0][0][0]
        obj = publisher.call_args_list[0][0][1]

        self.assertEqual(language_installation_task_path, object_path)
        self.assertIsInstance(obj, TaskInterface)
        self.assertIsInstance(obj.implementation, LanguageInstallationTask)
        self.assertEqual(obj.implementation._lang, "cs_CZ.UTF-8")

        object_path = publisher.call_args_list[1][0][0]
        obj = publisher.call_args_list[1][0][1]

        self.assertEqual(keyboard_installation_task_path, object_path)
        self.assertIsInstance(obj, TaskInterface)
        self.assertIsInstance(obj.implementation, KeyboardInstallationTask)
        self.assertEqual(obj.implementation._x_layouts, ['cz', 'cz (qwerty)'])
        self.assertEqual(obj.implementation._vc_keymap, 'us')
        self.assertEqual(obj.implementation._switch_options,
                         ["grp:alt_shift_toggle"])

    @patch_dbus_publish_object
    def populate_missing_keyboard_configuration_with_task_test(
            self, publisher):
        """Test PopulateMissingKeyboardConfigurationWithTask."""
        self.localization_interface.SetVirtualConsoleKeymap('us')
        self.localization_interface.SetXLayouts(['cz', 'cz (qwerty)'])

        task_path = self.localization_interface.PopulateMissingKeyboardConfigurationWithTask(
        )

        obj = check_task_creation(self, task_path, publisher,
                                  GetMissingKeyboardConfigurationTask)
        self.assertEqual(obj.implementation._vc_keymap, 'us')
        self.assertEqual(obj.implementation._x_layouts, ['cz', 'cz (qwerty)'])

    @patch_dbus_publish_object
    def apply_keyboard_with_task_test(self, publisher):
        """Test ApplyKeyboardWithTask."""
        self.localization_interface.SetVirtualConsoleKeymap('us')
        self.localization_interface.SetXLayouts(['cz', 'cz (qwerty)'])
        self.localization_interface.SetLayoutSwitchOptions(
            ["grp:alt_shift_toggle"])

        task_path = self.localization_interface.ApplyKeyboardWithTask()

        obj = check_task_creation(self, task_path, publisher,
                                  ApplyKeyboardTask)
        self.assertEqual(obj.implementation._vc_keymap, 'us')
        self.assertEqual(obj.implementation._x_layouts, ['cz', 'cz (qwerty)'])
        self.assertEqual(obj.implementation._switch_options,
                         ["grp:alt_shift_toggle"])

    def _test_kickstart(self, ks_in, ks_out):
        check_kickstart_interface(self, self.localization_interface, ks_in,
                                  ks_out)

    def no_kickstart_test(self):
        """Test with no kickstart."""
        ks_in = None
        ks_out = ""
        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 lang_kickstart_test(self):
        """Test the lang command."""
        ks_in = """
        lang cs_CZ.UTF-8
        """
        ks_out = """
        # System language
        lang cs_CZ.UTF-8
        """
        self._test_kickstart(ks_in, ks_out)

    def lang_kickstart2_test(self):
        """Test the lang command with added language support.."""
        ks_in = """
        lang en_US.UTF-8 --addsupport=cs_CZ.UTF-8
        """
        ks_out = """
        # System language
        lang en_US.UTF-8 --addsupport=cs_CZ.UTF-8
        """
        self._test_kickstart(ks_in, ks_out)

    def keyboard_kickstart1_test(self):
        """Test the keyboard command."""
        ks_in = """
        keyboard --vckeymap=us --xlayouts='us','cz (qwerty)'
        """
        ks_out = """
        # Keyboard layouts
        keyboard --vckeymap=us --xlayouts='us','cz (qwerty)'
        """
        self._test_kickstart(ks_in, ks_out)

    def keyboard_kickstart2_test(self):
        """Test the keyboard command."""
        ks_in = """
        keyboard us
        """
        ks_out = """
        # Keyboard layouts
        keyboard --vckeymap=us
        """
        self._test_kickstart(ks_in, ks_out)

    def keyboard_kickstart_ignore_generic_keyboard_test(self):
        """Test that keyboard argument is ignored if there is specific option."""
        ks_in = """
        keyboard --vckeymap cz us
        """
        ks_out = """
        # Keyboard layouts
        keyboard --vckeymap=cz
        """
        self._test_kickstart(ks_in, ks_out)

    @patch("pyanaconda.modules.localization.runtime.conf")
    @patch("pyanaconda.modules.localization.runtime.try_to_load_keymap")
    def keyboard_kickstart_keyboard_assign_test(self, mocked_load_keymap,
                                                mocked_conf):
        """Test the keyboard command assignment to proper setting (running a task with try_to_load_keymap)."""
        mocked_conf.system.can_activate_keyboard = True

        mocked_load_keymap.return_value = True
        ks_in = """
        keyboard us
        """
        ks_out = """
        # Keyboard layouts
        keyboard --vckeymap=us
        """
        self._test_kickstart(ks_in, ks_out)

        mocked_load_keymap.return_value = False
        ks_in = """
        keyboard us
        """
        ks_out = """
        # Keyboard layouts
        keyboard --xlayouts='us'
        """
        self._test_kickstart(ks_in, ks_out)

    def keyboard_kickstart3_test(self):
        """Test the keyboard command."""
        ks_in = """
        keyboard --xlayouts=cz,'cz (qwerty)' --switch=grp:alt_shift_toggle
        """
        ks_out = """
        # Keyboard layouts
        keyboard --xlayouts='cz','cz (qwerty)' --switch='grp:alt_shift_toggle'
        """
        self._test_kickstart(ks_in, ks_out)

    def keyboard_kickstart4_test(self):
        """Test the keyboard command."""
        ks_in = """
        keyboard --xlayouts='cz (qwerty)','en' en
        """
        ks_out = """
        # Keyboard layouts
        keyboard --xlayouts='cz (qwerty)','en'
        """
        self._test_kickstart(ks_in, ks_out)