Пример #1
0
    def test_mdraid_validation(self):
        parent_device = Mock(type="disk",
                             format=Mock(label_type="gpt",
                                         extended_partition=None))
        free_device = Mock(is_logical=False, size=Size("8 GiB"))

        advanced_options = AdvancedOptions(add_dialog=self.add_dialog,
                                           device_type="mdraid",
                                           parent_device=parent_device,
                                           free_device=free_device)

        entry = advanced_options.chunk_combo.get_child()

        # invalid size specification
        entry.set_text("aaaaaaa")
        advanced_options.validate_user_input()
        self.error_dialog.assert_any_call(
            self.add_dialog,
            _("'{0}' is not a valid chunk size specification.").format(
                "aaaaaaa"), not self.add_dialog.installer_mode)
        self.error_dialog.reset_mock()

        # invalid size
        entry.set_text("1 KiB")
        advanced_options.validate_user_input()
        self.error_dialog.assert_any_call(
            self.add_dialog, _("Chunk size must be multiple of 4 KiB."),
            not self.add_dialog.installer_mode)
        self.error_dialog.reset_mock()

        # valid size
        entry.set_text("64 KiB")
        advanced_options.validate_user_input()
        self.assertFalse(self.error_dialog.called)
        self.error_dialog.reset_mock()
Пример #2
0
    def test_encrypt_validity_check(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device, [("free", free_device)], [])

        # passphrases specified and matches
        add_dialog.encrypt_check.set_active(True)
        add_dialog.pass_entry.set_text("aaaaa")
        add_dialog.pass2_entry.set_text("aaaaa")
        add_dialog.validate_user_input()
        self.assertFalse(self.error_dialog.called)  # passphrases specified and matches --> no error
        self.error_dialog.reset_mock()

        # passphrases specified but don't matche
        add_dialog.encrypt_check.set_active(True)
        add_dialog.pass_entry.set_text("aaaaa")
        add_dialog.pass2_entry.set_text("bbbb")
        add_dialog.validate_user_input()
        self.error_dialog.assert_any_call(add_dialog, _("Provided passphrases do not match."), True)
        self.error_dialog.reset_mock()

        # no passphrase specified
        add_dialog.encrypt_check.set_active(True)
        add_dialog.pass_entry.set_text("")
        add_dialog.validate_user_input()
        self.error_dialog.assert_any_call(add_dialog, _("Passphrase not specified."), True)
        self.error_dialog.reset_mock()
Пример #3
0
    def test_mountpoint_validity_check(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device, [("free", free_device)], ["/root"], True)

        # reset mock
        self.error_dialog.reset_mock()

        # valid mountpoint
        add_dialog.mountpoint_entry.set_text("/home")
        add_dialog.validate_user_input()
        self.assertFalse(self.error_dialog.called)  # passphrase specified --> no error
        self.error_dialog.reset_mock()

        # invalid mountpoint
        mnt = "home"
        add_dialog.mountpoint_entry.set_text(mnt)
        add_dialog.validate_user_input()
        self.error_dialog.assert_any_call(add_dialog, _('"{0}" is not a valid mountpoint.').format(mnt), False)
        self.error_dialog.reset_mock()

        # duplicate mountpoint
        mnt = "/root"
        add_dialog.mountpoint_entry.set_text(mnt)
        add_dialog.validate_user_input()
        self.error_dialog.assert_any_call(
            add_dialog, _('Selected mountpoint "{0}" is already set for another device.').format(mnt), False
        )
        self.error_dialog.reset_mock()
Пример #4
0
    def test_mountpoint_validity_check(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, "disk", parent_device, free_device, [],
                               [free_device], self.supported_raids, self.supported_fs, ["/root"], True)

        # valid mountpoint
        add_dialog.mountpoint_entry.set_text("/home")
        add_dialog.validate_user_input()
        self.assertFalse(self.error_dialog.called)  # passphrase specified --> no error
        self.error_dialog.reset_mock()

        # invalid mountpoint
        mnt = "home"
        add_dialog.mountpoint_entry.set_text(mnt)
        add_dialog.validate_user_input()
        self.error_dialog.assert_any_call(add_dialog, _("\"{0}\" is not a valid mountpoint.").format(mnt))
        self.error_dialog.reset_mock()

        # duplicate mountpoint
        mnt = "/root"
        add_dialog.mountpoint_entry.set_text(mnt)
        add_dialog.validate_user_input()
        self.error_dialog.assert_any_call(add_dialog, _("Selected mountpoint \"{0}\" is already set for another device.").format(mnt))
        self.error_dialog.reset_mock()
