Exemplo n.º 1
0
async def test_push_executor_with_deps():
    payload = "Actual payload"
    push_instance = Nop(name='pytest')
    dep_instance = Nop(name='pytest2')
    dep_push = PushModel(instance=dep_instance,
                         selector=None,
                         deps=[],
                         unwrap=False)
    push = PushModel(instance=push_instance,
                     selector=None,
                     unwrap=False,
                     deps=[dep_push])

    dut = PushExecutor()
    await dut.execute("id", payload, push, result_callback=None)

    assert push_instance.last_payload == "Actual payload"
    assert dep_instance.last_payload == "Actual payload"

    call_cnt = 0

    def callback(payload, push):
        nonlocal call_cnt
        assert payload == "Actual payload"
        assert push == dep_push
        call_cnt += 1

    await dut.execute("id", payload, push, result_callback=callback)
    assert call_cnt == 1
Exemplo n.º 2
0
def test_push_executor_unwrap_selector():
    input = ["one", "two", "three"]
    push_instance = Nop(name="pytest")
    dep_instance = Nop(name='pytest2')
    dep_push = PushModel(instance=dep_instance, selector=None, deps=[], unwrap=False)
    push = PushModel(instance=push_instance, selector="str(data)[0]", unwrap=True, deps=[dep_push])

    dut = PushExecutor()
    call_cnt = 0
    def callback(payload, push):
        nonlocal call_cnt
        assert payload in ['o', 't']
        assert push is dep_push
        call_cnt += 1
    dut.execute("id", input, push, result_callback=callback)
    assert call_cnt == 3
Exemplo n.º 3
0
def test_push_executor_with_selector():
    payload = dict(a="Actual payload", b="Another key that is ignored")
    push_instance = Nop(name='pytest')
    push = PushModel(instance=push_instance, selector="data.a", unwrap=False, deps=[])
    dut = PushExecutor()
    dut.execute("id", payload, push, result_callback=None)

    assert push_instance.last_payload == "Actual payload"
Exemplo n.º 4
0
async def test_basic():
    payload = dict(a="This is the payload",
                   b="another ignored key by selector")
    push_instance = Nop(name='doctest')
    push = PushModel(instance=push_instance,
                     selector='data.a',
                     deps=[],
                     unwrap=False)
    await PushExecutor().execute("pytest", payload, push)
    assert push_instance.last_payload == 'This is the payload'
Exemplo n.º 5
0
def test_endpoint_polling_error():
    tasks = {
        'pytest':
        TaskModel(
            name='pytest',
            pull=PullModel(instance=ErrorPollingDummy(name='pytest_pull')),
            pushes=[PushModel(instance=Nop(name='pytest_push'))])
    }
    with api_client(Trigger(tasks)) as client:
        response = client.post('/trigger?task=pytest')
        assert response.status_code == 500
        assert response.json() == {
            'detail': 'While triggering the poll an error occurred.'
        }
Exemplo n.º 6
0
def test_endpoint_unknown_task():
    tasks = {
        'pytest':
        TaskModel(
            name='pytest',
            pull=PullModel(instance=SyncPollingDummy(name='pytest_pull')),
            pushes=[PushModel(instance=Nop(name='pytest_push'))])
    }
    with api_client(Trigger(tasks)) as client:
        response = client.post('/trigger?task=unknown')
        assert response.status_code == 422
        assert response.json() == {
            'detail': "Given task name 'unknown' is not a known task."
        }
Exemplo n.º 7
0
def test_endpoint_not_a_poll():
    tasks = {
        'pytest':
        TaskModel(name='pytest',
                  pull=PullModel(instance=NoPollingDummy(name='pytest_pull')),
                  pushes=[PushModel(instance=Nop(name='pytest_push'))])
    }
    with api_client(Trigger(tasks)) as client:
        response = client.post('/trigger?task=pytest')
        assert response.status_code == 422
        assert response.json() == {
            'detail':
            "Task 'pytest' does not support pull_now(). "
            "Implement PullNowMixin / AsyncPullNowMixin for support"
        }
Exemplo n.º 8
0
def test_endpoint_working(clazz):

    polling = clazz(name='pytest_pull')
    result = []
    polling.callback(lambda pull, payload: result.append(payload))
    tasks = {
        'pytest':
        TaskModel(name='pytest',
                  pull=PullModel(instance=polling),
                  pushes=[PushModel(instance=Nop(name='pytest_push'))])
    }
    with api_client(Trigger(tasks)) as client:
        response = client.post('/trigger?task=pytest')
        assert response.status_code == 200
        assert response.json() == {}
        assert result == [42]