Exemple #1
0
def test_create_workflow_run_invalid_org_workflow(app, organization_workflow):
    with pytest.raises(ValueError):
        create_workflow_run(
            organization_workflow.organization_uuid,
            "1234",
            PIPELINE_RUN_INPUT_FILE_JSON,
        )
Exemple #2
0
def test_create_workflow_run_invalid_no_pipelines(app, organization_workflow,
                                                  monkeypatch):
    monkeypatch.setattr(OrganizationWorkflow,
                        "organization_workflow_pipelines", [])

    with pytest.raises(ValueError):
        create_workflow_run(
            organization_workflow.organization_uuid,
            organization_workflow.uuid,
            PIPELINE_RUN_INPUT_FILE_JSON,
        )
Exemple #3
0
def test_create_workflow_run_deleted_workflow_pipeline(execute_pipeline_mock,
                                                       app, pipeline,
                                                       workflow_pipeline):
    services.delete_workflow_pipeline(workflow_pipeline.workflow.uuid,
                                      workflow_pipeline.uuid)
    create_data = {
        "callback_url": "https://example.com",
        "inputs": [],
    }
    workflow = workflow_pipeline.workflow
    with pytest.raises(ValueError):
        services.create_workflow_run(workflow.uuid, create_data)
    assert len(workflow.workflow_runs) == 0
Exemple #4
0
def test_find_dest_workflow_runs(delay_mock, app, workflow_line):
    workflow_run = create_workflow_run(
        workflow_line.uuid,
        {
            "callback_url": "http://example.com/cb",
            "inputs": [],
        },
    )
    assert queries.find_dest_workflow_runs(
        workflow_run.workflow_pipeline_runs[0]) == [
            workflow_run.workflow_pipeline_runs[1].pipeline_run
        ]
    assert queries.find_dest_workflow_runs(
        workflow_run.workflow_pipeline_runs[1]) == [
            workflow_run.workflow_pipeline_runs[2].pipeline_run
        ]
    assert queries.find_dest_workflow_runs(
        workflow_run.workflow_pipeline_runs[2]) == []

    # if a workflow_pipeline is deleted it is not found/included
    delete_workflow_pipeline(
        workflow_run.workflow.uuid,
        workflow_run.workflow_pipeline_runs[1].workflow_pipeline.uuid,
    )
    assert queries.find_dest_workflow_runs(
        workflow_run.workflow_pipeline_runs[0]) == []
Exemple #5
0
def test_create_workflow_run(execute_pipeline_mock, app, workflow_square):
    create_data = {
        "callback_url": "https://example.com",
        "inputs": [{
            "name": "aname.pdf",
            "url": "https://example.com/ex.pdf",
        }],
    }
    # A complex workflow with only one WorkflowPipeline w/o input should be the
    # only thing to start initially.
    workflow_pipeline_run = services.create_workflow_run(
        workflow_square.uuid, create_data)
    assert len(workflow_pipeline_run.workflow_run_states) == 1
    assert (workflow_pipeline_run.workflow_run_states[0].run_state_type.code ==
            RunStateEnum.NOT_STARTED)
    assert len(workflow_pipeline_run.workflow_pipeline_runs) == 4
    assert [
        wpr.run_state_enum()
        for wpr in workflow_pipeline_run.workflow_pipeline_runs
    ] == [
        RunStateEnum.NOT_STARTED,
        RunStateEnum.QUEUED,
        RunStateEnum.QUEUED,
        RunStateEnum.QUEUED,
    ]
