def test_failed_request(self, session_getter):
        """Test a request that fails to be send."""
        # Prepare the session.
        session = session_getter.return_value.__enter__.return_value
        session.head.side_effect = RequestException("Fake!")

        # Run the task.
        configuration = LiveImageConfigurationData()
        configuration.url = "http://my/fake/path"

        task = SetUpRemoteImageSourceTask(configuration)
        with pytest.raises(SourceSetupError) as cm:
            task.run()

        # Check the exception.
        assert str(cm.value) == "Error while handling a request: Fake!"
    def invalid_response_test(self, session_getter):
        """Test an invalid response."""
        # Prepare the session.
        session = session_getter.return_value.__enter__.return_value
        response = session.head.return_value
        response.status_code = 303

        # Run the task.
        configuration = LiveImageConfigurationData()
        configuration.url = "http://my/fake/path"

        task = SetUpRemoteImageSourceTask(configuration)
        with self.assertRaises(SourceSetupError) as cm:
            task.run()

        # Check the exception.
        self.assertEqual(str(cm.exception), "The request has failed: 303")
    def fake_request_test(self, session_getter):
        """Test a fake request."""
        # Prepare the session.
        session = session_getter.return_value.__enter__.return_value
        response = session.head.return_value

        response.status_code = 200
        response.headers = {'content-length': 1000}

        # Run the task.
        configuration = LiveImageConfigurationData()
        configuration.url = "http://my/fake/path"

        task = SetUpRemoteImageSourceTask(configuration)
        result = task.run()

        # Check the result.
        self.assertIsInstance(result, SetupImageResult)
        self.assertEqual(result, SetupImageResult(4000))
    def missing_size_test(self, session_getter):
        """Test a request with a missing size."""
        # Prepare the session.
        session = session_getter.return_value.__enter__.return_value
        response = session.head.return_value

        response.status_code = 200
        response.headers = {}

        # Run the task.
        configuration = LiveImageConfigurationData()
        configuration.url = "http://my/fake/path"

        task = SetUpRemoteImageSourceTask(configuration)
        result = task.run()

        # Check the result.
        self.assertIsInstance(result, SetupImageResult)
        self.assertEqual(result, SetupImageResult(None))
Beispiel #5
0
    def set_up_with_tasks(self):
        """Set up the installation source for installation.

        :return: list of tasks required for the source setup
        :rtype: [Task]
        """
        if self.is_local:
            task = SetUpLocalImageSourceTask(self.configuration)
        else:
            task = SetUpRemoteImageSourceTask(self.configuration)

        handler = self._handle_setup_task_result
        task.succeeded_signal.connect(lambda: handler(task.get_result()))
        return [task]