Ejemplo n.º 1
0
def test_remove():
    """Ensure queue.remove properly removes Job from queue."""

    connection = object()
    sentinel = []

    class Protocol:
        @staticmethod
        @asyncio.coroutine
        def cancel_job(redis, name, id):
            assert redis is connection
            assert name == 'example'
            assert id == '56e6ba45-1aa3-4724-8c9f-51b7b0031cee'
            sentinel.append(1)

    class TestQueue(Queue):
        protocol = Protocol()

    q = TestQueue(connection, 'example')

    job = Job(connection=connection,
              id='56e6ba45-1aa3-4724-8c9f-51b7b0031cee',
              func=say_hello,
              args=(),
              kwargs={},
              description='fixtures.say_hello()',
              timeout=180,
              result_ttl=5000,
              origin='default',
              created_at=datetime(2016, 4, 5, 22, 40, 35))

    yield from q.remove(job)
    yield from q.remove(job.id)
    assert len(sentinel) == 2