Exemple #6
0
def test_create_workflow_run(execute_pipeline_mock, app, pipeline,
                             workflow_pipeline):
    create_data = {
        "callback_url": "https://example.com",
        "inputs": [{
            "name": "aname.pdf",
            "url": "https://example.com/ex.pdf",
        }],
    }
    # A new WorkflowPipelineRun creates new PipelineRuns as QUEUED...when the
    # celery worker runs it'll update their states appropriately.
    workflow_pipeline_run = services.create_workflow_run(
        workflow_pipeline.workflow.uuid, create_data)
    assert len(workflow_pipeline_run.workflow_run_states) == 1
    assert (workflow_pipeline_run.workflow_run_states[0].run_state_type.code ==
            RunStateEnum.NOT_STARTED)
    assert len(workflow_pipeline_run.workflow_pipeline_runs) == 1
    pipeline_run = workflow_pipeline_run.workflow_pipeline_runs[0].pipeline_run
    assert pipeline_run.callback_url == create_data["callback_url"]
    assert [prs.code for prs in pipeline_run.pipeline_run_states] == [
        RunStateEnum.QUEUED,
        RunStateEnum.NOT_STARTED,
    ]
    assert len(pipeline_run.pipeline_run_inputs) == 1
    assert (pipeline_run.pipeline_run_inputs[0].filename ==
            create_data["inputs"][0]["name"])
    assert pipeline_run.pipeline_run_inputs[0].url == create_data["inputs"][0][
        "url"]
Exemple #7
0
def test_create_workflow_run_not_found(app, organization_workflow,
                                       organization_workflow_pipeline):
    wf_uuid = organization_workflow.workflow_uuid
    wf_pipeline_uuid = organization_workflow_pipeline.workflow_pipeline_uuid

    responses.add(
        responses.POST,
        f"{app.config[WORKFLOW_HOSTNAME]}/v1/workflows/{wf_uuid}/runs",
        json={"not": "found"},
        status=404,
    )

    with pytest.raises(ValueError):
        create_workflow_run(
            organization_workflow.organization_uuid,
            organization_workflow.uuid,
            PIPELINE_RUN_INPUT_FILE_JSON,
        )
Exemple #8
0
def test_create_workflow_run_bad_json(app, organization_workflow,
                                      organization_workflow_pipeline):
    wf_uuid = organization_workflow.workflow_uuid
    wf_pipeline_uuid = organization_workflow_pipeline.workflow_pipeline_uuid

    responses.add(
        responses.POST,
        f"{app.config[WORKFLOW_HOSTNAME]}/v1/workflows/{wf_uuid}/runs",
        body="notjson",
        status=503,
    )

    with pytest.raises(HTTPError):
        create_workflow_run(
            organization_workflow.organization_uuid,
            organization_workflow.uuid,
            PIPELINE_RUN_INPUT_FILE_JSON,
        )
Exemple #9
0
def test_update_workflow_run_state(app, workflow_pipeline):
    workflow = workflow_pipeline.workflow
    services.create_workflow_run(
        workflow.uuid,
        {
            "callback_url": "http://example.com/cb",
            "inputs": [],
        },
    )
    workflow = workflow_pipeline.workflow
    db.session.add(workflow)
    # Setting a pipeline to its current state does nothing.
    services.update_workflow_run_state(workflow.workflow_runs[0],
                                       RunStateEnum.NOT_STARTED)
    assert workflow.workflow_runs[0].run_state_enum(
    ) == RunStateEnum.NOT_STARTED

    # Trying to make an bad state transition is an error.
    with pytest.raises(ValueError):
        services.update_workflow_run_state(workflow.workflow_runs[0],
                                           RunStateEnum.COMPLETED)
Exemple #10
0
def _configure_run_state(workflow, run_state_enum, delay_mock):
    """ Update first PipelineRun to run_state_enum and call update_workflow_run() """
    services.create_workflow_run(
        workflow.uuid,
        {
            "callback_url": "http://example.com/cb",
            "inputs": [],
        },
    )
    pipeline_runs = [
        wpr.pipeline_run
        for wpr in workflow.workflow_runs[0].workflow_pipeline_runs
    ]
    pipeline_runs[0].pipeline_run_states.append(
        create_pipeline_run_state(run_state_enum))
    pipeline_runs[0].pipeline_run_artifacts.append(
        PipelineRunArtifact(name="afile.txt"))
    db.session.commit()

    delay_mock.reset_mock()

    return (services.update_workflow_run(pipeline_runs[0]), pipeline_runs)
