Skip to content

Commit

Permalink
fix: Pass selected revision to the session container
Browse files Browse the repository at this point in the history
Instead of the default branch for a git model.
  • Loading branch information
amolenaar committed Oct 5, 2023
1 parent 7e0cc6a commit 8b9618a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
6 changes: 3 additions & 3 deletions backend/capellacollab/sessions/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
34 changes: 34 additions & 0 deletions backend/tests/sessions/test_sessions_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8b9618a

Please sign in to comment.