示例#1
0
async def test_async_engine_for_smoke():
    engine = AsyncEngine(retry_handler=NoRetryHandler())
    deps = [
        PushModel(instance=Echo(name='dep_echo'),
                  selector="payload",
                  deps=[],
                  unwrap=False)
    ]
    tasks = {
        'pytest':
        TaskModel(
            name="pytest",
            pull=PullModel(instance=Count(name='count', from_cnt=0, wait=0.5)),
            pushes=[
                PushModel(instance=Echo(name='echo'),
                          selector=None,
                          deps=deps,
                          unwrap=False)
            ])
    }
    t = Thread(target=partial(_run_engine, engine=engine, tasks=tasks))
    try:
        t.start()
        time.sleep(1)
        await engine.stop()
        t.join(timeout=5)
    finally:
        if t.is_alive():
            assert False
示例#2
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
示例#3
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
示例#4
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"
示例#5
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'
示例#6
0
def test_task_to_str_for_smoke():
    tasks_to_str({
        'pytest':
        TaskModel(
            name="pytest",
            pull=PullModel(instance=Repeat(name='pytest_pul', repeat='hello')),
            pushes=[
                PushModel(instance=Echo(name='pytest_push'),
                          selector=None,
                          deps=[],
                          unwrap=False)
            ])
    })
示例#7
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.'
        }
示例#8
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."
        }
示例#9
0
def test_engine_for_smoke(engine):
    tasks = {
        'pytest':
        TaskModel(
            name="pytest",
            pull=PullModel(instance=Count(name='count', from_cnt=0, wait=0.5)),
            pushes=[
                PushModel(instance=Echo(name='echo'),
                          selector=None,
                          deps=[],
                          unwrap=False)
            ])
    }
    run_engine(engine, tasks)
示例#10
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"
        }
示例#11
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]
示例#12
0
 def _many(pushlist: List[Box], prefix: str) -> Iterable[PushModel]:
     for i, push in enumerate(pushlist):
         push_name = '{prefix}_{i}'.format(i=i, prefix=prefix)
         args = {
             'name': push_name,
             **extra,
             **push[Schemas.plugin_args_name]
         }
         unwrap = getattr(push, Schemas.push_unwrap_name, False)
         yield PushModel(instance=cast(
             Push,
             load_plugin(plugin_path=push[Schemas.plugin_name],
                         plugin_type=Push,
                         instantiate=True,
                         **args)),
                         selector=push[Schemas.push_selector_name],
                         unwrap=unwrap,
                         deps=list(
                             _many(push[Schemas.push_deps_name],
                                   push_name)))