Skip to content

Commit

Permalink
feat: Add coffee machine as default model
Browse files Browse the repository at this point in the history
  • Loading branch information
Paula-Kli committed Oct 30, 2023
1 parent ca2d78a commit b8c94a0
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 14 deletions.
71 changes: 69 additions & 2 deletions backend/capellacollab/core/database/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
models as git_models,
)
from capellacollab.projects.toolmodels.modelsources.t4c import crud as t4c_crud
from capellacollab.settings.modelsources.git import crud as modelssources_crud
from capellacollab.settings.modelsources.git import (
models as modelssources_models,
)
from capellacollab.settings.modelsources.t4c import crud as settings_t4c_crud
from capellacollab.settings.modelsources.t4c import (
models as settings_t4c_models,
Expand Down Expand Up @@ -71,10 +75,13 @@ def migrate_db(engine, database_url: str):
command.stamp(alembic_cfg, "head")
initialize_admin_user(session)
initialize_default_project(session)
initialize_coffee_machine_project(session)

create_tools(session)
create_t4c_instance_and_repositories(session)
create_models(session)
create_github_instance(session)
create_default_models(session)
create_coffee_machine_model(session)


def initialize_admin_user(db):
Expand All @@ -97,6 +104,16 @@ def initialize_default_project(db):
)


def initialize_coffee_machine_project(db):
LOGGER.info("Initialize project 'Coffee Machine'")
projects_crud.create_project(
db=db,
name="Coffee Machine",
description="",
visibility=project_models.Visibility.INTERNAL,
)


def create_tools(db):
LOGGER.info("Initialized tools")
registry = config["docker"]["registry"]
Expand Down Expand Up @@ -189,7 +206,19 @@ def create_t4c_instance_and_repositories(db):
LOGGER.info("Initialized T4C instance and repositories")


def create_models(db: orm.Session):
def create_github_instance(db: orm.Session):
modelssources_crud.create_git_instance(
db=db,
body=modelssources_models.PostGitInstance(
type=modelssources_models.GitType.GITHUB,
name="Github",
url="https://github.com",
api_url="https://api.github.com",
),
)


def create_default_models(db: orm.Session):
capella_tool = tools_crud.get_tool_by_name(db, "Capella")
assert capella_tool

Expand Down Expand Up @@ -224,3 +253,41 @@ def create_models(db: orm.Session):
),
)
LOGGER.info("Initialized default models")


def create_coffee_machine_model(db: orm.Session):
capella_tool = tools_crud.get_tool_by_name(db, "Capella")
assert capella_tool

coffee_machine_project = projects_crud.get_project_by_slug(
db, "coffee-machine"
)
assert coffee_machine_project

capella_model = toolmodels_crud.create_model(
db=db,
project=coffee_machine_project,
post_model=toolmodels_models.PostCapellaModel(
name="Coffee Machine",
description="An open source model of a coffee machine",
tool_id=capella_tool.id,
),
tool=capella_tool,
version=tools_crud.get_version_by_tool_id_version_name(
db, capella_tool.id, "6.0.0"
),
nature=tools_crud.get_nature_by_name(db, capella_tool, "model"),
)

git_crud.add_git_model_to_capellamodel(
db=db,
capella_model=capella_model,
post_git_model=git_models.PostGitModel(
path="https://github.com/DSD-DBS/coffee-machine",
entrypoint="coffee-machine-demo.aird",
revision="main",
username="",
password="",
),
)
LOGGER.info("Initialized coffee machine model")
24 changes: 12 additions & 12 deletions backend/tests/projects/test_projects_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_get_projects_as_user_only_shows_default_internal_project(

data = response.json()

assert len(data) == 1
assert len(data) == 2
assert data[0]["slug"] == "default"
assert data[0]["visibility"] == "internal"

Expand All @@ -68,7 +68,7 @@ def test_get_projects_as_user_with_project(

data = response.json()

assert len(data) == 2
assert len(data) == 3
assert data[0]["slug"] == project.slug
assert data[0]["visibility"] == "private"

Expand All @@ -87,9 +87,9 @@ def test_get_projects_as_admin(

data = response.json()

assert len(data) == 2
assert data[1]["slug"] == project.slug
assert data[1]["visibility"] == "private"
assert len(data) == 3
assert data[2]["slug"] == project.slug
assert data[2]["visibility"] == "private"


def test_get_internal_projects_as_user(
Expand All @@ -106,9 +106,9 @@ def test_get_internal_projects_as_user(

data = response.json()

assert len(data) == 2
assert data[1]["slug"] == project.slug
assert data[1]["visibility"] == "internal"
assert len(data) == 3
assert data[2]["slug"] == project.slug
assert data[2]["visibility"] == "internal"


def test_get_internal_projects_as_user_without_duplicates(
Expand All @@ -132,15 +132,15 @@ def test_get_internal_projects_as_user_without_duplicates(

data = response.json()

assert len(data) == 2
assert len(data) == 3

assert data[0]["slug"] == "default"
assert data[0]["visibility"] == "internal"
assert data[0]["users"]["contributors"] == 0

assert data[1]["slug"] == project.slug
assert data[1]["visibility"] == "internal"
assert data[1]["users"]["contributors"] == 1
assert data[2]["slug"] == project.slug
assert data[2]["visibility"] == "internal"
assert data[2]["users"]["contributors"] == 1


def test_create_private_project_as_admin(
Expand Down

0 comments on commit b8c94a0

Please sign in to comment.