Пример #5
0
    def test_mdraid_validation(self):
        parent_device = Mock(type="disk", format=Mock(label_type="gpt", extended_partition=None))
        free_device = Mock(is_logical=False, size=Size("8 GiB"))

        advanced_options = AdvancedOptions(
            add_dialog=self.add_dialog, device_type="mdraid", parent_device=parent_device, free_device=free_device
        )

        entry = advanced_options.chunk_combo.get_child()

        # invalid size specification
        entry.set_text("aaaaaaa")
        advanced_options.validate_user_input()
        self.error_dialog.assert_any_call(
            self.add_dialog, _("'aaaaaaa' is not a valid chunk size specification."), not self.add_dialog.installer_mode
        )
        self.error_dialog.reset_mock()

        # invalid size
        entry.set_text("1 KiB")
        advanced_options.validate_user_input()
        self.error_dialog.assert_any_call(
            self.add_dialog, _("Chunk size must be multiple of 4 KiB."), not self.add_dialog.installer_mode
        )
        self.error_dialog.reset_mock()

        # valid size
        entry.set_text("64 KiB")
        advanced_options.validate_user_input()
        self.assertFalse(self.error_dialog.called)
        self.error_dialog.reset_mock()
Пример #6
0
    def test_encrypt_validity_check(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device,
                               [("free", free_device)],
                               self.supported_filesystems, [])

        # passphrases specified and matches
        add_dialog.encrypt_check.set_active(True)
        add_dialog.pass_entry.set_text("aaaaa")
        add_dialog.pass2_entry.set_text("aaaaa")
        add_dialog.validate_user_input()
        self.assertFalse(self.error_dialog.called
                         )  # passphrases specified and matches --> no error
        self.error_dialog.reset_mock()

        # passphrases specified but don't matche
        add_dialog.encrypt_check.set_active(True)
        add_dialog.pass_entry.set_text("aaaaa")
        add_dialog.pass2_entry.set_text("bbbb")
        add_dialog.validate_user_input()
        self.error_dialog.assert_any_call(
            add_dialog, _("Provided passphrases do not match."), True)
        self.error_dialog.reset_mock()

        # no passphrase specified
        add_dialog.encrypt_check.set_active(True)
        add_dialog.pass_entry.set_text("")
        add_dialog.validate_user_input()
        self.error_dialog.assert_any_call(add_dialog,
                                          _("Passphrase not specified."), True)
        self.error_dialog.reset_mock()
Пример #7
0
    def test_label_validity_check(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device,
                               [("free", free_device)],
                               self.supported_filesystems, [])

        add_dialog.devices_combo.set_active_id(
            "partition")  # select device type that has a label option
        add_dialog.filesystems_combo.set_active_id("ext4")

        # valid label for ext4
        label = "a" * 5
        add_dialog.label_entry.set_text(label)
        add_dialog.validate_user_input()
        self.assertFalse(
            self.error_dialog.called)  # passphrase specified --> no error
        self.error_dialog.reset_mock()

        # invalid label for ext4
        label = "a" * 50
        add_dialog.label_entry.set_text(label)
        add_dialog.validate_user_input()
        self.error_dialog.assert_any_call(
            add_dialog,
            _("\"{0}\" is not a valid label.").format(label), True)
        self.error_dialog.reset_mock()
Пример #8
0
    def test_name_validity_check(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device,
                               [("free", free_device)],
                               self.supported_filesystems, [])

        add_dialog.devices_combo.set_active_id(
            "lvm")  # select device type that has a name option

        # valid name
        name = "aaaaa"
        add_dialog.name_entry.set_text(name)
        add_dialog.validate_user_input()
        self.assertFalse(
            self.error_dialog.called)  # passphrase specified --> no error
        self.error_dialog.reset_mock()

        # invalid name
        name = "?*#%@"
        add_dialog.name_entry.set_text(name)
        add_dialog.validate_user_input()
        self.error_dialog.assert_any_call(
            add_dialog,
            _("\"{0}\" is not a valid name.").format(name), True)
        self.error_dialog.reset_mock()
