Skip to content

Commit

Permalink
fix: Remove file ending in diagram route
Browse files Browse the repository at this point in the history
When using the diagram cache the route should not run into errors  when calling diagrams with a file ending or without.
  • Loading branch information
Paula-Kli committed Oct 12, 2023
1 parent 772b922 commit ab4b4a4
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
7 changes: 5 additions & 2 deletions backend/capellacollab/projects/toolmodels/diagrams/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,17 @@ async def get_diagram_metadata(
)


@router.get("/{diagram_uuid}", response_class=fastapi.responses.Response)
@router.get(
"/{diagram_uuid_or_filename}", response_class=fastapi.responses.Response
)
async def get_diagram(
diagram_uuid: str,
diagram_uuid_or_filename: str,
handler: git_handler.GitHandler = fastapi.Depends(
git_injectables.get_git_handler
),
logger: logging.LoggerAdapter = fastapi.Depends(log.get_request_logger),
):
diagram_uuid = diagram_uuid_or_filename.split(".")[0]
try:
_, diagram = await handler.get_file_from_repository_or_artifacts(
f"diagram_cache/{parse.quote(diagram_uuid, safe='')}.svg",
Expand Down
58 changes: 58 additions & 0 deletions backend/tests/projects/toolmodels/test_diagrams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit ab4b4a4

Please sign in to comment.