Esempio n. 1
0
class DiskInitializationModuleTestCase(unittest.TestCase):
    """Test the disk initialization module."""

    def setUp(self):
        """Set up the module."""
        self.disk_init_module = DiskInitializationModule()

    def storage_property_test(self):
        """Test the storage property."""
        with self.assertRaises(UnavailableStorageError):
            self.assertIsNotNone(self.disk_init_module.storage)

        storage = Mock()
        self.disk_init_module.on_storage_changed(storage)
        self.assertEqual(self.disk_init_module.storage, storage)

    def setup_kickstart_test(self):
        """Test setup_kickstart with storage."""
        storage = create_storage()
        data = Mock()

        self.disk_init_module.on_storage_changed(storage)
        self.disk_init_module.set_initialization_mode(InitializationMode.CLEAR_NONE)
        self.disk_init_module.setup_kickstart(data)

        self.assertEqual(data.clearpart.type, CLEARPART_TYPE_NONE)
        self.assertEqual(data.clearpart.devices, [])
        self.assertEqual(data.clearpart.drives, [])
Esempio n. 2
0
class DiskInitializationModuleTestCase(unittest.TestCase):
    """Test the disk initialization module."""
    def setUp(self):
        """Set up the module."""
        self.disk_init_module = DiskInitializationModule()

    def test_storage_property(self):
        """Test the storage property."""
        with pytest.raises(UnavailableStorageError):
            assert self.disk_init_module.storage is not None

        storage = Mock()
        self.disk_init_module.on_storage_changed(storage)
        assert self.disk_init_module.storage == storage

    def test_setup_kickstart(self):
        """Test setup_kickstart with storage."""
        storage = create_storage()
        data = Mock()

        self.disk_init_module.on_storage_changed(storage)
        self.disk_init_module.set_initialization_mode(
            InitializationMode.CLEAR_NONE)
        self.disk_init_module.setup_kickstart(data)

        assert data.clearpart.type == CLEARPART_TYPE_NONE
        assert data.clearpart.devices == []
        assert data.clearpart.drives == []
Esempio n. 3
0
class DiskInitializationModuleTestCase(unittest.TestCase):
    """Test the disk initialization module."""

    def setUp(self):
        """Set up the module."""
        self.disk_init_module = DiskInitializationModule()

    def storage_property_test(self):
        """Test the storage property."""
        with self.assertRaises(UnavailableStorageError):
            self.assertIsNotNone(self.disk_init_module.storage)

        storage = Mock()
        self.disk_init_module.on_storage_reset(storage)
        self.assertEqual(self.disk_init_module.storage, storage)

    def setup_kickstart_test(self):
        """Test setup_kickstart with storage."""
        storage = create_storage()
        data = Mock()

        self.disk_init_module.on_storage_reset(storage)
        self.disk_init_module.set_initialization_mode(InitializationMode.CLEAR_NONE)
        self.disk_init_module.setup_kickstart(data)

        self.assertEqual(data.clearpart.type, CLEARPART_TYPE_NONE)
        self.assertEqual(data.clearpart.devices, [])
        self.assertEqual(data.clearpart.drives, [])
Esempio n. 4
0
class DiskInitializationInterfaceTestCase(unittest.TestCase):
    """Test DBus interface of the disk initialization module."""

    def setUp(self):
        """Set up the module."""
        self.disk_init_module = DiskInitializationModule()
        self.disk_init_interface = DiskInitializationInterface(self.disk_init_module)

    def on_partitioning_changed_test(self):
        """Smoke test for on_partitioning_changed callback."""
        mode_changed_callback = Mock()
        devices_changed_callback = Mock()
        drives_changed_callback = Mock()

        self.disk_init_module.set_initialization_mode(InitializationMode.CLEAR_NONE)
        self.disk_init_module.initialization_mode_changed.connect(mode_changed_callback)
        self.disk_init_module.devices_to_clear_changed.connect(devices_changed_callback)
        self.disk_init_module.drives_to_clear_changed.connect(drives_changed_callback)
        self.disk_init_module.on_partitioning_changed(create_storage())

        mode_changed_callback.called_once_with(InitializationMode.CLEAR_NONE)
        drives_changed_callback.called_once_with([])
        devices_changed_callback.called_once_with([])

    def _test_dbus_property(self, *args, **kwargs):
        check_dbus_property(
            self,
            DISK_INITIALIZATION,
            self.disk_init_interface,
            *args, **kwargs
        )

    def default_disk_label_property_test(self):
        """Test the default disk label property."""
        self._test_dbus_property(
            "DefaultDiskLabel",
            "msdos"
        )

    def format_unrecognized_enabled_property_test(self):
        """Test the can format unrecognized property."""
        self._test_dbus_property(
            "FormatUnrecognizedEnabled",
            False
        )

    def can_initialize_label_property_test(self):
        """Test the can initialize label property."""
        self._test_dbus_property(
            "InitializeLabelsEnabled",
            False
        )

    def format_ldl_enabled_property_test(self):
        """Test the can format LDL property."""
        self._test_dbus_property(
            "FormatLDLEnabled",
            True
        )

    def initialization_mode_property_test(self):
        """Test the type to clear property."""
        self._test_dbus_property(
            "InitializationMode",
            CLEAR_PARTITIONS_LINUX
        )

    def devices_to_clear_property_test(self):
        """Test the devices to clear property."""
        self._test_dbus_property(
            "DevicesToClear",
            ["sda2", "sda3", "sdb1"]
        )

    def drives_to_clear_property_test(self):
        """Test the drives to clear property."""
        self._test_dbus_property(
            "DrivesToClear",
            ["sda", "sdb"]
        )