示例#1
0
def test_find_organization_pipelines(app, organization_pipeline):
    assert set(
        find_organization_pipelines(organization_pipeline.organization_uuid)
    ) == set([organization_pipeline])

    # deleted pipelines are not included
    organization_pipeline.is_deleted = True
    db.session.commit()
    assert set(
        find_organization_pipelines(organization_pipeline.organization_uuid)
    ) == set([])
示例#2
0
def test_delete_pipeline_http_error(delete_mock, app, client,
                                    client_application, organization_pipeline):
    delete_mock.side_effect = HTTPError("something is wrong")
    result = client.delete(
        f"/v1/organizations/{ORGANIZATION_UUID}/pipelines/{organization_pipeline.uuid}",
        content_type="application/json",
        headers={
            "Authorization": f"Bearer {JWT_TOKEN}",
            ROLES_KEY: client_application.api_key,
        },
    )
    assert result.status_code == 503
    assert set(find_organization_pipelines(ORGANIZATION_UUID)) == set(
        [organization_pipeline])
    assert result.json == {"message": "something is wrong"}
示例#3
0
def test_delete_pipeline_bad_response(delete_mock, app, client,
                                      client_application,
                                      organization_pipeline):
    message = {"message": "error"}
    delete_mock.side_effect = ValueError(message)
    result = client.delete(
        f"/v1/organizations/{ORGANIZATION_UUID}/pipelines/{organization_pipeline.uuid}",
        content_type="application/json",
        headers={
            "Authorization": f"Bearer {JWT_TOKEN}",
            ROLES_KEY: client_application.api_key,
        },
    )
    assert result.status_code == 400
    assert set(find_organization_pipelines(ORGANIZATION_UUID)) == set(
        [organization_pipeline])
示例#4
0
def test_delete_pipeline(app, client, client_application,
                         organization_pipeline):
    responses.add(
        responses.DELETE,
        f"{app.config[WORKFLOW_HOSTNAME]}/v1/pipelines/{organization_pipeline.pipeline_uuid}",
    )

    result = client.delete(
        f"/v1/organizations/{ORGANIZATION_UUID}/pipelines/{organization_pipeline.uuid}",
        content_type="application/json",
        headers={
            "Authorization": f"Bearer {JWT_TOKEN}",
            ROLES_KEY: client_application.api_key,
        },
    )
    assert result.status_code == 200
    assert set(find_organization_pipelines(ORGANIZATION_UUID)) == set()
示例#5
0
def fetch_workflow_pipelines(organization_uuid, organization_workflow_uuid):
    """Fetches all Organization Workflow Pipelines."""

    organization_workflow = find_organization_workflow(
        organization_uuid, organization_workflow_uuid
    )

    if not organization_workflow:
        raise ValueError("Organization Workflow not found.")

    response = requests.get(
        f"{current_app.config[WORKFLOW_HOSTNAME]}/v1/workflows/{organization_workflow.workflow_uuid}/pipelines",
        headers={
            "Content-Type": "application/json",
            ROLES_KEY: current_app.config[WORKFLOW_API_TOKEN],
        },
    )

    try:
        json_value = response.json()
        response.raise_for_status()

        # map workflow pipelines to org pipeline ids and uuids
        org_pipelines = {
            o_p.pipeline_uuid: (
                o_p.id,
                o_p.uuid,
            )
            for o_p in find_organization_pipelines(organization_uuid)
        }

        wp_to_owp = {
            owp.workflow_pipeline_uuid: owp
            for owp in organization_workflow.organization_workflow_pipelines
        }

        for workflow_pipeline in json_value:
            workflow_pipeline = _workflow_pipeline_to_org_wp(
                workflow_pipeline, wp_to_owp[workflow_pipeline["uuid"]]
            )

        return json_value
    except ValueError as value_error:
        raise HTTPError("Non JSON payload returned") from value_error
    except HTTPError as http_error:
        raise ValueError(json_value) from http_error