def create_partitioning(method: PartitioningMethod): """Create a partitioning module. :param method: a partitioning method :return: a partitioning module """ if method is PartitioningMethod.AUTOMATIC: from pyanaconda.modules.storage.partitioning.automatic.automatic_module import \ AutoPartitioningModule return AutoPartitioningModule() if method is PartitioningMethod.MANUAL: from pyanaconda.modules.storage.partitioning.manual.manual_module import \ ManualPartitioningModule return ManualPartitioningModule() if method is PartitioningMethod.CUSTOM: from pyanaconda.modules.storage.partitioning.custom.custom_module import \ CustomPartitioningModule return CustomPartitioningModule() if method is PartitioningMethod.INTERACTIVE: from pyanaconda.modules.storage.partitioning.interactive.interactive_module import \ InteractivePartitioningModule return InteractivePartitioningModule() if method is PartitioningMethod.BLIVET: from pyanaconda.modules.storage.partitioning.blivet.blivet_module import \ BlivetPartitioningModule return BlivetPartitioningModule() raise ValueError("Unknown partitioning method: {}".format(method))
def setUp(self): """Set up the module.""" self.module = BlivetPartitioningModule() self.interface = BlivetPartitioningInterface(self.module)
class BlivetPartitioningInterfaceTestCase(unittest.TestCase): """Test DBus interface of the Blivet partitioning module.""" def setUp(self): """Set up the module.""" self.module = BlivetPartitioningModule() self.interface = BlivetPartitioningInterface(self.module) @patch.dict('sys.modules') def unsupported_partitioning_test(self): """Test the UnsupportedPartitioningError.""" # Forget imported modules from pyanaconda and blivetgui. for name in list(sys.modules): if name.startswith('pyanaconda') or name.startswith('blivetgui'): sys.modules.pop(name) # Disable the blivetgui package. sys.modules['blivetgui'] = None # Import the StorageModule again. from pyanaconda.modules.storage.storage import StorageService # We should be able to create the Storage module storage_module = StorageService() self.assertIsNotNone(storage_module.storage) # We should be able to create the Blivet module. from pyanaconda.modules.storage.partitioning.constants import PartitioningMethod blivet_module = storage_module.create_partitioning( PartitioningMethod.BLIVET) self.assertIsNotNone(blivet_module.storage) # Import the exception again. from pyanaconda.modules.common.errors.storage import UnsupportedPartitioningError # Handle the missing support. with self.assertRaises(UnsupportedPartitioningError): self.assertFalse(blivet_module.storage_handler) with self.assertRaises(UnsupportedPartitioningError): self.assertFalse(blivet_module.request_handler) with self.assertRaises(UnsupportedPartitioningError): request = pickle.dumps(("call", "get_disks", [])) blivet_module.send_request(request) def storage_handler_test(self): """Test the storage_handler property.""" self.module.on_storage_changed(Mock()) self.assertIsNotNone(self.module.storage_handler) self.assertEqual(self.module.storage, self.module.storage_handler.storage) def request_handler_test(self): """Test the request_handler property.""" self.module.on_storage_changed(Mock()) self.assertIsNotNone(self.module.request_handler) self.assertEqual(self.module.storage_handler, self.module.request_handler.blivet_utils) def send_request_test(self): """Test SendRequest.""" self.module.on_storage_changed(Mock()) request = pickle.dumps(("call", "get_disks", [])) answer = self.interface.SendRequest(request) answer = pickle.loads(answer) self.assertIsInstance(answer, ProxyID) self.assertEqual(answer.id, 0) @patch_dbus_publish_object def configure_with_task_test(self, publisher): """Test ConfigureWithTask.""" self.module.on_storage_changed(Mock()) task_path = self.interface.ConfigureWithTask() obj = check_task_creation(self, task_path, publisher, InteractivePartitioningTask) self.assertEqual(obj.implementation._storage, self.module.storage)
class BlivetPartitioningInterfaceTestCase(unittest.TestCase): """Test DBus interface of the Blivet partitioning module.""" def setUp(self): """Set up the module.""" self.module = BlivetPartitioningModule() self.interface = BlivetPartitioningInterface(self.module) @patch.dict('sys.modules') def test_unsupported_partitioning(self): """Test the UnsupportedPartitioningError.""" # Forget imported modules from pyanaconda and blivetgui. for name in list(sys.modules): if name.startswith('pyanaconda') or name.startswith('blivetgui'): sys.modules.pop(name) # Disable the blivetgui package. sys.modules['blivetgui'] = None # Import the StorageModule again. from pyanaconda.modules.storage.storage import StorageService # We should be able to create the Storage module storage_module = StorageService() assert storage_module.storage is not None # We should be able to create the Blivet module. from pyanaconda.modules.storage.partitioning.constants import PartitioningMethod blivet_module = storage_module.create_partitioning( PartitioningMethod.BLIVET) assert blivet_module.storage is not None # Import the exception again. from pyanaconda.modules.common.errors.storage import UnsupportedPartitioningError # Handle the missing support. with pytest.raises(UnsupportedPartitioningError): assert not blivet_module.storage_handler # pylint: disable=no-member with pytest.raises(UnsupportedPartitioningError): assert not blivet_module.request_handler # pylint: disable=no-member with pytest.raises(UnsupportedPartitioningError): request = pickle.dumps(("call", "get_disks", [])) blivet_module.send_request(request) # pylint: disable=no-member @unittest.skipUnless(HAVE_BLIVET_GUI, "blivet-gui not installed") def test_storage_handler(self): """Test the storage_handler property.""" self.module.on_storage_changed(create_storage()) assert self.module.storage_handler is not None assert self.module.storage == self.module.storage_handler.storage @unittest.skipUnless(HAVE_BLIVET_GUI, "blivet-gui not installed") def test_request_handler(self): """Test the request_handler property.""" self.module.on_storage_changed(create_storage()) assert self.module.request_handler is not None assert self.module.storage_handler == self.module.request_handler.blivet_utils @unittest.skipUnless(HAVE_BLIVET_GUI, "blivet-gui not installed") def test_send_request(self): """Test SendRequest.""" self.module.on_storage_changed(create_storage()) request = pickle.dumps(("call", "get_disks", [])) answer = self.interface.SendRequest(request) answer = pickle.loads(answer) from blivetgui.communication.proxy_utils import ProxyID # pylint: disable=import-error assert isinstance(answer, ProxyID) assert answer.id == 0 @patch_dbus_publish_object def test_configure_with_task(self, publisher): """Test ConfigureWithTask.""" self.module.on_storage_changed(create_storage()) task_path = self.interface.ConfigureWithTask() obj = check_task_creation(task_path, publisher, InteractivePartitioningTask) assert obj.implementation._storage == self.module.storage