Beispiel #1
0
def test_positional_args_and_the_kw_item_called_args_use_type_tuple(backend):
    # Even though we use JSON for serialization, which uses lists instead of
    # tuples, the Python convention is that positional arguments are a tuple.
    backend.set(ANYTIME, 'myid', ('arg', ), {'args': ('celery-kw-arg', )})
    task = backend.get('myid')
    assert isinstance(task[0], tuple)
    assert isinstance(task[1]['args'], tuple)
Beispiel #2
0
def test_task_passed_to_set_can_be_retrieved_with_get(backend):
    args = ('arg', )
    kw = {'kw': None}
    backend.set(ANYTIME, 'myid', args, kw)
    task = backend.get('myid')
    assert task[0] == args
    assert task[1] == kw
Beispiel #3
0
def test_delete_task_can_not_be_retrieved_with_get_or_older_than(backend):
    backend.set(ANYTIME, 'one', ('arg1', ), {'kw1': None})
    backend.set(ANYTIME, 'two', ('arg2', ), {'kw2': None})
    backend.delete('one')
    with pytest.raises(KeyError):
        backend.get('one')
    assert backend.get('two') == (('arg2', ), {'kw2': None})
    assert list(backend.get_older_than(ANYTIME)) == [('two', (('arg2', ), {
        'kw2': None
    }))]
Beispiel #4
0
def test_get_older_than_returns_timestamps_smaller_or_equal(backend):
    backend.set(pendulum.create(2017, 1, 1, 9), '1', (1, ), {'1': 1})
    backend.set(pendulum.create(2017, 1, 1, 10), '2', (2, ), {'2': 2})
    backend.set(pendulum.create(2017, 1, 1, 11), '3', (3, ), {'3': 3})
    items = list(backend.get_older_than(pendulum.create(2017, 1, 1, 10)))
    assert len(items) == 2
    assert items[0][0] == '1'
    assert items[0][1] == ((1, ), {'1': 1})
    assert items[1][0] == '2'
    assert items[1][1] == ((2, ), {'2': 2})
Beispiel #5
0
def test_set_works_with_datetime(backend):
    due = datetime.now(pendulum.timezone('UTC'))
    backend.set(due, 'myid', (), {})
    tasks = list(backend.get_older_than(due))
    assert len(tasks) == 1
    assert tasks[0][0] == 'myid'
Beispiel #6
0
def test_set_requires_timezone_aware_datetime(backend):
    with pytest.raises(ValueError):
        backend.set(datetime.now(), 'myid', (), {})