diff --git a/foxglove/client/api.py b/foxglove/client/api.py index 9f84255..e3f066e 100644 --- a/foxglove/client/api.py +++ b/foxglove/client/api.py @@ -1301,6 +1301,7 @@ def update_session( session_id: Optional[str] = None, session_key: Optional[str] = None, project_id: str, + new_key: Optional[str] = None, add_recording_ids: Optional[List[str]] = None, remove_recording_ids: Optional[List[str]] = None, properties: Optional[Dict[str, Union[str, bool, float, int]]] = None, @@ -1308,8 +1309,9 @@ def update_session( """Updates a session. session_id: The ID of the session to update. - session_key: The key of the session to update. + session_key: The current key of the session to update. project_id: The Project ID to which the session belongs. + new_key: Optional new user-supplied identifier, unique within the project. add_recording_ids: IDs of recordings to add to the session. remove_recording_ids: IDs of recordings to remove from the session. properties: Optional custom properties to add to or edit on the session. @@ -1319,6 +1321,7 @@ def update_session( identifier = _session_identifier_for_path(session_id, session_key) params = { + "key": new_key, "addRecordingIds": add_recording_ids, "removeRecordingIds": remove_recording_ids, "properties": properties, diff --git a/tests/test_sessions.py b/tests/test_sessions.py index 4cecbfc..bec3c27 100644 --- a/tests/test_sessions.py +++ b/tests/test_sessions.py @@ -178,6 +178,59 @@ def test_update_session(): assert result["properties"] == props +@responses.activate +def test_update_session_key(): + session_id = fake.uuid4() + project_id = fake.uuid4() + new_key = "renamed-session" + s = _make_session_json( + session_id=session_id, + project_id=project_id, + key=new_key, + ) + responses.add( + responses.PATCH, + api_url(f"/v1/sessions/{session_id}"), + match=[ + query_string_matcher(f"projectId={project_id}"), + json_params_matcher({"key": new_key}), + ], + json=s, + ) + client = Client("test") + result = client.update_session( + session_id=session_id, + project_id=project_id, + new_key=new_key, + ) + assert result["id"] == session_id + assert result["key"] == new_key + + +@responses.activate +def test_update_session_key_by_existing_key(): + session_key = "old-session" + new_key = "new-session" + project_id = fake.uuid4() + s = _make_session_json(key=new_key, project_id=project_id) + responses.add( + responses.PATCH, + api_url(f"/v1/sessions/{session_key}"), + match=[ + query_string_matcher(f"projectId={project_id}"), + json_params_matcher({"key": new_key}), + ], + json=s, + ) + client = Client("test") + result = client.update_session( + session_key=session_key, + project_id=project_id, + new_key=new_key, + ) + assert result["key"] == new_key + + @responses.activate def test_delete_session(): session_id = fake.uuid4()