diff --git a/backend/capellacollab/projects/toolmodels/diagrams/routes.py b/backend/capellacollab/projects/toolmodels/diagrams/routes.py index 148cd6aec7..eb06af59c4 100644 --- a/backend/capellacollab/projects/toolmodels/diagrams/routes.py +++ b/backend/capellacollab/projects/toolmodels/diagrams/routes.py @@ -67,14 +67,15 @@ async def get_diagram_metadata( ) -@router.get("/{diagram_uuid}", response_class=fastapi.responses.Response) +@router.get("/{diagram_file_name}", response_class=fastapi.responses.Response) async def get_diagram( - diagram_uuid: str, + diagram_file_name: str, handler: git_handler.GitHandler = fastapi.Depends( git_injectables.get_git_handler ), logger: logging.LoggerAdapter = fastapi.Depends(log.get_request_logger), ): + diagram_uuid = diagram_file_name.rsplit(".", maxsplit=1)[0] try: _, diagram = await handler.get_file_from_repository_or_artifacts( f"diagram_cache/{parse.quote(diagram_uuid, safe='')}.svg", diff --git a/backend/tests/projects/toolmodels/test_diagrams.py b/backend/tests/projects/toolmodels/test_diagrams.py index ee05c737ad..3cd734df81 100644 --- a/backend/tests/projects/toolmodels/test_diagrams.py +++ b/backend/tests/projects/toolmodels/test_diagrams.py @@ -384,6 +384,64 @@ def test_get_single_diagram_from_artifacts( assert response.content == EXAMPLE_SVG +@responses.activate +@pytest.mark.parametrize( + "git_type,git_response_status,git_query_params", + [ + ( + git_models.GitType.GITLAB, + 404, + [ + { + "path": "diagram_cache/index.json", + "ref_name": "diagram-cache/main", + }, + { + "path": "diagram_cache/_c90e4Hdf2d2UosmJBo0GTw.svg", + "ref_name": "diagram-cache/main", + }, + ], + ), + ( + git_models.GitType.GITHUB, + 404, + [ + { + "path": "diagram_cache/index.json", + "sha": "diagram-cache/main", + }, + { + "path": "diagram_cache/_c90e4Hdf2d2UosmJBo0GTw.svg", + "sha": "diagram-cache/main", + }, + ], + ), + ], +) +@pytest.mark.usefixtures( + "project_user", + "git_instance", + "git_model", + "mock_git_diagram_cache_from_repo_api", + "mock_git_rest_api_for_artifacts", + "mock_git_diagram_cache_index_api", + "mock_git_diagram_cache_svg", + "mock_git_get_commit_information_api", +) +@pytest.mark.usefixtures("project_user", "git_instance", "git_model") +def test_get_single_diagram_from_artifacts_with_file_ending( + project: project_models.DatabaseProject, + capella_model: toolmodels_models.CapellaModel, + client: testclient.TestClient, +): + response = client.get( + f"/api/v1/projects/{project.slug}/models/{capella_model.slug}/diagrams/_c90e4Hdf2d2UosmJBo0GTw.svg", + ) + + assert response.status_code == 200 + assert response.content == EXAMPLE_SVG + + @responses.activate @pytest.mark.parametrize( "git_type,git_query_params",