예제 #1
0
def test_update_workflow_pipeline(update_mock, client, client_application,
                                  pipeline, workflow, workflow_pipeline):
    update_mock.return_value = workflow_pipeline
    params = {
        "pipeline_uuid": pipeline.uuid,
        "source_workflow_pipelines": [],
        "destination_workflow_pipelines": [],
    }
    result = client.put(
        f"/v1/workflows/{workflow.uuid}/pipelines/{workflow_pipeline.uuid}",
        content_type="application/json",
        json=params,
        headers={ROLES_KEY: client_application.api_key},
    )
    assert result.status_code == 200
    workflow_pipeline = find_workflow_pipeline(result.json["uuid"])
    assert result.json == {
        "uuid": workflow_pipeline.uuid,
        "pipeline_uuid": pipeline.uuid,
        "source_workflow_pipelines": [],
        "destination_workflow_pipelines": [],
        "created_at": to_iso8601(workflow_pipeline.created_at),
        "updated_at": to_iso8601(workflow_pipeline.updated_at),
    }
    assert update_mock.called
예제 #2
0
def test_create_workflow_pipeline(client, client_application, pipeline,
                                  workflow, workflow_pipeline):
    another_workflow_pipeline = create_workflow_pipeline(
        workflow.uuid,
        {
            "pipeline_uuid": pipeline.uuid,
            "source_workflow_pipelines": [],
            "destination_workflow_pipelines": [],
        },
    )
    params = {
        "pipeline_uuid": pipeline.uuid,
        "source_workflow_pipelines": [workflow_pipeline.uuid],
        "destination_workflow_pipelines": [another_workflow_pipeline.uuid],
    }
    result = client.post(
        f"/v1/workflows/{workflow.uuid}/pipelines",
        content_type="application/json",
        json=params,
        headers={ROLES_KEY: client_application.api_key},
    )
    assert result.status_code == 200
    result_wp = find_workflow_pipeline(result.json["uuid"])
    assert result.json == {
        "uuid": result_wp.uuid,
        "pipeline_uuid": pipeline.uuid,
        "source_workflow_pipelines": [workflow_pipeline.uuid],
        "destination_workflow_pipelines": [another_workflow_pipeline.uuid],
        "created_at": to_iso8601(result_wp.created_at),
        "updated_at": to_iso8601(result_wp.updated_at),
    }
예제 #3
0
def test_create_run(client, pipeline, client_application,
                    mock_execute_pipeline):
    db.session.commit()
    result = client.post(
        f"/v1/pipelines/{pipeline.uuid}/runs",
        content_type="application/json",
        json={
            "inputs": [{
                "name": "name1.pdf",
                "url": "http://example.com"
            }],
            "callback_url": "http://callback.com",
        },
        headers={ROLES_KEY: client_application.api_key},
    )
    assert result.status_code == 200
    assert len(pipeline.pipeline_runs) == 1
    assert pipeline.pipeline_runs[0].run_state_enum(
    ) == RunStateEnum.NOT_STARTED
    assert len(pipeline.pipeline_runs[0].pipeline_run_inputs) == 1
    assert pipeline.pipeline_runs[0].callback_url == "http://callback.com"
    pipeline_run = pipeline.pipeline_runs[0]

    assert result.json == {
        "uuid":
        pipeline_run.uuid,
        "sequence":
        pipeline_run.sequence,
        "created_at":
        to_iso8601(pipeline_run.created_at),
        "inputs": [{
            "name": "name1.pdf",
            "url": "http://example.com",
        }],
        "states": [
            {
                "state":
                RunStateEnum.QUEUED.name,
                "created_at":
                to_iso8601(pipeline_run.pipeline_run_states[0].created_at),
            },
            {
                "state":
                RunStateEnum.NOT_STARTED.name,
                "created_at":
                to_iso8601(pipeline_run.pipeline_run_states[1].created_at),
            },
        ],
        "artifacts": [],
    }
