Exemplo n.º 1
0
def test_pipelinelist_post_no_project(client):
    pipeline = {
        "project_uuid": gen_uuid(),
        "uuid": gen_uuid(),
        "env_variables": {
            "a": [1]
        },
    }
    resp = client.post("/api/pipelines/", json=pipeline)

    assert resp.status_code == 500
Exemplo n.º 2
0
def test_project_get(client):
    project = {"uuid": gen_uuid(), "env_variables": {"a": [1]}}

    client.post("/api/projects/", json=project)
    data = client.get(f'/api/projects/{project["uuid"]}').get_json()

    assert data == project
Exemplo n.º 3
0
def test_projectlist_post_same_uuid(client):
    project = {"uuid": gen_uuid(), "env_variables": {"a": [1]}}
    resp1 = client.post("/api/projects/", json=project)
    resp2 = client.post("/api/projects/", json=project)

    assert resp1.status_code == 201
    assert resp2.status_code == 500
Exemplo n.º 4
0
def test_app():
    """Setup a flask application with a working db.

    Expects a postgres database service to be running. A new database
    will be created with a random name. The database is dropped at the
    end of scope of the fixture.
    """

    # Setup the DB URI.
    db_host = os.environ.get("ORCHEST_TEST_DATABASE_HOST", "localhost")
    db_port = os.environ.get("ORCHEST_TEST_DATABASE_PORT", "5432")
    # Postgres does not accept "-" as part of a name.
    db_name = gen_uuid(use_underscores=True)
    db_name = "test_db"
    SQLALCHEMY_DATABASE_URI = f"postgresql://postgres@{db_host}:{db_port}/{db_name}"
    config.TestingConfig.SQLALCHEMY_DATABASE_URI = SQLALCHEMY_DATABASE_URI
    config.CONFIG_CLASS = config.TestingConfig
    _utils.GlobalOrchestConfig._path = os.path.join(TEMP_DIR, "config.json")

    # Migrate DB
    app, _, _ = create_app(to_migrate_db=True)
    with app.app_context():
        upgrade()

    app, _, _ = create_app()
    yield app

    drop_database(app.config["SQLALCHEMY_DATABASE_URI"])
    try:
        os.remove(os.path.join(TEMP_DIR, "config.json"))
    except FileNotFoundError:
        # Config file was never created because default values were
        # never updated.
        ...
Exemplo n.º 5
0
def test_app():
    """Setup a flask application with a working db.

    Expects a postgres database service to be running. A new database
    will be created with a random name. The database is dropped at the
    end of scope of the fixture.
    """

    config = copy.deepcopy(CONFIG_CLASS)

    # Setup the DB URI.
    db_host = os.environ.get("ORCHEST_TEST_DATABASE_HOST", "localhost")
    db_port = os.environ.get("ORCHEST_TEST_DATABASE_PORT", "5432")
    # Postgres does not accept "-" as part of a name.
    db_name = gen_uuid(use_underscores=True)
    db_name = "test_db"
    SQLALCHEMY_DATABASE_URI = f"postgresql://postgres@{db_host}:{db_port}/{db_name}"
    config.SQLALCHEMY_DATABASE_URI = SQLALCHEMY_DATABASE_URI

    config.TESTING = True
    app = create_app(config, use_db=True, be_scheduler=False)
    scheduler = EagerScheduler(
        job_defaults={
            # Same settings as the "real" scheduler.
            "misfire_grace_time": 2**31,
            "coalesce": False,
            "max_instances": 2**31,
        })
    app.config["SCHEDULER"] = scheduler
    scheduler.start()
    yield app

    drop_database(app.config["SQLALCHEMY_DATABASE_URI"])
Exemplo n.º 6
0
def create_job_spec(
    project_uuid,
    pipeline_uuid,
    cron_schedule=None,
    scheduled_start=None,
    parameters=[{}],
    pipeline_run_spec=None,
):
    if pipeline_run_spec is None:
        pipeline_run_spec = create_pipeline_run_spec(project_uuid,
                                                     pipeline_uuid)

    job_spec = {
        "uuid": gen_uuid(),
        "name": "job-name",
        "project_uuid": project_uuid,
        "pipeline_uuid": pipeline_uuid,
        "pipeline_name": "pipeline-name",
        "cron_schedule": cron_schedule,
        "parameters": parameters,
        "pipeline_definition": pipeline_run_spec["pipeline_definition"],
        "pipeline_run_spec": pipeline_run_spec,
        "scheduled_start": scheduled_start,
        "strategy_json": {},
    }
    return job_spec
Exemplo n.º 7
0
def test_project_delete_existing(client):
    project = {"uuid": gen_uuid()}
    client.post("/api/projects/", json=project)

    resp = client.delete(f'/api/projects/{project["uuid"]}')

    assert resp.status_code == 200
Exemplo n.º 8
0
def test_projectlist_post_n(client):
    n = 5
    for _ in range(n):
        project = {"uuid": gen_uuid(), "env_variables": {"a": [1]}}
        client.post("/api/projects/", json=project)

    data = client.get("/api/projects/").get_json()["projects"]
    assert len(data) == n
