class InteractivePartitioningInterfaceTestCase(unittest.TestCase): """Test DBus interface of the interactive partitioning module.""" def setUp(self): """Set up the module.""" self.module = InteractivePartitioningModule() self.interface = InteractivePartitioningInterface(self.module) def publication_test(self): """Test the DBus representation.""" self.assertIsInstance(self.module.for_publication(), InteractivePartitioningInterface) def method_property_test(self): """Test Method property.""" self.assertEqual(self.interface.PartitioningMethod, PARTITIONING_METHOD_INTERACTIVE) @patch_dbus_publish_object def get_device_tree_test(self, publisher): """Test GetDeviceTree.""" DeviceTreeContainer._counter = 0 self.module.on_storage_changed(Mock()) tree_path = self.interface.GetDeviceTree() publisher.assert_called_once() object_path, obj = publisher.call_args[0] self.assertEqual(tree_path, object_path) self.assertIsInstance(obj, DeviceTreeInterface) self.assertEqual(obj.implementation, self.module._device_tree_module) self.assertEqual(obj.implementation.storage, self.module.storage) self.assertTrue(tree_path.endswith("/DeviceTree/1")) publisher.reset_mock() self.assertEqual(tree_path, self.interface.GetDeviceTree()) self.assertEqual(tree_path, self.interface.GetDeviceTree()) self.assertEqual(tree_path, self.interface.GetDeviceTree()) publisher.assert_not_called() @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 InteractivePartitioningInterfaceTestCase(unittest.TestCase): """Test DBus interface of the interactive partitioning module.""" def setUp(self): """Set up the module.""" self.module = InteractivePartitioningModule() self.interface = InteractivePartitioningInterface(self.module) def test_publication(self): """Test the DBus representation.""" assert isinstance(self.module.for_publication(), InteractivePartitioningInterface) @patch_dbus_publish_object def test_device_tree(self, publisher): """Test the device tree.""" self.module.on_storage_changed(create_storage()) path = self.interface.GetDeviceTree() check_dbus_object_creation(path, publisher, DeviceTreeSchedulerModule) def test_method_property(self): """Test Method property.""" assert self.interface.PartitioningMethod == PARTITIONING_METHOD_INTERACTIVE @patch_dbus_publish_object def test_lazy_storage(self, publisher): """Make sure that the storage playground is created lazily.""" self.module.on_storage_changed(create_storage()) device_tree_module = self.module.get_device_tree() assert self.module._storage_playground is None device_tree_module.get_disks() assert self.module._storage_playground is not None self.module.on_partitioning_reset() self.module.on_storage_changed(create_storage()) assert self.module._storage_playground is None device_tree_module.get_actions() assert self.module._storage_playground is not None @patch_dbus_publish_object def test_get_device_tree(self, publisher): """Test GetDeviceTree.""" reset_dbus_container(DeviceTreeContainer) self.module.on_storage_changed(create_storage()) tree_path = self.interface.GetDeviceTree() publisher.assert_called_once() object_path, obj = publisher.call_args[0] assert tree_path == object_path assert isinstance(obj, DeviceTreeInterface) assert obj.implementation == self.module._device_tree_module assert obj.implementation.storage == self.module.storage assert tree_path.endswith("/DeviceTree/1") publisher.reset_mock() assert tree_path == self.interface.GetDeviceTree() assert tree_path == self.interface.GetDeviceTree() assert tree_path == self.interface.GetDeviceTree() publisher.assert_not_called() @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