Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Delete TeamForCapella server instances #1778

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions backend/capellacollab/settings/modelsources/t4c/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,11 @@ def update_t4c_instance(
db.commit()

return instance


def delete_t4c_instance(
db: orm.Session,
instance: models.DatabaseT4CInstance,
):
db.delete(instance)
db.commit()
13 changes: 13 additions & 0 deletions backend/capellacollab/settings/modelsources/t4c/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ def edit_t4c_instance(
return crud.update_t4c_instance(db, instance, body)


@router.delete(
"/{t4c_instance_id}",
status_code=204,
)
def delete_t4c_instance(
instance: models.DatabaseT4CInstance = fastapi.Depends(
injectables.get_existing_instance
),
db: orm.Session = fastapi.Depends(database.get_db),
):
crud.delete_t4c_instance(db, instance)


@router.get(
"/{t4c_instance_id}/licenses",
response_model=models.GetSessionUsageResponse,
Expand Down
22 changes: 22 additions & 0 deletions backend/tests/settings/teamforcapella/test_t4c_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
from fastapi import status, testclient
from sqlalchemy import orm

from capellacollab.projects.toolmodels.modelsources.t4c import (
crud as models_t4c_crud,
)
from capellacollab.projects.toolmodels.modelsources.t4c import (
models as models_t4c_models,
)
from capellacollab.settings.modelsources.t4c import crud as t4c_crud
from capellacollab.settings.modelsources.t4c import (
exceptions as settings_t4c_exceptions,
Expand Down Expand Up @@ -260,6 +266,22 @@ def test_patch_t4c_instance_already_existing_name(
assert "name already used" in detail["title"]


@pytest.mark.usefixtures("admin")
def test_delete_t4c_instance(
client: testclient.TestClient,
db: orm.Session,
t4c_instance: t4c_models.DatabaseT4CInstance,
t4c_model: models_t4c_models.DatabaseT4CModel,
):
response = client.delete(
f"/api/v1/settings/modelsources/t4c/{t4c_instance.id}",
)

assert response.status_code == 204
assert t4c_crud.get_t4c_instance_by_id(db, t4c_instance.id) is None
assert models_t4c_crud.get_t4c_model_by_id(db, t4c_model.id) is None


def test_injectables_raise_when_archived_instance(
db: orm.Session,
executor_name: str,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class T4CInstanceWrapperService {
);

loadInstances(): void {
this._t4cInstances.next(undefined);
this.t4cInstanceService.getT4cInstances().subscribe({
next: (instances) => this._t4cInstances.next(instances),
error: () => this._t4cInstances.next(undefined),
Expand Down
Loading
Loading