コード例 #1
0
def test_input_in_substate() -> None:
    @inputstep("Input Name", assignee=Assignee.SYSTEM)
    def input_action(state: State) -> FormGenerator:
        class SubForm(FormPage):
            a: int

        class TestForm(FormPage):
            sub: SubForm

        user_input = yield TestForm

        return user_input.dict()

    wf = workflow("Workflow with user interaction")(
        lambda: begin >> input_action >> purestep("process inputs")(Success))

    log: List[Tuple[str, Process]] = []
    pid = uuid4()
    p = ProcessStat(pid=pid,
                    workflow=wf,
                    state=Suspend({"sub": {
                        "a": 1,
                        "b": 2
                    }}),
                    log=wf.steps[1:],
                    current_user="******")
    result = runwf(p, logstep=store(log))

    assert_success(result)
    assert_state(result, {"sub": {"a": 1, "b": 2}})
コード例 #2
0
def test_resume_suspended_workflow():
    wf = workflow("Workflow with user interaction")(
        lambda: begin >> step1 >> user_action >> step2)

    log = []

    p = ProcessStat(
        pid=1,
        workflow=wf,
        state=Suspend({
            "steps": [1],
            "name": "Jane Doe"
        }),
        log=wf.steps[1:],
        current_user="******",
    )
    result = runwf(p, logstep=store(log))

    assert_success(result)
    assert result == Success({"steps": [1, 2], "name": "Jane Doe"})
    assert [
        ("Input Name", Success({
            "steps": [1],
            "name": "Jane Doe"
        })),
        ("Step 2", Success({
            "steps": [1, 2],
            "name": "Jane Doe"
        })),
    ] == log
コード例 #3
0
def test_exec_through_all_steps():
    log = []

    pstat = create_new_process_stat(sample_workflow, {})
    result = runwf(pstat, store(log))
    assert_success(result)
    assert_state(result, {"steps": [1, 2, 3]})
コード例 #4
0
def test_recover():
    log = []

    p = ProcessStat(
        pid=1,
        workflow=sample_workflow,
        state=Success({"steps": [4]}),
        log=sample_workflow.steps[1:],
        current_user="******",
    )
    result = runwf(p, store(log))
    assert_success(result)
    assert_state(result, {"steps": [4, 2, 3]})
コード例 #5
0
def test_resume_waiting_workflow():
    hack = {"error": True}

    @retrystep("Waiting step")
    def soft_fail():
        if hack["error"]:
            raise ValueError("error")
        else:
            return {"some_key": True}

    wf = workflow("Workflow with soft fail")(
        lambda: begin >> step1 >> soft_fail >> step2)

    log = []

    state = Waiting({"steps": [1]})

    hack["error"] = False
    p = ProcessStat(pid=1,
                    workflow=wf,
                    state=state,
                    log=wf.steps[1:],
                    current_user="******")
    result = runwf(p, logstep=store(log))

    assert_success(result)
    assert [
        ("Waiting step", Success({
            "steps": [1],
            "some_key": True
        })),
        ("Step 2", Success({
            "steps": [1, 2],
            "some_key": True
        })),
    ] == log
コード例 #6
0
def test_process_state_assertions():
    process_success = Success({"done": True})
    assert_success(process_success)
    with pytest.raises(AssertionError):
        assert_failed(process_success)

    process_failed_with_message = Failed("Failure message")

    assert_failed(process_failed_with_message)

    with pytest.raises(AssertionError):
        assert_success(process_failed_with_message)

    process_failed_with_exception = Failed(ValueError("A is not B"))

    assert_failed(process_failed_with_exception)

    with pytest.raises(ValueError):
        # When a Failed or Waiting state is encountered with an exception it will be reraised
        assert_success(process_failed_with_exception)