class LiveImageModuleTestCase(unittest.TestCase):
    def setUp(self):
        self.module = LiveImageModule()

    def test_calculate_required_space(self):
        """Test the calculate_required_space method."""
        self.assertEqual(self.module.calculate_required_space(), 0)

        source = SourceFactory.create_source(SourceType.LIVE_IMAGE)
        self.module.add_source(source)

        self.assertEqual(self.module.calculate_required_space(),
                         1024 * 1024 * 1024)

    def test_install_with_task_from_tar(self):
        """Test Live Image install with tasks from tarfile."""
        # task_path = self.live_image_interface.PreInstallWithTasks()
        # check_task_creation_list(self, task_path, publisher, [SetupInstallationSourceImageTask])

        # task_path = self.live_image_interface.InstallWithTasks()
        # check_task_creation_list(self, task_path, publisher, [InstallFromTarTask])
        self.assertEqual(self.module.install_with_tasks(), [])

    @patch_dbus_publish_object
    def test_install_with_task_from_image(self, publisher):
        """Test Live Image install with tasks from image."""
        # task_path = self.live_image_interface.PreInstallWithTasks()
        # check_task_creation_list(self, task_path, publisher, [SetupInstallationSourceImageTask])

        # task_path = self.live_image_interface.InstallWithTasks()
        # check_task_creation_list(self, task_path, publisher, [InstallFromImageTask])
        self.assertEqual(self.module.install_with_tasks(), [])

    @patch_dbus_publish_object
    def test_post_install_with_tasks(self, publisher):
        """Test Live Image post installation configuration task."""
        # task_classes = [
        #     TeardownInstallationSourceImageTask
        # ]
        #
        # task_paths = self.live_image_interface.PostInstallWithTasks()
        #
        # # Check the number of installation tasks.
        # task_number = len(task_classes)
        # self.assertEqual(task_number, len(task_paths))
        # self.assertEqual(task_number, publisher.call_count)
        #
        # # Check the tasks.
        # for i in range(task_number):
        #     object_path, obj = publisher.call_args_list[i][0]
        #     self.assertEqual(object_path, task_paths[i])
        #     self.assertIsInstance(obj, TaskInterface)
        #     self.assertIsInstance(obj.implementation, task_classes[i])
        self.assertEqual(self.module.post_install_with_tasks(), [])
Example #2
0
class LiveImageModuleTestCase(unittest.TestCase):
    def setUp(self):
        self.module = LiveImageModule()

    def test_multiple_sources(self):
        """The live image payload cannot have multiple sources."""
        sources = [
            SourceFactory.create_source(SourceType.LIVE_IMAGE),
            SourceFactory.create_source(SourceType.LIVE_IMAGE)
        ]

        with pytest.raises(IncompatibleSourceError) as cm:
            self.module.set_sources(sources)

        assert str(
            cm.value) == "You can set only one source for this payload type."

    def test_calculate_required_space(self):
        """Test the calculate_required_space method."""
        assert self.module.calculate_required_space() == 0

        source = SourceFactory.create_source(SourceType.LIVE_IMAGE)
        self.module.add_source(source)

        assert self.module.calculate_required_space() == 1024 * 1024 * 1024

    def test_install_with_task_from_tar(self):
        """Test installation tasks with a tarfile."""
        assert self.module.install_with_tasks() == []

        source = SourceFactory.create_source(SourceType.LIVE_TAR)
        self.module.add_source(source)

        tasks = self.module.install_with_tasks()
        assert len(tasks) == 1
        assert isinstance(tasks[0], InstallLiveTarTask)

    def test_install_with_task_from_image(self):
        """Test installation tasks with an image."""
        assert self.module.install_with_tasks() == []

        source = SourceFactory.create_source(SourceType.LIVE_IMAGE)
        self.module.add_source(source)

        tasks = self.module.install_with_tasks()
        assert len(tasks) == 1
        assert isinstance(tasks[0], InstallLiveImageTask)

    def test_post_install_with_tasks(self):
        """Test post-installation tasks."""
        assert self.module.post_install_with_tasks() == []