Example #1
0
def test_list_project_names_filter(
    db: DBInterface,
    db_session: sqlalchemy.orm.Session,
):

    project_names = [
        "project-1", "project-2", "project-3", "project-4", "project-5"
    ]
    for project in project_names:
        db.create_project(
            db_session,
            mlrun.api.schemas.Project(
                metadata=mlrun.api.schemas.ProjectMetadata(name=project), ),
        )
    filter_names = [project_names[0], project_names[3], project_names[4]]
    projects_output = db.list_projects(
        db_session,
        format_=mlrun.api.schemas.ProjectsFormat.name_only,
        names=filter_names,
    )

    assert (deepdiff.DeepDiff(
        filter_names,
        projects_output.projects,
        ignore_order=True,
    ) == {})

    projects_output = db.list_projects(
        db_session,
        format_=mlrun.api.schemas.ProjectsFormat.name_only,
        names=[],
    )

    assert projects_output.projects == []
Example #2
0
def test_list_project(
    db: DBInterface,
    db_session: sqlalchemy.orm.Session,
):
    expected_projects = [
        {
            "name": "project-name-1"
        },
        {
            "name": "project-name-2",
            "description": "project-description-2"
        },
        {
            "name": "project-name-3"
        },
        {
            "name": "project-name-4",
            "description": "project-description-4"
        },
    ]
    for project in expected_projects:
        db.create_project(
            db_session,
            mlrun.api.schemas.Project(name=project["name"],
                                      description=project.get("description")),
        )
    projects_output = db.list_projects(db_session)
    for index, project in enumerate(projects_output.projects):
        assert project.name == expected_projects[index]["name"]
        assert project.description == expected_projects[index].get(
            "description")
Example #3
0
def test_data_migration_fill_project_state(
    db: DBInterface, db_session: sqlalchemy.orm.Session,
):
    for i in range(10):
        project_name = f"project-name-{i}"
        _generate_and_insert_pre_060_record(db_session, project_name)
    projects = db.list_projects(db_session)
    for project in projects.projects:
        # getting default value from the schema
        assert project.spec.desired_state == mlrun.api.schemas.ProjectState.online
        assert project.status.state is None
    mlrun.api.initial_data._fill_project_state(db, db_session)
    projects = db.list_projects(db_session)
    for project in projects.projects:
        assert project.spec.desired_state == mlrun.api.schemas.ProjectState.online
        assert project.status.state == project.spec.desired_state
    # verify not storing for no reason
    db.store_project = unittest.mock.Mock()
    mlrun.api.initial_data._fill_project_state(db, db_session)
    assert db.store_project.call_count == 0
Example #4
0
def test_list_project(
    db: DBInterface,
    db_session: sqlalchemy.orm.Session,
):
    expected_projects = [
        {
            "name": "project-name-1"
        },
        {
            "name": "project-name-2",
            "description": "project-description-2"
        },
        {
            "name": "project-name-3",
            "labels": {
                "key": "value"
            }
        },
        {
            "name": "project-name-4",
            "description": "project-description-4",
            "labels": {
                "key2": "value2"
            },
        },
    ]
    for project in expected_projects:
        db.create_project(
            db_session,
            mlrun.api.schemas.Project(
                metadata=mlrun.api.schemas.ProjectMetadata(
                    name=project["name"], labels=project.get("labels")),
                spec=mlrun.api.schemas.ProjectSpec(
                    description=project.get("description")),
            ),
        )
    projects_output = db.list_projects(db_session)
    for index, project in enumerate(projects_output.projects):
        assert project.metadata.name == expected_projects[index]["name"]
        assert project.spec.description == expected_projects[index].get(
            "description")
        assert (deepdiff.DeepDiff(
            expected_projects[index].get("labels"),
            project.metadata.labels,
            ignore_order=True,
        ) == {})