def create_source(source_type: SourceType): """Create a source module. :param source_type: a source type :return: a source module """ if source_type == SourceType.LIVE_OS_IMAGE: from pyanaconda.modules.payloads.source.live_os.live_os import LiveOSSourceModule return LiveOSSourceModule() elif source_type == SourceType.LIVE_IMAGE: from pyanaconda.modules.payloads.source.live_image.live_image import \ LiveImageSourceModule return LiveImageSourceModule() elif source_type == SourceType.LIVE_TAR: from pyanaconda.modules.payloads.source.live_tar.live_tar import LiveTarSourceModule return LiveTarSourceModule() elif source_type == SourceType.CDROM: from pyanaconda.modules.payloads.source.cdrom.cdrom import CdromSourceModule return CdromSourceModule() elif source_type == SourceType.HMC: from pyanaconda.modules.payloads.source.hmc.hmc import HMCSourceModule return HMCSourceModule() elif source_type == SourceType.REPO_FILES: from pyanaconda.modules.payloads.source.repo_files.repo_files import \ RepoFilesSourceModule return RepoFilesSourceModule() elif source_type == SourceType.NFS: from pyanaconda.modules.payloads.source.nfs.nfs import NFSSourceModule return NFSSourceModule() elif source_type == SourceType.URL: from pyanaconda.modules.payloads.source.url.url import URLSourceModule return URLSourceModule() elif source_type == SourceType.HDD: from pyanaconda.modules.payloads.source.harddrive.harddrive import \ HardDriveSourceModule return HardDriveSourceModule() elif source_type == SourceType.CDN: from pyanaconda.modules.payloads.source.cdn.cdn import CDNSourceModule return CDNSourceModule() elif source_type == SourceType.CLOSEST_MIRROR: from pyanaconda.modules.payloads.source.closest_mirror.closest_mirror import \ ClosestMirrorSourceModule return ClosestMirrorSourceModule() elif source_type == SourceType.RPM_OSTREE: from pyanaconda.modules.payloads.source.rpm_ostree.rpm_ostree import \ RPMOSTreeSourceModule return RPMOSTreeSourceModule() elif source_type == SourceType.FLATPAK: from pyanaconda.modules.payloads.source.flatpak.flatpak import \ FlatpakSourceModule return FlatpakSourceModule() raise ValueError("Unknown source type: {}".format(source_type))
class FlatpakSourceTestCase(unittest.TestCase): """Test the OSTree source module.""" def setUp(self): self.module = FlatpakSourceModule() def test_type(self): """Test the type property.""" self.assertEqual(self.module.type, SourceType.FLATPAK) def test_network_required(self): """Test the network_required property.""" self.assertEqual(self.module.network_required, False) def test_required_space(self): """Test the required_space property.""" self.assertEqual(self.module.required_space, 0) self.module._set_required_space(1024) self.assertEqual(self.module.required_space, 1024) @patch( "pyanaconda.modules.payloads.source.flatpak.flatpak.GetFlatpaksSizeTask.run" ) def test_set_required_space_with_task(self, run_mock): """Set the required_space property with a task.""" run_mock.return_value = 1024 for task in self.module.set_up_with_tasks(): task.run_with_signals() self.assertEqual(self.module.required_space, 1024) def test_get_state(self): """Test the source state.""" self.assertEqual(self.module.get_state(), SourceState.NOT_APPLICABLE) def test_set_up_with_tasks(self): """Test the set-up tasks.""" tasks = self.module.set_up_with_tasks() self.assertEqual(len(tasks), 1) self.assertIsInstance(tasks[0], GetFlatpaksSizeTask) def test_tear_down_with_tasks(self): """Test the tear-down tasks.""" self.assertEqual(self.module.tear_down_with_tasks(), []) def test_repr(self): """Test the string representation.""" self.assertEqual(repr(self.module), "Source(type='FLATPAK')")
class FlatpakSourceTestCase(unittest.TestCase): """Test the OSTree source module.""" def setUp(self): self.module = FlatpakSourceModule() def test_type(self): """Test the type property.""" assert self.module.type == SourceType.FLATPAK def test_network_required(self): """Test the network_required property.""" assert self.module.network_required == False def test_required_space(self): """Test the required_space property.""" assert self.module.required_space == 0 self.module._set_required_space(1024) assert self.module.required_space == 1024 @patch( "pyanaconda.modules.payloads.source.flatpak.flatpak.GetFlatpaksSizeTask.run" ) def test_set_required_space_with_task(self, run_mock): """Set the required_space property with a task.""" run_mock.return_value = 1024 for task in self.module.set_up_with_tasks(): task.run_with_signals() assert self.module.required_space == 1024 def test_get_state(self): """Test the source state.""" assert self.module.get_state() == SourceState.NOT_APPLICABLE def test_set_up_with_tasks(self): """Test the set-up tasks.""" tasks = self.module.set_up_with_tasks() assert len(tasks) == 1 assert isinstance(tasks[0], GetFlatpaksSizeTask) def test_tear_down_with_tasks(self): """Test the tear-down tasks.""" assert self.module.tear_down_with_tasks() == [] def test_repr(self): """Test the string representation.""" assert repr(self.module) == "Source(type='FLATPAK')"
class FlatpakSourceInterfaceTestCase(unittest.TestCase): """Test the DBus interface of the Flatpak source.""" def setUp(self): self.module = FlatpakSourceModule() self.interface = self.module.for_publication() def _check_dbus_property(self, *args, **kwargs): check_dbus_property(self, PAYLOAD_SOURCE_RPM_OSTREE, self.interface, *args, **kwargs) def test_type(self): """Test the Type property.""" self.assertEqual(self.interface.Type, SOURCE_TYPE_FLATPAK) def test_description(self): """Test the Description property.""" self.assertEqual(self.interface.Description, "Flatpak") def test_is_available(self): """Test the IsAvailable method.""" self.assertEqual(self.interface.IsAvailable(), False)
def setUp(self): self.module = FlatpakSourceModule()
def setUp(self): self.module = FlatpakSourceModule() self.interface = self.module.for_publication()