def handle_setup_task_result_test(self, runner): """Test the handler of the set-up tasks.""" self.module.configuration.url = "file://my/path" runner.return_value = SetupImageResult(12345) tasks = self.module.set_up_with_tasks() for task in tasks: task.run_with_signals() runner.assert_called_once_with() self.assertEqual(self.module.required_space, 12345)
def empty_image_test(self): """Test an empty image.""" with tempfile.NamedTemporaryFile("w") as f: # Run the task. configuration = LiveImageConfigurationData() configuration.url = "file://" + f.name task = SetUpLocalImageSourceTask(configuration) result = task.run() # Check the result. self.assertIsInstance(result, SetupImageResult) self.assertEqual(result, SetupImageResult(None))
def test_empty_image(self, os_stat): """Test an empty image.""" os_stat.return_value = Mock(st_blocks=0) with tempfile.NamedTemporaryFile("w") as f: # Run the task. configuration = LiveImageConfigurationData() configuration.url = "file://" + f.name task = SetUpLocalImageSourceTask(configuration) result = task.run() # Check the result. assert isinstance(result, SetupImageResult) assert result == SetupImageResult(None)
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))
def fake_image_test(self, os_stat): """Test a fake image.""" os_stat.return_value = Mock(st_blocks=2) with tempfile.NamedTemporaryFile("w") as f: # Create a fake image. f.write("MY FAKE IMAGE") f.flush() # Run the task. configuration = LiveImageConfigurationData() configuration.url = "file://" + f.name task = SetUpLocalImageSourceTask(configuration) result = task.run() # Check the result. self.assertIsInstance(result, SetupImageResult) self.assertEqual(result, SetupImageResult(3072))