Skip to content

Commit

Permalink
Merge pull request #2014 from DSD-DBS/in-flight-entertainment-system
Browse files Browse the repository at this point in the history
feat: Add IFE model as default model
  • Loading branch information
MoritzWeber0 authored Nov 19, 2024
2 parents 6a3ca78 + 871ac02 commit 2324dcb
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 52 deletions.
112 changes: 78 additions & 34 deletions backend/capellacollab/core/database/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,47 +77,38 @@ def migrate_db(engine, database_url: str):
LOGGER.info("Database structure creation successful")
command.stamp(alembic_cfg, "head")
initialize_admin_user(session)
initialize_default_project(session)
create_tools(session)

initialize_capellambse_test_project(session)
initialize_coffee_machine_project(session)
initialize_ife_project(session)

create_tools(session)
create_t4c_instance_and_repositories(session)
create_git_instances(session)
create_default_models(session)
create_coffee_machine_model(session)

logging.info("Database migrations completed.")


def initialize_admin_user(db: orm.Session):
LOGGER.info("Initialized adminuser %s", config.initial.admin)
admin_user = users_crud.create_user(
db=db,
username=config.initial.admin,
idp_identifier=config.initial.admin,
role=users_models.Role.ADMIN,
)
events_crud.create_user_creation_event(db, admin_user)
LOGGER.info("Initialized admin user %s", config.initial.admin)


def initialize_default_project(db: orm.Session):
LOGGER.info("Initialized project 'default'")
projects_crud.create_project(
db=db,
name="default",
description="",
visibility=project_models.Visibility.INTERNAL,
)


def initialize_coffee_machine_project(db: orm.Session):
LOGGER.info("Initialize project 'Coffee Machine'")
projects_crud.create_project(
def initialize_capellambse_test_project(db: orm.Session):
project = projects_crud.create_project(
db=db,
name="Coffee Machine",
description="",
name="Melody Model Test",
description="Group of test models of the capellambse Python library",
visibility=project_models.Visibility.INTERNAL,
)
create_capellambse_test_models(db, project)
LOGGER.info("Initialized project '%s'", project.name)


def get_eclipse_session_configuration() -> (
Expand Down Expand Up @@ -445,17 +436,16 @@ def create_git_instances(db: orm.Session):
)


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

default_project = projects_crud.get_project_by_slug(db, "default")
assert default_project

for version in ["5.0.0", "5.2.0", "6.0.0"]:
capella_model = toolmodels_crud.create_model(
db=db,
project=default_project,
project=project,
post_model=toolmodels_models.PostToolModel(
name=f"Melody Model Test {version}",
description="",
Expand All @@ -479,21 +469,28 @@ def create_default_models(db: orm.Session):
password="",
),
)
LOGGER.info("Initialized default models")


def create_coffee_machine_model(db: orm.Session):
def initialize_coffee_machine_project(db: orm.Session):
project = projects_crud.create_project(
db=db,
name="Coffee Machine",
description="Contains the Capella Coffee Machine sample model",
visibility=project_models.Visibility.INTERNAL,
)
create_coffee_machine_model(db, project)
LOGGER.info("Initialized project '%s'", project.name)


def create_coffee_machine_model(
db: orm.Session, project: project_models.DatabaseProject
):
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,
project=project,
post_model=toolmodels_models.PostToolModel(
name="Coffee Machine",
description="An open source model of a coffee machine",
Expand All @@ -517,4 +514,51 @@ def create_coffee_machine_model(db: orm.Session):
password="",
),
)
LOGGER.info("Initialized coffee machine model")


def initialize_ife_project(db: orm.Session):
project = projects_crud.create_project(
db=db,
name="In-Flight Entertainment",
description="Contains the Capella In-Flight Entertainment System sample model",
visibility=project_models.Visibility.INTERNAL,
)
create_ife_model(db, project)
LOGGER.info("Initialized project '%s'", project.name)


def create_ife_model(db: orm.Session, project: project_models.DatabaseProject):
"""Add the Capella In-Flight Entertainment project & model."""

capella_tool = tools_crud.get_tool_by_name(db, "Capella")
assert capella_tool

capella_model = toolmodels_crud.create_model(
db=db,
project=project,
post_model=toolmodels_models.PostToolModel(
name="In-Flight Entertainment",
description=(
"The Capella In-Flight Entertainment System sample model,"
" with some modifications"
),
tool_id=capella_tool.id,
),
tool=capella_tool,
version=tools_crud.get_version_by_tool_id_version_name(
db, capella_tool.id, "7.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/Capella-IFE-sample",
entrypoint="In-Flight Entertainment System.aird",
revision="master",
username="",
password="",
),
)
36 changes: 18 additions & 18 deletions backend/tests/projects/test_projects_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ def test_get_internal_default_project_as_user(
db, executor_name, executor_name, None, users_models.Role.USER
)

response = client.get("/api/v1/projects/default")
response = client.get("/api/v1/projects/melody-model-test")

assert response.status_code == 200
assert response.json()["name"] == "default"
assert response.json()["name"] == "Melody Model Test"
assert response.json()["visibility"] == "internal"
assert response.json()["slug"] == "default"
assert response.json()["slug"] == "melody-model-test"


def test_get_projects_as_user_only_shows_default_internal_project(
Expand All @@ -52,9 +52,9 @@ def test_get_projects_as_user_only_shows_default_internal_project(

data = response.json()

assert len(data) == 2
assert data[0]["slug"] == "default"
assert data[0]["visibility"] == "internal"
assert len(data) > 0
for project in data:
assert project["visibility"] == "internal"


@pytest.mark.usefixtures("project_manager")
Expand All @@ -68,7 +68,7 @@ def test_get_projects_as_user_with_project(

data = response.json()

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

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

data = response.json()

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


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

data = response.json()

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


def test_get_internal_projects_as_user_without_duplicates(
Expand Down Expand Up @@ -144,15 +144,15 @@ def test_get_internal_projects_as_user_without_duplicates(

data = response.json()

assert len(data) == 3
assert len(data) > 1

assert data[0]["slug"] == "default"
assert data[0]["slug"] == "melody-model-test"
assert data[0]["visibility"] == "internal"
assert data[0]["users"]["contributors"] == 0

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


def test_create_private_project_as_admin(
Expand Down

0 comments on commit 2324dcb

Please sign in to comment.