Пример #1
0
def test_create_job_instance_method():
    """Create job instance method job form the job spec."""

    redis = object()
    id = b'2a5079e7-387b-492f-a81c-68aa55c194c8'
    spec = {
        b'created_at': b'2016-04-05T22:40:35Z',
        b'data': b'\x80\x04\x959\x00\x00\x00\x00\x00\x00\x00(\x8c\x03div\x94\x8c\x08fixtures\x94\x8c\x06Number\x94\x93\x94)}\x94\x92\x94}\x94\x8c\x05value\x94K\x02sbK\x04\x85\x94}\x94t\x94.',  # noqa
        b'description': b'div(4)',
        b'timeout': 180,
        b'result_ttl': 5000,
        b'status': JobStatus.QUEUED.encode(),
        b'origin': b'default',
        b'enqueued_at': b'2016-05-03T12:10:11Z',
    }
    job = create_job(redis, id, spec)
    assert job.connection == redis
    assert job.id == '2a5079e7-387b-492f-a81c-68aa55c194c8'
    assert job.created_at == datetime(2016, 4, 5, 22, 40, 35)
    assert job.func.__name__ == 'div'
    assert job.func.__self__.__class__ == Number
    assert job.args == (4,)
    assert job.kwargs == {}
    assert job.description == 'div(4)'
    assert job.timeout == 180
    assert job.result_ttl == 5000
    assert job.status == 'queued'
    assert job.origin == 'default'
    assert job.enqueued_at == datetime(2016, 5, 3, 12, 10, 11)
Пример #2
0
def test_create_job():
    """Create job job form the job spec."""

    redis = object()
    id = b'2a5079e7-387b-492f-a81c-68aa55c194c8'
    spec = {
        b'created_at': b'2016-04-05T22:40:35Z',
        b'data': b'\x80\x04\x950\x00\x00\x00\x00\x00\x00\x00(\x8c\x19fixtures.some_calculation\x94NK\x03K\x04\x86\x94}\x94\x8c\x01z\x94K\x02st\x94.',  # noqa
        b'description': b'fixtures.some_calculation(3, 4, z=2)',
        b'timeout': 180,
        b'result_ttl': 5000,
        b'status': JobStatus.QUEUED.encode(),
        b'origin': b'default',
        b'enqueued_at': b'2016-05-03T12:10:11Z',
    }
    job = create_job(redis, id, spec)
    assert job.connection == redis
    assert job.id == '2a5079e7-387b-492f-a81c-68aa55c194c8'
    assert job.created_at == datetime(2016, 4, 5, 22, 40, 35)
    assert job.func == some_calculation
    assert job.args == (3, 4)
    assert job.kwargs == {'z': 2}
    assert job.description == 'fixtures.some_calculation(3, 4, z=2)'
    assert job.timeout == 180
    assert job.result_ttl == 5000
    assert job.status == 'queued'
    assert job.origin == 'default'
    assert job.enqueued_at == datetime(2016, 5, 3, 12, 10, 11)
Пример #3
0
def test_create_job_unreadable_data(redis):
    """Create job unreadable pickle string will raise UnpickleError."""

    id = b'2a5079e7-387b-492f-a81c-68aa55c194c8'
    spec = {
        b'created_at': b'2016-04-05T22:40:35Z',
        b'data': b'this is no pickle string',
        b'description': b'fixtures.some_calculation(3, 4, z=2)',
        b'timeout': 180,
        b'result_ttl': 5000,
        b'status': JobStatus.QUEUED.encode(),
        b'origin': b'default',
        b'enqueued_at': b'2016-05-03T12:10:11Z',
    }
    with pytest.raises(UnpicklingError):
        create_job(redis, id, spec)
Пример #4
0
def test_create_job_unimportable_data(redis):
    """Create job unimportable data will raise attribute error."""

    id = b'2a5079e7-387b-492f-a81c-68aa55c194c8'
    spec = {
        b'created_at': b'2016-04-05T22:40:35Z',
        # nay_hello instead of say_hello
        b'data': b"\x80\x04\x95'\x00\x00\x00\x00\x00\x00\x00(\x8c\x12fixtures.nay_hello\x94N\x8c\x06Lionel\x94\x85\x94}\x94t\x94.",  # noqa
        b'description': b"fixtures.say_hello('Lionel')",
        b'timeout': 180,
        b'result_ttl': 5000,
        b'status': JobStatus.QUEUED.encode(),
        b'origin': b'default',
        b'enqueued_at': b'2016-05-03T12:10:11Z',
    }
    with pytest.raises(AttributeError):
        create_job(redis, id, spec)
Пример #5
0
def test_create_job_custom_job_class():
    """Create job will instantiate passed job class."""

    redis = object()
    id = b'2a5079e7-387b-492f-a81c-68aa55c194c8'
    spec = {
        b'created_at': b'2016-04-05T22:40:35Z',
        b'data': b'\x80\x04\x950\x00\x00\x00\x00\x00\x00\x00(\x8c\x19fixtures.some_calculation\x94NK\x03K\x04\x86\x94}\x94\x8c\x01z\x94K\x02st\x94.',  # noqa
        b'description': b'fixtures.some_calculation(3, 4, z=2)',
        b'timeout': 180,
        b'result_ttl': 5000,
        b'status': JobStatus.QUEUED.encode(),
        b'origin': b'default',
        b'enqueued_at': b'2016-05-03T12:10:11Z',
    }
    job = create_job(redis, id, spec, job_class=CustomJob)
    assert isinstance(job, CustomJob)
Пример #6
0
def test_create_job_meta_missed():
    """Store meta field as empty dict if it missed in the spec."""

    redis = object()
    id = b'2a5079e7-387b-492f-a81c-68aa55c194c8'
    spec = {
        b'created_at': b'2016-04-05T22:40:35Z',
        b'data': b'\x80\x04\x950\x00\x00\x00\x00\x00\x00\x00(\x8c\x19fixtures.some_calculation\x94NK\x03K\x04\x86\x94}\x94\x8c\x01z\x94K\x02st\x94.',  # noqa
        b'description': b'fixtures.some_calculation(3, 4, z=2)',
        b'timeout': 180,
        b'result': stubs.job_result,
        b'result_ttl': 5000,
        b'status': JobStatus.QUEUED.encode(),
        b'origin': b'default',
        b'enqueued_at': b'2016-05-03T12:10:11Z',
    }
    job = create_job(redis, id, spec)
    assert job.meta == {}