Пример #9
0
    def test_mountpoint_validity_check(self):
        dialog = PartitionEditDialog(self.parent_window, self.edited_device, self.resize_info, self.supported_fs, ["/root", "/var"], True)

        # valid mountpoint
        dialog.mountpoint_entry.set_text("/home")
        dialog.validate_user_input()
        self.assertFalse(self.error_dialog.called)
        self.error_dialog.reset_mock()

        # invalid mountpoint
        mnt = "home"
        dialog.mountpoint_entry.set_text(mnt)
        dialog.validate_user_input()
        self.error_dialog.assert_any_call(dialog, _("\"{0}\" is not a valid mountpoint.").format(mnt))
        self.error_dialog.reset_mock()

        # duplicate mountpoint
        mnt = "/root"
        dialog.mountpoint_entry.set_text(mnt)
        dialog.validate_user_input()
        self.error_dialog.assert_any_call(dialog, "Selected mountpoint \"%s\" is already set for another device." % mnt)
        self.error_dialog.reset_mock()

        # same mountpoint
        self.edited_device.format.configure_mock(mountpoint="/var")
        dialog.mountpoint_entry.set_text("/var")
        dialog.validate_user_input()
        self.assertFalse(self.error_dialog.called)  # no change --> no error
        self.error_dialog.reset_mock()
        self.edited_device.format.configure_mock(mountpoint="")
Пример #10
0
    def test_installer(self):
        dev = MagicMock(size=Size("1 GiB"), format=MagicMock(mountpoint=None))

        dialog = FormatDialog(self.parent_window, dev, self.supported_filesystems, [], True)

        # ninstaller_mode, mountpoint widgets should be visible
        self.assertTrue(dialog.mnt_entry.get_visible())

        # test mountpoint entry sensitivity (insensitive for not mountable) and selection
        fstype = next((fs.type for fs in supported_filesystems() if fs.mountable), None)
        if fstype:
            dialog.fs_combo.set_active_id(fstype)
            dialog.mnt_entry.set_text("/boot")

            selected_fs, _selected_label, selected_mnt = dialog.get_selection()
            self.assertTrue(dialog.mnt_entry.get_sensitive())
            self.assertEqual(selected_fs, fstype)
            self.assertEqual(selected_mnt, "/boot")

        # test 'unformatted' selection (can't set mountpoint for "none" format)
        dialog.fs_combo.set_active_id("unformatted")
        selected_fs, _selected_label, selected_mnt = dialog.get_selection()
        self.assertFalse(dialog.mnt_entry.get_sensitive())

        # test mountpoint validation
        fstype = next((fs.type for fs in supported_filesystems() if fs.mountable), None)
        if fstype:
            dialog.fs_combo.set_active_id(fstype)
            dialog.mnt_entry.set_text("aaaaa")
            dialog.validate_user_input()
            self.error_dialog.assert_any_call(dialog.dialog,
                                              _("\"{0}\" is not a valid mountpoint.").format("aaaaa"),
                                              False)
Пример #11
0
    def test_pop(self):
        action1 = MagicMock()
        self.actions_list.append(action_type="add",
                                 action_desc="add",
                                 blivet_actions=[action1])
        action2 = MagicMock()
        self.actions_list.append(action_type="add",
                                 action_desc="add",
                                 blivet_actions=[action2])

        # pop action2 from the list
        pop = self.actions_list.pop()
        self.assertEqual(pop, [action2])
        self.assertEqual(self.actions_list.actions, 1)
        self.assertEqual(len(self.actions_list.history), 1)
        self.assertTrue(
            [action1]
            in self.actions_list.history)  # action1 should stay there
        self.assertFalse([action2]
                         in self.actions_list.history)  # action2 shouldn't
        self.assertTrue(self.buttons_state)
        self.assertIn(
            P_("%s pending action", "%s pending actions", 1) % 1,
            self.actions_label)

        # pop action1 from the list
        pop = self.actions_list.pop()
        self.assertEqual(pop, [action1])
        self.assertEqual(self.actions_list.actions, 0)
        self.assertEqual(len(self.actions_list.history), 0)
        self.assertFalse(self.buttons_state)
        self.assertIn(_("No pending actions"), self.actions_label)
