Beispiel #1
0
def test_Task_apply_async_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.apply_async((), {option: expected})
        margs, mkwargs = mock_apply_async.call_args
        assert 'headers' in mkwargs
        assert option in mkwargs['headers']
        assert mkwargs['headers'][option] == expected
Beispiel #2
0
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
Beispiel #3
0
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