From d88a763c9a8f5d086beb3ca98d60a36611ccc395 Mon Sep 17 00:00:00 2001 From: Dhruvkumar-Microsoft Date: Fri, 14 Aug 2026 09:54:33 +0530 Subject: [PATCH 1/2] updated the testcases --- .../backend/services/test_team_service.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/tests/backend/services/test_team_service.py b/src/tests/backend/services/test_team_service.py index 4c6222954..90bef1834 100644 --- a/src/tests/backend/services/test_team_service.py +++ b/src/tests/backend/services/test_team_service.py @@ -329,6 +329,7 @@ class TestTeamCrudOperations: @pytest.mark.asyncio async def test_save_team_configuration_success(self): mock_context = MagicMock() + mock_context.get_team = AsyncMock(return_value=None) mock_context.add_team = AsyncMock() service = TeamService(memory_context=mock_context) @@ -337,9 +338,44 @@ async def test_save_team_configuration_success(self): assert result == "test-id-123" mock_context.add_team.assert_called_once_with(team_config) + @pytest.mark.asyncio + async def test_save_team_configuration_upserts_when_team_exists(self): + existing = MockTeamConfiguration( + id="existing-doc-id", + session_id="existing-session", + team_id="team-1", + created="2024-01-01T00:00:00Z", + created_by="original-user", + ) + mock_context = MagicMock() + mock_context.get_team = AsyncMock(return_value=existing) + mock_context.update_team = AsyncMock() + mock_context.add_team = AsyncMock() + service = TeamService(memory_context=mock_context) + + team_config = MockTeamConfiguration( + id="new-doc-id", + session_id="new-session", + team_id="team-1", + name="Updated Team", + created="2025-01-01T00:00:00Z", + created_by="seed-user", + ) + result = await service.save_team_configuration(team_config) + + assert result == "existing-doc-id" + mock_context.update_team.assert_called_once_with(team_config) + mock_context.add_team.assert_not_called() + # Immutable identity fields must be preserved from the existing document. + assert team_config.id == "existing-doc-id" + assert team_config.session_id == "existing-session" + assert team_config.created == "2024-01-01T00:00:00Z" + assert team_config.created_by == "original-user" + @pytest.mark.asyncio async def test_save_team_configuration_raises_on_db_error(self): mock_context = MagicMock() + mock_context.get_team = AsyncMock(return_value=None) mock_context.add_team = AsyncMock(side_effect=Exception("DB error")) service = TeamService(memory_context=mock_context) From 08175b20e0a368f292ad51b8af8ba68d947d0e20 Mon Sep 17 00:00:00 2001 From: Dhruvkumar-Microsoft Date: Fri, 14 Aug 2026 10:05:44 +0530 Subject: [PATCH 2/2] resolved the copilot comments --- .../post-provision/upload_team_config.py | 30 ------------------- 1 file changed, 30 deletions(-) diff --git a/infra/scripts/post-provision/upload_team_config.py b/infra/scripts/post-provision/upload_team_config.py index 111986a35..5dccef39d 100644 --- a/infra/scripts/post-provision/upload_team_config.py +++ b/infra/scripts/post-provision/upload_team_config.py @@ -34,36 +34,6 @@ def request_with_retry(method, url, **kwargs): return response -def check_team_exists(backend_url, team_id, user_principal_id): - """ - Check if a team already exists in the database. - - Args: - backend_url: The backend endpoint URL - team_id: The team ID to check - user_principal_id: User principal ID for authentication - - Returns: - exists: bool - """ - check_endpoint = backend_url.rstrip('/') + f'/api/v4/team_configs/{team_id}' - headers = { - 'x-ms-client-principal-id': user_principal_id - } - - try: - response = request_with_retry("GET", check_endpoint, headers=headers) - if response.status_code == 200: - return True - elif response.status_code == 404: - return False - else: - print(f"Error checking team {team_id}: Status {response.status_code}, Response: {response.text}") - return False - except Exception as e: - print(f"Exception checking team {team_id}: {str(e)}") - return False - if len(sys.argv) < 3: print("Usage: python upload_team_config.py [] []") sys.exit(1)