Пример #12
0
    def test_installer(self):
        dev = MagicMock(size=Size("1 GiB"), format=MagicMock(mountpoint=None))

        dialog = FormatDialog(self.parent_window, dev, self.supported_filesystems, [], True)

        # ninstaller_mode, mountpoint widgets should be visible
        self.assertTrue(dialog.mnt_entry.get_visible())

        # test mountpoint entry sensitivity (insensitive for not mountable) and selection
        fstype = next((fs.type for fs in supported_filesystems() if fs.mountable), None)
        if fstype:
            dialog.fs_combo.set_active_id(fstype)
            dialog.mnt_entry.set_text("/boot")

            selected_fs, _selected_label, selected_mnt = dialog.get_selection()
            self.assertTrue(dialog.mnt_entry.get_sensitive())
            self.assertEqual(selected_fs, fstype)
            self.assertEqual(selected_mnt, "/boot")

        # test 'unformatted' selection (can't set mountpoint for "none" format)
        dialog.fs_combo.set_active_id("unformatted")
        selected_fs, _selected_label, selected_mnt = dialog.get_selection()
        self.assertFalse(dialog.mnt_entry.get_sensitive())

        # test mountpoint validation
        fstype = next((fs.type for fs in supported_filesystems() if fs.mountable), None)
        if fstype:
            dialog.fs_combo.set_active_id(fstype)
            dialog.mnt_entry.set_text("aaaaa")
            dialog.validate_user_input()
            self.error_dialog.assert_any_call(dialog.dialog,
                                              _("\"{0}\" is not a valid mountpoint.").format("aaaaa"),
                                              False)
Пример #13
0
    def test_clear(self):
        action1 = MagicMock()
        self.actions_list.append(action_type="add",
                                 action_desc="add",
                                 blivet_actions=[action1])

        self.actions_list.clear()
        self.assertEqual(self.actions_list.actions, 0)
        self.assertEqual(len(self.actions_list.history), 0)
        self.assertFalse(self.buttons_state)
        self.assertIn(_("No pending actions"), self.actions_label)
Пример #14
0
    def test_mountpoint_validity_check(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device,
                               [("free", free_device)],
                               self.supported_filesystems, ["/root"], True)

        # reset mock
        self.error_dialog.reset_mock()

        # valid mountpoint
        add_dialog.mountpoint_entry.set_text("/home")
        add_dialog.validate_user_input()
        self.assertFalse(
            self.error_dialog.called)  # passphrase specified --> no error
        self.error_dialog.reset_mock()

        # invalid mountpoint
        mnt = "home"
        add_dialog.mountpoint_entry.set_text(mnt)
        add_dialog.validate_user_input()
        self.error_dialog.assert_any_call(
            add_dialog,
            _("\"{0}\" is not a valid mountpoint.").format(mnt), False)
        self.error_dialog.reset_mock()

        # duplicate mountpoint
        mnt = "/root"
        add_dialog.mountpoint_entry.set_text(mnt)
        add_dialog.validate_user_input()
        self.error_dialog.assert_any_call(
            add_dialog,
            _("Selected mountpoint \"{0}\" is already set for another device."
              ).format(mnt), False)
        self.error_dialog.reset_mock()
Пример #15
0
    def test_free_type2(self):
        # disk region --> free type chooser should be added and insensitive
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device, size=Size("8 GiB"), is_free_region=True)

        add_dialog = AddDialog(self.parent_window, "disk", parent_device, free_device, [], [free_device],
                               self.supported_raids, self.supported_fs, [])

        add_dialog.devices_combo.set_active_id("btrfs volume")

        self.assertIsNotNone(add_dialog.free_type_chooser)
        self.assertFalse(all(widget.get_sensitive() for widget in add_dialog.free_type_chooser))

        # partitions should be selected by default and size chooser should be sensitive
        self.assertEqual(add_dialog.free_type_chooser[2].get_label(), _("Partitions"))  # just to make sure we are testing right button
        self.assertTrue(add_dialog.free_type_chooser[2].get_active())
        self.assertTrue(add_dialog.size_areas[0][0].get_sensitive())
Пример #16
0
    def test_name_validity_check(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device, [("free", free_device)], [])

        add_dialog.devices_combo.set_active_id("lvm")  # select device type that has a name option

        # valid name
        name = "aaaaa"
        add_dialog.name_entry.set_text(name)
        add_dialog.validate_user_input()
        self.assertFalse(self.error_dialog.called)  # passphrase specified --> no error
        self.error_dialog.reset_mock()

        # invalid name
        name = "?*#%@"
        add_dialog.name_entry.set_text(name)
        add_dialog.validate_user_input()
        self.error_dialog.assert_any_call(add_dialog, _('"{0}" is not a valid name.').format(name), True)
        self.error_dialog.reset_mock()
