async def test_returned_task_runs_original_function(self, original_task_function: Callable, task_config: TaskConfig, mocked_job_with_adapter: Job): job_handler = task_builder.build_job_handler( original_task_function, task_config) await job_handler(mocked_job_with_adapter) original_task_function.assert_called_once()
async def test_complete_job_called(self, original_task_function: Callable, task_config: TaskConfig, mocked_job_with_adapter: Job): job_handler = task_builder.build_job_handler( original_task_function, task_config) await job_handler(mocked_job_with_adapter) mocked_job_with_adapter.set_success_status.assert_called_once()
async def test_parameters_are_provided_to_task(self, original_task_function: Callable, task_config: TaskConfig, mocked_job_with_adapter: Job): mocked_job_with_adapter.variables = {"x": 1} job_handler = task_builder.build_job_handler( original_task_function, task_config) await job_handler(mocked_job_with_adapter) original_task_function.assert_called_with(x=1)
async def test_job_parameter_is_injected(self, task_config: TaskConfig, mocked_job_with_adapter: Job): task_config.job_parameter_name = "job" job_handler = task_builder.build_job_handler( self.function_with_job_parameter, task_config ) job = await job_handler(mocked_job_with_adapter) assert job.variables["job"] == mocked_job_with_adapter
async def test_variables_are_added_to_result(self, original_task_function: Callable, task_config: TaskConfig, mocked_job_with_adapter: Job): original_task_function.return_value = {"x": 1} job_handler = task_builder.build_job_handler( original_task_function, task_config ) job = await job_handler(mocked_job_with_adapter) assert job.variables.pop("x") == 1
async def test_job_parameter_retains_variables(self, task_config: TaskConfig, mocked_job_with_adapter: Job): task_config.job_parameter_name = "job" expected_variables = copy.copy(mocked_job_with_adapter.variables) job_handler = task_builder.build_job_handler( self.function_with_job_parameter, task_config ) job = await job_handler(mocked_job_with_adapter) assert job.variables["job"].variables == expected_variables
async def test_exception_handler_called(self, original_task_function: Callable, task_config: TaskConfig, mocked_job_with_adapter: Job): exception = Exception() original_task_function.side_effect = exception job_handler = task_builder.build_job_handler( original_task_function, task_config) await job_handler(mocked_job_with_adapter) task_config.exception_handler.assert_called_with( exception, mocked_job_with_adapter)
async def test_decorator_variables_are_added(self, original_task_function: Callable, decorator: TaskDecorator, task_config: TaskConfig, mocked_job_with_adapter: Job): mocked_job_with_adapter.variables = {"x": 2} decorator_return_value = mocked_job_with_adapter decorator.return_value = decorator_return_value job_handler = task_builder.build_job_handler( original_task_function, task_config) job = await job_handler(mocked_job_with_adapter) assert "x" in job.variables
async def test_after_decorator_called(self, original_task_function: Callable, decorator: TaskDecorator, task_config: TaskConfig, mocked_job_with_adapter: Job): task_config.after.append(decorator) job_handler = task_builder.build_job_handler( original_task_function, task_config ) await job_handler(mocked_job_with_adapter) task_config.after.pop().assert_called_once()
async def test_failing_decorator_continues(self, original_task_function: Callable, decorator: TaskDecorator, task_config: TaskConfig, mocked_job_with_adapter: Job): decorator.side_effect = Exception() task_config.before.append(decorator) job_handler = task_builder.build_job_handler( original_task_function, task_config ) await job_handler(mocked_job_with_adapter) decorator.assert_called_once() task_config.exception_handler.assert_not_called()
def test_returned_task_is_callable(self, original_task_function: Callable, task_config: TaskConfig): task = task_builder.build_job_handler( original_task_function, task_config) assert callable(task)