Exemplo n.º 9
0
def test_projectlist_post(client):
    project = {"uuid": gen_uuid(), "env_variables": {"a": [1]}}

    client.post("/api/projects/", json=project)
    data = client.get("/api/projects/").get_json()["projects"][0]

    # env_variables is a deferred column, not returned by this endpoint.
    project["env_variables"] = None
    assert data == project
Exemplo n.º 10
0
def test_project_put(client):
    project = {"uuid": gen_uuid(), "env_variables": {"a": "[1]"}}

    client.post("/api/projects/", json=project)
    project["env_variables"] = {"b": '{"x": ""}'}
    client.put(f'/api/projects/{project["uuid"]}', json=project)

    data = client.get(f'/api/projects/{project["uuid"]}').get_json()
    assert data == project
Exemplo n.º 11
0
def test_environmentbuildlist_post_same(client, celery, project):
    env = {
        "project_uuid": project.uuid,
        "project_path": "project_path",
        "environment_uuid": gen_uuid(),
    }
    req = {"environment_build_requests": [env, env]}
    data = client.post("/api/environment-builds/", json=req).get_json()
    assert len(data["environment_builds"]) == 1
    assert data["failed_requests"] is None
Exemplo n.º 12
0
def create_env_build_request(project_uuid, n):
    request = {"environment_build_requests": []}

    for _ in range(n):
        request["environment_build_requests"].append(
            {
                "project_uuid": project_uuid,
                "project_path": "project_path",
                "environment_uuid": gen_uuid(),
            }
        )

    return request
Exemplo n.º 13
0
def test_pipeline_get(client, project):
    pipeline = {
        "project_uuid": project.uuid,
        "uuid": gen_uuid(),
        "env_variables": {
            "a": [1]
        },
    }
    client.post("/api/pipelines/", json=pipeline)

    data = client.get(
        f'/api/pipelines/{project.uuid}/{pipeline["uuid"]}').get_json()

    assert data == pipeline
Exemplo n.º 14
0
def test_pipelinelist_post_n(client, project):
    n = 5
    for _ in range(n):
        pipeline = {
            "project_uuid": project.uuid,
            "uuid": gen_uuid(),
            "env_variables": {
                "a": [1]
            },
        }
        client.post("/api/pipelines/", json=pipeline)

    data = client.get("/api/pipelines/").get_json()["pipelines"]
    assert len(data) == n
Exemplo n.º 15
0
def test_pipelinelist_post_same_uuid(client, project):
    pipeline = {
        "project_uuid": project.uuid,
        "uuid": gen_uuid(),
        "env_variables": {
            "a": [1]
        },
    }

    resp1 = client.post("/api/pipelines/", json=pipeline)
    resp2 = client.post("/api/pipelines/", json=pipeline)

    assert resp1.status_code == 201
    assert resp2.status_code == 500
Exemplo n.º 16
0
def test_delete_existing(client, project):
    pipeline = {
        "project_uuid": project.uuid,
        "uuid": gen_uuid(),
        "env_variables": {
            "a": [1]
        },
    }

    client.post("/api/pipelines/", json=pipeline)

    resp = client.delete(f'/api/pipelines/{project.uuid}/{pipeline["uuid"]}')

    assert resp.status_code == 200
Exemplo n.º 17
0
def test_pipelinelist_post(client, project):
    pipeline = {
        "project_uuid": project.uuid,
        "uuid": gen_uuid(),
        "env_variables": {
            "a": [1]
        },
    }
    client.post("/api/pipelines/", json=pipeline)

    data = client.get("/api/pipelines/").get_json()["pipelines"][0]

    # env_variables is a deferred column, not returned by this endpoint.
    pipeline["env_variables"] = None
    assert data == pipeline
Exemplo n.º 18
0
def test_app():
    """Setup a flask application with a working db.

    Expects a postgres database service to be running. A new database
    will be created with a random name. The database is dropped at the
    end of scope of the fixture.
    """

    config = copy.deepcopy(CONFIG_CLASS)

    # Setup the DB URI.
    db_host = os.environ.get("ORCHEST_TEST_DATABASE_HOST", "localhost")
    db_port = os.environ.get("ORCHEST_TEST_DATABASE_PORT", "5432")
    # Postgres does not accept "-" as part of a name.
    db_name = gen_uuid(use_underscores=True)
    db_name = "test_db"
    SQLALCHEMY_DATABASE_URI = f"postgresql://postgres@{db_host}:{db_port}/{db_name}"
    config.SQLALCHEMY_DATABASE_URI = SQLALCHEMY_DATABASE_URI

    config.TESTING = True
    app = create_app(config, use_db=True, be_scheduler=False)
    yield app

    drop_database(app.config["SQLALCHEMY_DATABASE_URI"])
Exemplo n.º 19
0
def project(test_app):
    """Provides a project backed by an entry in the db."""
    return Project(test_app, gen_uuid())
Exemplo n.º 20
0
def pipeline(client, project):
    """Provides a pipeline backed by an entry in the db."""
    return Pipeline(client, project, gen_uuid())
Exemplo n.º 21
0
def project(client):
    """Provides a project backed by an entry in the db."""
    return Project(client, gen_uuid())