Пример #17
0
    def test_label_validity_check(self):
        parent_device = self._get_parent_device()
        free_device = self._get_free_device(parent=parent_device)

        add_dialog = AddDialog(self.parent_window, parent_device, free_device, [("free", free_device)], [])

        add_dialog.devices_combo.set_active_id("partition")  # select device type that has a label option
        add_dialog.filesystems_combo.set_active_id("ext4")

        # valid label for ext4
        label = "a" * 5
        add_dialog.label_entry.set_text(label)
        add_dialog.validate_user_input()
        self.assertFalse(self.error_dialog.called)  # passphrase specified --> no error
        self.error_dialog.reset_mock()

        # invalid label for ext4
        label = "a" * 50
        add_dialog.label_entry.set_text(label)
        add_dialog.validate_user_input()
        self.error_dialog.assert_any_call(add_dialog, _('"{0}" is not a valid label.').format(label), True)
        self.error_dialog.reset_mock()
Пример #18
0
    def test_label_validity_check(self):
        dialog = PartitionEditDialog(self.parent_window, self.edited_device, self.resize_info, self.supported_fs, [], True)

        # valid label
        label = "a" * 5
        dialog.format_check.set_active(True)
        dialog.filesystems_combo.set_active_id("ext4")
        dialog.fslabel_entry.set_text(label)

        dialog.validate_user_input()
        self.assertFalse(self.error_dialog.called)  # valid label, no error_dialog
        self.error_dialog.reset_mock()

        # invalid label for ext4 (too long)
        label = "a" * 50
        dialog.format_check.set_active(True)
        dialog.filesystems_combo.set_active_id("ext4")
        dialog.fslabel_entry.set_text(label)

        dialog.validate_user_input()
        self.error_dialog.assert_any_call(dialog, _("\"{label}\" is not a valid label.").format(label=label))
        self.error_dialog.reset_mock()
Пример #19
0
    def test_resizable(self):
        with patch("blivetgui.blivet_utils.BlivetUtils.blivet_reset",
                   lambda _: True):
            storage = BlivetUtils()
        device = MagicMock(type="",
                           size=Size("1 GiB"),
                           protected=False,
                           format_immutable=False,
                           children=[])
        device.format = MagicMock(exists=True, system_mountpoint=None)
        device.format.return_value = None

        # swap is not resizable
        device.format.configure_mock(type="swap")
        res = storage.device_resizable(device)
        self.assertFalse(res.resizable)
        self.assertEqual(
            res.error, _("Resizing of swap format is currently not supported"))
        self.assertEqual(res.min_size, Size("1 MiB"))
        self.assertEqual(res.max_size, Size("1 GiB"))

        # mounted devices are not resizable
        device.format.configure_mock(type="ext4", system_mountpoint="/")
        res = storage.device_resizable(device)
        self.assertFalse(res.resizable)
        self.assertEqual(res.error, _("Mounted devices cannot be resized"))
        self.assertEqual(res.min_size, Size("1 MiB"))
        self.assertEqual(res.max_size, Size("1 GiB"))

        # resizable device
        device.configure_mock(resizable=True,
                              max_size=Size("2 GiB"),
                              min_size=Size("500 MiB"))
        device.format.configure_mock(resizable=True,
                                     type="ext4",
                                     system_mountpoint=None)
        res = storage.device_resizable(device)
        self.assertTrue(res.resizable)
        self.assertIsNone(res.error)
        self.assertEqual(res.min_size, Size("500 MiB"))
        self.assertEqual(res.max_size, Size("2 GiB"))

        # resizable device and non-resizable format
        device.configure_mock(resizable=True,
                              max_size=Size("2 GiB"),
                              min_size=Size("500 MiB"))
        device.format.configure_mock(resizable=False, type="ext4")
        res = storage.device_resizable(device)
        self.assertFalse(res.resizable)
        self.assertIsNone(res.error)
        self.assertEqual(res.min_size, Size("1 MiB"))
        self.assertEqual(res.max_size, Size("1 GiB"))

        # LV with snapshot -> not resizable
        with patch("blivetgui.blivet_utils.BlivetUtils._has_snapshots",
                   lambda _, device: True):
            device.configure_mock(type="lvmlv",
                                  resizable=True,
                                  max_size=Size("2 GiB"),
                                  min_size=Size("500 MiB"))
            device.format.configure_mock(resizable=True, type="ext4")
            res = storage.device_resizable(device)
            self.assertFalse(res.resizable)
            self.assertIsNotNone(res.error)
            self.assertEqual(res.min_size, Size("1 MiB"))
            self.assertEqual(res.max_size, Size("1 GiB"))
Пример #20
0
 def test_initial_state(self):
     self.assertFalse(self.buttons_state)
     self.assertIn(_("No pending actions"), self.actions_label)
     self.assertEqual(self.actions_list.actions, 0)
     self.assertEqual(len(self.actions_list.history), 0)