From 8b9618a574cd799af506154492de74d88c8f2f85 Mon Sep 17 00:00:00 2001 From: Arjan Molenaar Date: Thu, 5 Oct 2023 17:13:58 +0200 Subject: [PATCH] fix: Pass selected revision to the session container Instead of the default branch for a git model. --- backend/capellacollab/sessions/routes.py | 6 ++-- .../tests/sessions/test_sessions_routes.py | 34 +++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/backend/capellacollab/sessions/routes.py b/backend/capellacollab/sessions/routes.py index 36aa16e817..c1149f6397 100644 --- a/backend/capellacollab/sessions/routes.py +++ b/backend/capellacollab/sessions/routes.py @@ -257,15 +257,15 @@ def models_as_json( ) ): continue - yield git_model_as_json(git_model, entry.deep_clone) + yield git_model_as_json(git_model, entry.revision, entry.deep_clone) def git_model_as_json( - git_model: git_models.DatabaseGitModel, deep_clone: bool + git_model: git_models.DatabaseGitModel, revision: str, deep_clone: bool ) -> dict[str, str | int]: d = { "url": git_model.path, - "revision": git_model.revision, + "revision": revision or git_model.revision, "depth": 0 if deep_clone else 1, "entrypoint": git_model.entrypoint, "nature": git_model.model.nature.name, diff --git a/backend/tests/sessions/test_sessions_routes.py b/backend/tests/sessions/test_sessions_routes.py index 1b81017e25..7577d2936c 100644 --- a/backend/tests/sessions/test_sessions_routes.py +++ b/backend/tests/sessions/test_sessions_routes.py @@ -344,6 +344,40 @@ def test_create_persistent_session_as_user( assert "/capella/remote:5.0.0" in kubernetes.sessions[0]["docker_image"] +def test_create_read_only_session_as_user( + client: testclient.TestClient, + db, + user, + kubernetes, +): + response = client.post( + "/api/v1/projects/default/sessions/readonly", + json={ + "models": [ + { + "model_slug": "meldody-model-test-6-0-0", + "git_model_id": 3, + "revision": "test-branch", + "deep_clone": False, + } + ] + }, + ) + out = response.json() + session = get_session_by_id(db, out["id"]) + + assert response.status_code == 200 + assert session + assert session.owner_name == user.name + assert kubernetes.sessions + + assert "/capella/readonly:6.0.0" in kubernetes.sessions[0]["docker_image"] + assert ( + '"revision": "test-branch"' + in kubernetes.sessions[0]["environment"]["GIT_REPOS_JSON"] + ) + + def test_create_persistent_jupyter_session(client, db, user, kubernetes): jupyter = create_tool( db,