예제 #1
0
def test_basic_worker():
    channel = InputOutputEndpoint()
    w = Worker(channel, identity_work_method)
    w.start()

    channel.push("TEST")

    assert channel.pull() == ["TEST", ]
    assert channel._acks == [True, ]
예제 #2
0
def test_forward_payload_error():
    channel = InputOutputEndpoint()
    w = Worker(channel, work_method)
    w.start()

    error_payload = {"error": "Some error", }
    channel.push(error_payload)

    assert channel.pull() == [error_payload, ]
    assert channel._acks == [True, ]
예제 #3
0
def test_error_field_with_no_error():
    channel = InputOutputEndpoint()
    w = Worker(channel, work_method)
    w.start()

    error_payload = {"error": {}, }
    channel.push(error_payload)

    assert channel.pull() == ["WORKED", ]
    assert channel._acks == [True, ]
예제 #4
0
def test_add_error():

    w = Worker('test', None, None, None)

    payload = {}
    error_payload = w.add_error(payload, invalid_payload_error)

    expected = {'error': {'test': [invalid_payload_error, ]}}

    assert expected == error_payload
예제 #5
0
def test_add_none_error_adds_no_error():

    w = Worker('test', None, None, None)

    payload = {}
    error_payload = w.add_error(payload, None)

    expected = {}

    assert expected == error_payload
예제 #6
0
def test_invalid_payload_sends_error_and_nacks():

    channel = InputOutputEndpoint()
    w = Worker(channel, identity_work_method, all_payloads_are_invalid)
    w.start()

    channel.push("TEST")

    assert channel.pull() == [invalid_payload_error, ]
    assert channel._acks == [False, ]
예제 #7
0
def test_forward_payload_error():
    channel = InputOutputEndpoint()
    w = Worker('test', channel, channel, work_method)
    w.start_consuming()

    error_payload = {"error": "Some error", }
    channel.push(error_payload)

    assert channel.pull() == [error_payload, ]
    assert channel._acks == [(None, True), ]
예제 #8
0
def test_basic_worker():
    channel = InputOutputEndpoint()
    w = Worker(channel, identity_work_method)
    w.start()

    channel.push("TEST")

    assert channel.pull() == [
        "TEST",
    ]
    assert channel._acks == [
        True,
    ]
예제 #9
0
def test_not_producer_does_not_send():

    channel = InputOutputEndpoint()
    w = Worker('test', channel, None, work_method)
    w.start_consuming()

    assert not w.is_producer()

    channel.push("TEST")

    results = channel.pull()

    assert len(results) == 0
    assert channel._acks == [(None, True), ]
예제 #10
0
def test_invalid_payload_sends_error_and_nacks():

    channel = InputOutputEndpoint()
    w = Worker(channel, identity_work_method, all_payloads_are_invalid)
    w.start()

    channel.push("TEST")

    assert channel.pull() == [
        invalid_payload_error,
    ]
    assert channel._acks == [
        False,
    ]
예제 #11
0
def test_error_field_with_no_error():
    channel = InputOutputEndpoint()
    w = Worker('test', channel, channel, work_method)
    w.start_consuming()

    error_payload = {"error": {}, }
    channel.push(error_payload)

    results = channel.pull()

    assert len(results) == 1
    assert results[0]['input'] == error_payload
    assert results[0]['output'] == "WORKED"
    assert 'trace' in results[0]
    assert channel._acks == [(None, True), ]
예제 #12
0
def test_basic_worker():
    channel = InputOutputEndpoint()
    w = Worker('test', channel, channel, work_method)
    w.start_consuming()

    channel.push("TEST")

    results = channel.pull()

    assert len(results) == 1

    assert results[0]['input'] == "TEST"
    assert results[0]['output'] == "WORKED"
    assert 'trace' in results[0]
    assert channel._acks == [(None, True), ]
예제 #13
0
def test_work_error_forwards_error_and_nacks():
    channel = InputOutputEndpoint()
    w = Worker('test', channel, channel, work_error_method)
    w.start_consuming()

    channel.push("TEST")

    results = channel.pull()

    assert results[0]['error']['test'] == [work_error, ]
    assert 'input' in results[0]
    assert 'output' in results[0]
    assert 'trace' in results[0]

    assert channel._acks == [(None, False), ]
예제 #14
0
def test_error_field_with_no_error():
    channel = InputOutputEndpoint()
    w = Worker(channel, work_method)
    w.start()

    error_payload = {
        "error": {},
    }
    channel.push(error_payload)

    assert channel.pull() == [
        "WORKED",
    ]
    assert channel._acks == [
        True,
    ]
예제 #15
0
def test_forward_payload_error():
    channel = InputOutputEndpoint()
    w = Worker(channel, work_method)
    w.start()

    error_payload = {
        "error": "Some error",
    }
    channel.push(error_payload)

    assert channel.pull() == [
        error_payload,
    ]
    assert channel._acks == [
        True,
    ]
예제 #16
0
def test_send_exception_does_not_acknowledge():
    class BrokenOutput(InputOutputEndpoint):

        def send_to_output(self, payload):
            raise Exception("BrokenOutput")

    channel = BrokenOutput()

    w = Worker('test', channel, channel, work_method)
    w.start_consuming()

    channel.push("TEST")

    results = channel.pull()

    assert len(results) == 0
    assert channel._acks == []
예제 #17
0
def test_invalid_payload_sends_error_and_nacks():

    channel = InputOutputEndpoint()
    w = Worker('test', channel, channel, work_method, all_payloads_are_invalid)
    w.start_consuming()

    channel.push({'data': "TEST"})

    results = channel.pull()

    assert len(results) == 1
    assert results[0]['error']['test'] == [invalid_payload_error, ]
    assert 'input' not in results[0]
    assert 'output' not in results[0]
    assert 'trace' in results[0]

    assert channel._acks == [(None, False), ]
예제 #18
0
def test_method_with_delivery_tag():
    class Method:
        delivery_tag = 99

    channel = InputOutputEndpoint()
    w = Worker('test', channel, channel, work_method)
    w.start_consuming()

    channel.push("TEST", method=Method())

    results = channel.pull()

    assert len(results) == 1
    assert results[0]['input'] == "TEST"
    assert results[0]['output'] == "WORKED"
    assert 'trace' in results[0]

    assert channel._acks == [(99, True), ]
예제 #19
0
def test_add_field_for_string_payload():
    w = Worker('test', None, None, None)

    payload = w.add_field('payload', 'some_field', 'some_value')
    assert payload == 'payload'
예제 #20
0
def test_check_field_for_string_payload():
    w = Worker('test', None, None, None)

    payload = w.check_field('payload', 'some_field')
    assert payload == 'payload'