Exemple #11
0
def test_create_workflow_run(
    mock_fetch_pipeline_run,
    mock_url,
    app,
    organization_workflow,
    organization_workflow_pipeline,
    organization_pipeline_run,
    organization_pipeline,
    organization_pipeline_input_file,
    organization_workflow_run,
    organization_workflow_pipeline_run,
):
    mock_fetch_pipeline_run.return_value = dict(PIPELINE_RUN_RESPONSE_JSON)
    mock_url.return_value = "http://somefileurl.com"

    wf_uuid = organization_workflow.workflow_uuid
    wf_pipeline_uuid = organization_workflow_pipeline.workflow_pipeline_uuid

    responses.add(
        responses.POST,
        f"{app.config[WORKFLOW_HOSTNAME]}/v1/workflows/{wf_uuid}/runs",
        json=WORKFLOW_PIPELINE_RUN_RESPONSE_JSON,
        status=200,
    )

    new_org_workflow_run = create_workflow_run(
        organization_workflow.organization_uuid,
        organization_workflow.uuid,
        PIPELINE_RUN_INPUT_FILE_JSON,
    )

    # update to use newly created uuids
    org_wf_run_uuid = new_org_workflow_run["workflow_pipeline_runs"][0]["uuid"]
    ORGANIZATION_WORKFLOW_RUN_RESPONSE["uuid"] = new_org_workflow_run["uuid"]
    ORGANIZATION_WORKFLOW_RUN_RESPONSE["created_at"] = new_org_workflow_run[
        "created_at"]
    ORGANIZATION_WORKFLOW_RUN_RESPONSE["workflow_pipeline_runs"][0][
        "uuid"] = org_wf_run_uuid

    assert new_org_workflow_run == ORGANIZATION_WORKFLOW_RUN_RESPONSE
Exemple #12
0
def workflow_run_create(organization_uuid, organization_workflow_uuid):
    """Create an Organization Workflow Runs.
    ---
    tags:
      - workflow runs
    parameters:
      - in: header
        name: Workflow-API-Key
        description: Requires key type REACT_CLIENT
        schema:
          type: string
    requestBody:
      description: "Create an Organization Workflow Run"
      required: true
      content:
        application/json:
          inputs:
            type: array
            items:
              type: object
              properties:
                name:
                  type: string
                url:
                  type: string
    responses:
      "200":
        description: "Creates a workflow run"
        content:
          application/json:
            schema:
              type: object
              properties:
                created_at:
                  type: string
                uuid:
                  type: string
                status:
                  type: string
                workflow_pipeline_runs:
                  type: array
                  items:
                    type: object
                    properties:
                      uuid:
                        type: string
                      pipeline_run:
                        type: array
                        items:
                          type: object
                          properties:
                            created_at:
                              type: string
                            inputs:
                              type: array
                              items:
                                type: object
                                properties:
                                  name:
                                    type: string
                                  url:
                                    type: string
                                  uuid:
                                    type: string
                            sequence:
                              type: integer
                            states:
                              type: array
                              items:
                                type: object
                                properties:
                                  created_at:
                                    type: string
                                  state:
                                    type: string
      "400":
        description: "Bad request"
      "503":
        description: "Http error"
    """

    try:
        return jsonify(
            create_workflow_run(
                organization_uuid, organization_workflow_uuid, request.json
            )
        )
    except ValueError as value_error:
        return jsonify(value_error.args[0]), 400
    except HTTPError as http_error:
        return {"message": http_error.args[0]}, 503
Exemple #13
0
def test_create_workflow_run_no_workflow(app, pipeline, workflow):
    with pytest.raises(ValueError):
        services.create_workflow_run("no-id", {
            "callback_url": "https://example.com",
            "inputs": []
        })