Ejemplo n.º 1
0
def test_focus_state():
    @step("Step that works on substate")
    def substep():
        return {"result": "substep"}

    subwf = focussteps("sub")
    wf = workflow("Workflow with sub workflow that focuses on sub state")(
        lambda: subwf(substep) >> done)

    log = []
    pstat = create_new_process_stat(wf, {"sub": {}})
    result = runwf(pstat, store(log))
    assert_complete(result)
    assert_state(result, {"sub": {"result": "substep"}})

    # Test on empty key
    subwf = focussteps("sub")
    wf = workflow("Workflow with sub workflow that focuses on sub state")(
        lambda: subwf(substep) >> done)

    log = []
    pstat = create_new_process_stat(wf, {})
    result = runwf(pstat, store(log))
    assert_complete(result)
    assert_state(result, {"sub": {"result": "substep"}})
Ejemplo n.º 2
0
def test_resume_workflow():
    @step("Test step 1")
    def fakestep1():
        return {"steden": ["Utrecht"], "stad": "Amsterdam"}

    @inputstep("Wait for me step 2", assignee=Assignee.SYSTEM)
    def waitforme(steden, stad):
        class WaitForm(FormPage):
            stad: str

        user_input = yield WaitForm
        meer = [*steden, stad]
        return {**user_input.dict(), "steden": meer}

    @step("Test step 3")
    def fakestep3(steden):
        meer = [*steden, "Leiden"]
        return {"steden": meer}

    @workflow("Test wf", target="Target.CREATE")
    def testwf():
        return begin >> fakestep1 >> waitforme >> fakestep3 >> done

    with WorkflowInstanceForTests(testwf, "testwf"):
        # The process and step_log from run_workflow can be used to resume it with resume_workflow
        result, process, step_log = run_workflow("testwf", {})
        assert_suspended(result)
        result, step_log = resume_workflow(process, step_log,
                                           {"stad": "Maastricht"})
        assert_complete(result)
Ejemplo n.º 3
0
def test_complete():
    wf = workflow("WF")(lambda: init >> done)

    log = []
    pstat = create_new_process_stat(wf, {"name": "completion"})
    result = runwf(pstat, store(log))
    assert_complete(result)
    assert_state(result, {"name": "completion"})
def test_happy_flow(generic_subscription_1, validation_workflow_instance):
    product = SubscriptionTable.query.get(generic_subscription_1).product
    product.workflows.append(WorkflowTable(name="validation_workflow", target=Target.SYSTEM))
    db.session.add(product)
    db.session.commit()

    result, process, step_log = run_workflow("validation_workflow", {"subscription_id": generic_subscription_1})
    assert_complete(result)
Ejemplo n.º 5
0
def test_skip_step():
    wf = workflow("Workflow with skipped step")(
        lambda: init >> purestep("Skipped")(Skipped) >> done)

    log = []
    pstat = create_new_process_stat(wf, {})
    result = runwf(pstat, store(log))
    assert_complete(result)

    skipped = [x[1] for x in log if x[0] == "Skipped"]
    assert skipped[0].isskipped()
def test_remove_tasks(task):
    result, process, step_log = run_workflow("task_clean_up_tasks", {})
    assert_complete(result)
    res = extract_state(result)
    state = {
        "process_id": res["process_id"],
        "reporter": "john.doe",
        "tasks_removed": 1
    }
    assert_state(result, state)

    processes = ProcessTable.query.all()

    assert len(processes) == 3
    assert sorted(p.workflow for p in processes) == sorted(
        ["nice and new task", "nice process", "task_clean_up_tasks"])
Ejemplo n.º 7
0
def test_resume_workflow(waiting_process):
    with mock.patch("orchestrator.services.processes.resume_process") as m:
        result, process, step_log = run_workflow("task_resume_workflows", {})
        assert_complete(result)
        #
        res = extract_state(result)
        state = {
            "process_id": res["process_id"],
            "reporter": "john.doe",
            "number_of_waiting_processes": 1,
            "number_of_resumed_pids": 1,
            "waiting_pids": [str(PID)],
            "resumed_pids": [str(PID)],
        }
        assert_state(result, state)
        m.assert_called_once()
Ejemplo n.º 8
0
def test_modify_note(responses, generic_subscription_1):
    init_state = [{"subscription_id": generic_subscription_1}, {"note": TEST}]

    result, process, step_log = run_workflow("modify_note", init_state)
    assert_complete(result)

    # assert state for correctness
    state = extract_state(result)
    assert state["old_note"] is None
    assert state["note"] == TEST
    assert state["__old_subscriptions__"].get(generic_subscription_1)
    assert state["__old_subscriptions__"][generic_subscription_1][
        "note"] is None
    assert state["__old_subscriptions__"][generic_subscription_1][
        "description"] == "Generic Subscription One"

    # assert subscription for correctness
    subscription = get_subscription(generic_subscription_1)
    assert subscription.note == TEST
Ejemplo n.º 9
0
def test_conditionally_skip_a_step():
    @step("Inc N")
    def inc_n(n=0):
        return {"n": n + 1}

    limit_to_10 = conditional(lambda s: s.get("n", 0) < 10)

    incs = [limit_to_10(inc_n) for _ in range(0, 25)]
    wf = workflow("Limit the number of increments")(
        lambda: init >> reduce(lambda acc, e: acc >> e, incs) >> done)

    log = []

    pstat = create_new_process_stat(wf, {})
    result = runwf(pstat, store(log))
    assert_complete(result)
    # from ipdb import set_trace; set_trace()
    assert_state(result, {"n": 10})
    assert len([x for x in log
                if x[1].isskipped()]) == 15, "15 steps should be skipped"
Ejemplo n.º 10
0
def test_check_subscriptions(generic_subscription_1, generic_subscription_2):
    result, process, step_log = run_workflow("task_validate_products", {})
    assert_complete(result)