class LiveOSSourceInterfaceTestCase(unittest.TestCase): def setUp(self): self.module = LiveOSSourceModule() self.interface = LiveOSSourceInterface(self.module) self.callback = PropertiesChangedCallback() self.interface.PropertiesChanged.connect(self.callback) def type_test(self): """Test Live OS source has a correct type specified.""" self.assertEqual(SOURCE_TYPE_LIVE_OS_IMAGE, self.interface.Type) def image_path_empty_properties_test(self): """Test Live OS payload image path property when not set.""" self.assertEqual(self.interface.ImagePath, "") def image_path_properties_test(self): """Test Live OS payload image path property is correctly set.""" self.interface.SetImagePath("/my/supper/image/path") self.assertEqual(self.interface.ImagePath, "/my/supper/image/path") self.callback.assert_called_once_with( PAYLOAD_SOURCE_LIVE_OS.interface_name, {"ImagePath": "/my/supper/image/path"}, []) # TODO: Make detection method coverage better @patch("pyanaconda.modules.payloads.source.live_os.live_os.stat") @patch("pyanaconda.modules.payloads.source.live_os.live_os.os.stat") def detect_live_os_image_failed_block_device_test(self, os_stat_mock, stat_mock): """Test Live OS image detection failed block device check.""" # we have to patch this even thought that result is used in another mock # otherwise we will skip the whole sequence os_stat_mock.return_value = {stat_mock.ST_MODE: "whatever"} stat_mock.S_ISBLK = Mock() stat_mock.S_ISBLK.return_value = False self.assertEqual(self.interface.DetectLiveOSImage(), "") @patch("pyanaconda.modules.payloads.source.live_os.live_os.os.stat") def detect_live_os_image_failed_nothing_found_test(self, os_stat_mock): """Test Live OS image detection failed missing file.""" # we have to patch this even thought that result is used in another mock # otherwise we will skip the whole sequence os_stat_mock.side_effect = FileNotFoundError() self.assertEqual(self.interface.DetectLiveOSImage(), "") @patch("pyanaconda.modules.payloads.source.live_os.live_os.stat") @patch("pyanaconda.modules.payloads.source.live_os.live_os.os.stat") def detect_live_os_image_test(self, os_stat_mock, stat_mock): """Test Live OS image detection.""" # we have to patch this even thought that result is used in another mock # otherwise we will skip the whole sequence stat_mock.S_ISBLK = Mock(return_value=True) detected_image = self.interface.DetectLiveOSImage() stat_mock.S_ISBLK.assert_called_once() self.assertEqual(detected_image, "/dev/mapper/live-base")
def setUp(self): self.live_os_source_module = LiveOSSourceModule() self.live_os_source_interface = LiveOSSourceInterface( self.live_os_source_module) self.callback = PropertiesChangedCallback() self.live_os_source_interface.PropertiesChanged.connect(self.callback)
class LiveOSSourceInterfaceTestCase(unittest.TestCase): """Test the DBus interface of the Live OS source.""" def setUp(self): self.module = LiveOSSourceModule() self.interface = LiveOSSourceInterface(self.module) def test_type(self): """Test the source type.""" assert self.interface.Type == SOURCE_TYPE_LIVE_OS_IMAGE def test_description(self): """Test the source description.""" assert self.interface.Description == "Live OS" def test_defaults(self): """Test the default values.""" assert self.interface.ImagePath == "" def test_image_path(self): """Test the ImagePath property.""" check_dbus_property(PAYLOAD_SOURCE_LIVE_OS, self.interface, "ImagePath", "/my/fake/path") @patch_dbus_publish_object def test_detect_image_with_task(self, publisher): """Test the DetectImageWithTask method.""" task_path = self.interface.DetectImageWithTask() check_task_creation(task_path, publisher, DetectLiveOSImageTask)
def setUp(self): self.module = LiveOSSourceModule() self.interface = LiveOSSourceInterface(self.module)
def for_publication(self): """Get the interface used to publish this source.""" return LiveOSSourceInterface(self)
def for_publication(self): """Return a DBus representation.""" return LiveOSSourceInterface(self)