예제 #4
0
def test_list_pipeline_runs(client, pipeline, client_application,
                            mock_execute_pipeline):
    db.session.commit()
    result = client.get(
        f"/v1/pipelines/no-id/runs",
        headers={ROLES_KEY: client_application.api_key},
    )
    assert result.status_code == 404

    result = client.get(
        f"/v1/pipelines/{pipeline.uuid}/runs",
        headers={ROLES_KEY: client_application.api_key},
    )
    assert result.status_code == 200
    assert result.json == []

    # successfully fetch a pipeline_run
    pipeline_run = create_pipeline_run(pipeline.uuid, VALID_CALLBACK_INPUT)
    result = client.get(
        f"/v1/pipelines/{pipeline.uuid}/runs",
        headers={ROLES_KEY: client_application.api_key},
    )
    assert result.status_code == 200
    assert result.json == [{
        "uuid":
        pipeline_run.uuid,
        "sequence":
        pipeline_run.sequence,
        "created_at":
        to_iso8601(pipeline_run.created_at),
        "inputs": [],
        "states": [
            {
                "state":
                RunStateEnum.QUEUED.name,
                "created_at":
                to_iso8601(pipeline_run.pipeline_run_states[0].created_at),
            },
            {
                "state":
                RunStateEnum.NOT_STARTED.name,
                "created_at":
                to_iso8601(pipeline_run.pipeline_run_states[1].created_at),
            },
        ],
        "artifacts": [],
    }]
예제 #5
0
def test_get_workflow_pipelines(client, client_application, pipeline, workflow,
                                workflow_pipeline):
    db.session.commit()
    result = client.get(
        f"/v1/workflows/{workflow.uuid}/pipelines/{workflow_pipeline.uuid}",
        content_type="application/json",
        headers={ROLES_KEY: client_application.api_key},
    )
    assert result.status_code == 200
    assert result.json == {
        "uuid": workflow_pipeline.uuid,
        "pipeline_uuid": pipeline.uuid,
        "source_workflow_pipelines": [],
        "destination_workflow_pipelines": [],
        "created_at": to_iso8601(workflow_pipeline.created_at),
        "updated_at": to_iso8601(workflow_pipeline.updated_at),
    }
예제 #6
0
def test_get_workflow(client, client_application, workflow):
    db.session.commit()
    result = client.get(
        f"/v1/workflows/{workflow.uuid}",
        content_type="application/json",
        headers={ROLES_KEY: client_application.api_key},
    )
    assert result.status_code == 200
    workflow = Workflow.query.filter(
        Workflow.name == workflow.name).one_or_none()
    assert result.json == {
        "uuid": workflow.uuid,
        "name": workflow.name,
        "description": workflow.description,
        "created_at": to_iso8601(workflow.created_at),
        "updated_at": to_iso8601(workflow.updated_at),
    }
예제 #7
0
def test_create_workflow(client, client_application):
    db.session.commit()
    params = {"name": "a workflow", "description": "desc"}
    result = client.post(
        "/v1/workflows",
        content_type="application/json",
        json=params,
        headers={ROLES_KEY: client_application.api_key},
    )
    assert result.status_code == 200
    workflow = Workflow.query.filter(
        Workflow.name == params["name"]).one_or_none()
    assert result.json == {
        "uuid": workflow.uuid,
        "name": workflow.name,
        "description": workflow.description,
        "created_at": to_iso8601(workflow.created_at),
        "updated_at": to_iso8601(workflow.updated_at),
    }
