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)
def test_failing_inputstep_with_form_state_params() -> None: @inputstep("Modify") def modify(subscription_id: UUIDstr) -> NoReturn: raise Exception("Something went wrong") class Form(FormPage): subscription_id: UUID @workflow("Workflow", initial_input_form=const(Form)) def inject_args_test_workflow(): return init >> modify >> done with WorkflowInstanceForTests(inject_args_test_workflow, "inject_args_test_workflow"): init_state = {"subscription_id": uuid4()} result, process, step_log = run_workflow("inject_args_test_workflow", init_state) assert_suspended(result) step_log_copy = deepcopy(step_log) with pytest.raises(Exception) as e: resume_workflow(process, step_log, {}) assert "Something went wrong" in str(e.value) assert step_log_copy == step_log # No steps have been logged because of the error
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)
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"])
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()
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
def test_failed_validation(generic_subscription_1: str, validation_workflow_instance) -> None: @step("Fail") def fail(): raise ValueError("Failed") @validate_workflow("Failing Validation") def failing_validation_workflow() -> StepList: return begin >> fail with WorkflowInstanceForTests(failing_validation_workflow, "failing_validation_workflow"): product = SubscriptionTable.query.get(generic_subscription_1).product product.workflows.append(WorkflowTable(name="failing_validation_workflow", target=Target.SYSTEM)) db.session.add(product) db.session.commit() result, process, step_log = run_workflow( "failing_validation_workflow", {"subscription_id": generic_subscription_1} ) assert_failed(result) assert "Failed" in extract_error(result)
def test_check_subscriptions(generic_subscription_1, generic_subscription_2): result, process, step_log = run_workflow("task_validate_products", {}) assert_complete(result)
def test_no_subscription(validation_workflow_instance): with pytest.raises(FormValidationError) as error_info: run_workflow("validation_workflow", {"subscription_id": None}) assert "none is not an allowed value" in str(error_info.value)