def test_Task_apply_async_reserved_headers_in_kwargs(header, expected): with mock.patch('girder_worker.task.celery.Task.apply_async', spec=True) as mock_apply_async: t = Task() t.name = 'example.task' t.apply_async((), {header: expected}) margs, mkwargs = mock_apply_async.call_args assert 'headers' in mkwargs assert header in mkwargs['headers'] assert mkwargs['headers'][header] == expected
def test_Task_delay_reserved_options_in_kwargs(option, expected): with mock.patch('girder_worker.task.celery.Task.apply_async', spec=True) as mock_apply_async: t = Task() t.name = 'example.task' t.delay(**{option: expected}) margs, mkwargs = mock_apply_async.call_args assert 'headers' in mkwargs assert option in mkwargs['headers'] assert mkwargs['headers'][option] == expected
def test_Task_apply_async_does_not_meddle_with_headers_on_builtin_tasks(name): kwargs = dict(RESERVED_OPTIONS) with mock.patch('girder_worker.task.celery.Task.apply_async', spec=True) as mock_apply_async: t = Task() t.name = name t.apply_async((), kwargs, **{}) mock_apply_async.assert_called_once() # Expected behavior is that reserved options will be popped out of kwargs # This tests to make sure that we never meddle with headers on builtin tasks for k, _ in RESERVED_OPTIONS: assert k in kwargs
def test_Task_apply_async_reserved_in_options_with_existing_header_option( header, expected): with mock.patch('girder_worker.task.celery.Task.apply_async', spec=True) as mock_apply_async: t = Task() t.name = 'example.task' t.apply_async((), {}, **{ header: expected, 'headers': { 'some': 'header' } }) margs, mkwargs = mock_apply_async.call_args assert 'headers' in mkwargs assert header in mkwargs['headers'] assert mkwargs['headers'][header] == expected
def _task_with_request(*args, **kwargs): task = Task() task.name = 'example.task' task.request_stack = celery.utils.threads.LocalStack() task.push_request(*args, **kwargs) return task