예제 #8
0
def test_start_workflow(client, client_application, workflow_pipeline):
    db.session.commit()
    result = client.post(
        f"/v1/workflows/{workflow_pipeline.workflow.uuid}/runs",
        content_type="application/json",
        json={
            "callback_url": "https://example.com",
            "inputs": [],
        },
        headers={ROLES_KEY: client_application.api_key},
    )
    workflow_run = workflow_pipeline.workflow.workflow_runs[0]
    workflow_pipeline_run = workflow_run.workflow_pipeline_runs[0]
    pipeline_run = workflow_pipeline_run.pipeline_run
    assert result.status_code == 200
    assert result.json == {
        "uuid":
        workflow_run.uuid,
        "states": [{
            "created_at":
            to_iso8601(workflow_run.workflow_run_states[0].created_at),
            "state":
            RunStateEnum.NOT_STARTED.name,
        }],
        "workflow_pipeline_runs": [{
            "uuid": workflow_pipeline_run.uuid,
            "pipeline_run": {
                "uuid":
                pipeline_run.uuid,
                "sequence":
                pipeline_run.sequence,
                "inputs": [],
                "states": [
                    {
                        "created_at":
                        to_iso8601(
                            pipeline_run.pipeline_run_states[0].created_at),
                        "state":
                        RunStateEnum.QUEUED.name,
                    },
                    {
                        "created_at":
                        to_iso8601(
                            pipeline_run.pipeline_run_states[1].created_at),
                        "state":
                        RunStateEnum.NOT_STARTED.name,
                    },
                ],
                "artifacts": [],
                "created_at":
                to_iso8601(pipeline_run.created_at),
            },
        }],
        "created_at":
        to_iso8601(workflow_run.created_at),
        "updated_at":
        to_iso8601(workflow_run.updated_at),
    }

    db.session.add(client_application)
    result = client.get(
        f"/v1/workflows/{workflow_pipeline.workflow.uuid}/runs/{workflow_run.uuid}",
        content_type="application/json",
        headers={ROLES_KEY: client_application.api_key},
    )
    assert result.status_code == 200
    assert result.json == {
        "uuid":
        workflow_run.uuid,
        "states": [{
            "created_at":
            to_iso8601(workflow_run.workflow_run_states[0].created_at),
            "state":
            RunStateEnum.NOT_STARTED.name,
        }],
        "workflow_pipeline_runs": [{
            "uuid": workflow_pipeline_run.uuid,
            "pipeline_run": {
                "uuid":
                pipeline_run.uuid,
                "sequence":
                pipeline_run.sequence,
                "inputs": [],
                "states": [
                    {
                        "created_at":
                        to_iso8601(
                            pipeline_run.pipeline_run_states[0].created_at),
                        "state":
                        RunStateEnum.QUEUED.name,
                    },
                    {
                        "created_at":
                        to_iso8601(
                            pipeline_run.pipeline_run_states[1].created_at),
                        "state":
                        RunStateEnum.NOT_STARTED.name,
                    },
                ],
                "artifacts": [],
                "created_at":
                to_iso8601(pipeline_run.created_at),
            },
        }],
        "created_at":
        to_iso8601(workflow_run.created_at),
        "updated_at":
        to_iso8601(workflow_run.updated_at),
    }
예제 #9
0
def test_get_pipeline_run(client, pipeline, client_application,
                          mock_execute_pipeline):
    db.session.commit()
    pipeline_run = create_pipeline_run(pipeline.uuid, VALID_CALLBACK_INPUT)
    artifact = PipelineRunArtifact(name="test.pdf")
    artifact.public_url = Mock()
    artifact.public_url.return_value = "http://fake.example.com/url"
    pipeline_run.pipeline_run_artifacts.append(artifact)
    db.session.commit()

    result = client.get(
        "/v1/pipelines/no-id/runs/no-id",
        headers={ROLES_KEY: client_application.api_key},
    )
    assert result.status_code == 404

    # no such pipeline_run_id
    result = client.get(
        f"/v1/pipelines/{pipeline.uuid}/runs/no-id",
        headers={ROLES_KEY: client_application.api_key},
    )
    assert result.status_code == 404

    # successfully fetch a pipeline_run
    result = client.get(
        f"/v1/pipelines/{pipeline.uuid}/runs/{pipeline_run.uuid}",
        headers={ROLES_KEY: client_application.api_key},
    )
    assert result.status_code == 200
    assert result.json == {
        "uuid":
        pipeline_run.uuid,
        "sequence":
        pipeline_run.sequence,
        "created_at":
        to_iso8601(pipeline_run.created_at),
        "inputs": [],
        "states": [
            {
                "state":
                RunStateEnum.QUEUED.name,
                "created_at":
                to_iso8601(pipeline_run.pipeline_run_states[0].created_at),
            },
            {
                "state":
                RunStateEnum.NOT_STARTED.name,
                "created_at":
                to_iso8601(pipeline_run.pipeline_run_states[1].created_at),
            },
        ],
        "artifacts": [{
            "uuid": artifact.uuid,
            "name": "test.pdf",
            "url": "http://fake.example.com/url",
        }],
    }

    # fails if the pipeline is deleted.
    pipeline.is_deleted = True
    db.session.commit()
    result = client.get(
        f"/v1/pipelines/{pipeline.uuid}/runs/{pipeline_run.uuid}",
        headers={ROLES_KEY: client_application.api_key},
    )
    assert result.status_code == 404