Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions infra/scripts/post-provision/upload_team_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <backend_endpoint> <directory_path> [<user_principal_id>] [<team_id_from_arg>]")
sys.exit(1)
Expand Down
36 changes: 36 additions & 0 deletions src/tests/backend/services/test_team_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down