-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Verify compatibility of TeamForCapella model links at all times
- Loading branch information
1 parent
bc0ea05
commit c75a139
Showing
15 changed files
with
302 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
backend/tests/projects/toolmodels/modelsources/fixtures.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import pytest | ||
from sqlalchemy import orm | ||
|
||
import capellacollab.projects.toolmodels.models as toolmodels_models | ||
import capellacollab.projects.toolmodels.modelsources.git.crud as project_git_crud | ||
import capellacollab.projects.toolmodels.modelsources.git.models as project_git_models | ||
import capellacollab.projects.toolmodels.modelsources.t4c.crud as models_t4c_crud | ||
import capellacollab.projects.toolmodels.modelsources.t4c.models as models_t4c_models | ||
import capellacollab.settings.modelsources.t4c.repositories.models as settings_t4c_repositories_models | ||
|
||
|
||
@pytest.fixture(name="t4c_model") | ||
def fixture_t4c_model( | ||
db: orm.Session, | ||
capella_model: toolmodels_models.DatabaseToolModel, | ||
t4c_repository: settings_t4c_repositories_models.DatabaseT4CRepository, | ||
) -> models_t4c_models.DatabaseT4CModel: | ||
return models_t4c_crud.create_t4c_model( | ||
db, capella_model, t4c_repository, "default" | ||
) | ||
|
||
|
||
@pytest.fixture(name="git_model") | ||
def fixture_git_model( | ||
db: orm.Session, capella_model: toolmodels_models.DatabaseToolModel | ||
) -> project_git_models.DatabaseGitModel: | ||
git_model = project_git_models.PostGitModel( | ||
path="https://example.com/test/project", | ||
entrypoint="test/test.aird", | ||
revision="main", | ||
username="user", | ||
password="password", | ||
) | ||
return project_git_crud.add_git_model_to_capellamodel( | ||
db, capella_model, git_model | ||
) |
186 changes: 186 additions & 0 deletions
186
backend/tests/projects/toolmodels/modelsources/test_t4c_routes.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
|
||
import pytest | ||
from fastapi import testclient | ||
from sqlalchemy import orm | ||
|
||
import capellacollab.projects.models as projects_models | ||
import capellacollab.settings.modelsources.t4c.repositories.crud as t4c_repositories_crud | ||
import capellacollab.settings.modelsources.t4c.repositories.models as t4c_repositories_models | ||
from capellacollab.projects.toolmodels import models as toolmodels_models | ||
from capellacollab.projects.toolmodels.modelsources.t4c import crud as t4c_crud | ||
from capellacollab.projects.toolmodels.modelsources.t4c import ( | ||
models as t4c_models, | ||
) | ||
from capellacollab.settings.modelsources.t4c import crud as t4c_servers_crud | ||
from capellacollab.settings.modelsources.t4c import ( | ||
models as t4c_servers_models, | ||
) | ||
from capellacollab.settings.modelsources.t4c.repositories import ( | ||
models as t4c_repositories_models, | ||
) | ||
from capellacollab.tools import models as tools_models | ||
|
||
|
||
@pytest.mark.usefixtures("project_manager") | ||
def test_list_t4c_models( | ||
client: testclient.TestClient, | ||
project: projects_models.DatabaseProject, | ||
capella_model: toolmodels_models.DatabaseToolModel, | ||
t4c_model: t4c_models.DatabaseT4CModel, | ||
): | ||
response = client.get( | ||
f"/api/v1/projects/{project.slug}/models/{capella_model.slug}/modelsources/t4c" | ||
) | ||
|
||
assert response.status_code == 200 | ||
assert len(response.json()) == 1 | ||
assert response.json()[0]["name"] == t4c_model.name | ||
|
||
|
||
@pytest.mark.usefixtures("project_manager") | ||
def test_get_t4c_model( | ||
client: testclient.TestClient, | ||
project: projects_models.DatabaseProject, | ||
capella_model: toolmodels_models.DatabaseToolModel, | ||
t4c_model: t4c_models.DatabaseT4CModel, | ||
): | ||
response = client.get( | ||
f"/api/v1/projects/{project.slug}/models/{capella_model.slug}/modelsources/t4c/{t4c_model.id}" | ||
) | ||
|
||
assert response.status_code == 200 | ||
assert response.json()["name"] == t4c_model.name | ||
assert ( | ||
response.json()["repository"]["instance"]["id"] | ||
== t4c_model.repository.instance.id | ||
) | ||
|
||
|
||
@pytest.mark.usefixtures("admin") | ||
def test_create_t4c_model( | ||
client: testclient.TestClient, | ||
project: projects_models.DatabaseProject, | ||
t4c_repository: t4c_repositories_models.DatabaseT4CRepository, | ||
capella_model: toolmodels_models.DatabaseToolModel, | ||
): | ||
response = client.post( | ||
f"/api/v1/projects/{project.slug}/models/{capella_model.slug}/modelsources/t4c", | ||
json={ | ||
"name": "project", | ||
"t4c_instance_id": t4c_repository.instance.id, | ||
"t4c_repository_id": t4c_repository.id, | ||
}, | ||
) | ||
|
||
assert response.status_code == 200 | ||
assert response.json()["name"] == "project" | ||
assert response.json()["repository"]["id"] == t4c_repository.id | ||
assert ( | ||
response.json()["repository"]["instance"]["id"] | ||
== t4c_repository.instance.id | ||
) | ||
|
||
|
||
@pytest.mark.usefixtures("admin", "t4c_model") | ||
def test_create_t4c_model_twice_fails( | ||
client: testclient.TestClient, | ||
project: projects_models.DatabaseProject, | ||
t4c_repository: t4c_repositories_models.DatabaseT4CRepository, | ||
capella_model: toolmodels_models.DatabaseToolModel, | ||
): | ||
response = client.post( | ||
f"/api/v1/projects/{project.slug}/models/{capella_model.slug}/modelsources/t4c", | ||
json={ | ||
"name": "default", | ||
"t4c_instance_id": t4c_repository.instance.id, | ||
"t4c_repository_id": t4c_repository.id, | ||
}, | ||
) | ||
|
||
assert response.status_code == 409 | ||
assert ( | ||
response.json()["detail"]["err_code"] | ||
== "T4C_INTEGRATION_ALREADY_EXISTS" | ||
) | ||
|
||
|
||
@pytest.mark.usefixtures("admin") | ||
def test_change_server_of_t4c_model( | ||
db: orm.Session, | ||
client: testclient.TestClient, | ||
project: projects_models.DatabaseProject, | ||
capella_model: toolmodels_models.DatabaseToolModel, | ||
t4c_model: t4c_models.DatabaseT4CModel, | ||
tool_version: tools_models.DatabaseVersion, | ||
): | ||
server = t4c_servers_models.DatabaseT4CInstance( | ||
name="test server 2", | ||
license="lic", | ||
host="localhost", | ||
usage_api="http://localhost:8086", | ||
rest_api="http://localhost:8080/api/v1.0", | ||
username="user", | ||
password="pass", | ||
protocol=t4c_servers_models.Protocol.tcp, | ||
version=tool_version, | ||
) | ||
db_server = t4c_servers_crud.create_t4c_instance(db, server) | ||
|
||
second_t4c_repository = t4c_repositories_crud.create_t4c_repository( | ||
db=db, repo_name="test2", instance=db_server | ||
) | ||
|
||
response = client.patch( | ||
f"/api/v1/projects/{project.slug}/models/{capella_model.slug}/modelsources/t4c/{t4c_model.id}", | ||
json={ | ||
"t4c_instance_id": db_server.id, | ||
"t4c_repository_id": second_t4c_repository.id, | ||
}, | ||
) | ||
|
||
assert response.status_code == 200 | ||
assert response.json()["name"] == t4c_model.name | ||
assert response.json()["repository"]["id"] == second_t4c_repository.id | ||
assert ( | ||
response.json()["repository"]["instance"]["id"] | ||
== second_t4c_repository.instance.id | ||
) | ||
|
||
|
||
@pytest.mark.usefixtures("admin") | ||
def test_patch_name_of_t4c_model( | ||
client: testclient.TestClient, | ||
project: projects_models.DatabaseProject, | ||
capella_model: toolmodels_models.DatabaseToolModel, | ||
t4c_model: t4c_models.DatabaseT4CModel, | ||
): | ||
response = client.patch( | ||
f"/api/v1/projects/{project.slug}/models/{capella_model.slug}/modelsources/t4c/{t4c_model.id}", | ||
json={"name": "new_default"}, | ||
) | ||
|
||
assert response.status_code == 200 | ||
assert response.json()["name"] == "new_default" | ||
assert ( | ||
response.json()["repository"]["instance"]["id"] | ||
== t4c_model.repository.instance.id | ||
) | ||
|
||
|
||
@pytest.mark.usefixtures("admin") | ||
def test_unlink_t4c_model( | ||
db: orm.Session, | ||
client: testclient.TestClient, | ||
project: projects_models.DatabaseProject, | ||
capella_model: toolmodels_models.DatabaseToolModel, | ||
t4c_model: t4c_models.DatabaseT4CModel, | ||
): | ||
response = client.delete( | ||
f"/api/v1/projects/{project.slug}/models/{capella_model.slug}/modelsources/t4c/{t4c_model.id}", | ||
) | ||
|
||
assert response.status_code == 204 | ||
assert t4c_crud.get_t4c_model_by_id(db, t4c_model.id) is None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.