Skip to content

Commit c67a8a2

Browse files
committed
Add more tests to improve coverage
1 parent 411200a commit c67a8a2

File tree

2 files changed

+478
-0
lines changed

2 files changed

+478
-0
lines changed

tests/admin/test_setup_participants.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,17 @@ def test_validate_csv_data_optional_fields(self) -> None:
9999
assert is_valid is True
100100
assert len(errors) == 0
101101

102+
def test_validate_csv_data_extra_columns(self) -> None:
103+
"""Test validation with extra columns (should warn but pass)."""
104+
csv_data = """github_handle,team_name,extra_column
105+
user1,team-a,extra_value"""
106+
df = pd.read_csv(StringIO(csv_data))
107+
108+
is_valid, errors = validate_csv_data(df)
109+
110+
assert is_valid is True
111+
assert len(errors) == 0
112+
102113

103114
class TestGroupParticipantsByTeam:
104115
"""Tests for group_participants_by_team function."""
@@ -327,6 +338,31 @@ def test_skip_participants_when_team_not_found(
327338
assert success_count == 0
328339
assert failed_count == 1
329340

341+
def test_create_participants_with_team_check_error(
342+
self, mock_firestore_client: Mock
343+
) -> None:
344+
"""Test handling error when checking if team exists."""
345+
teams_data = {
346+
"team-a": [
347+
{"github_handle": "user1", "email": "[email protected]"},
348+
],
349+
}
350+
351+
# Mock team ref that raises error on get()
352+
mock_team_ref = Mock()
353+
mock_team_ref.get.side_effect = Exception("Firestore error")
354+
355+
mock_collection = Mock()
356+
mock_collection.document.return_value = mock_team_ref
357+
mock_firestore_client.collection.return_value = mock_collection
358+
359+
success_count, failed_count = create_or_update_participants(
360+
mock_firestore_client, teams_data, dry_run=False
361+
)
362+
363+
assert success_count == 0
364+
assert failed_count == 1
365+
330366

331367
class TestDisplaySummaryTable:
332368
"""Tests for display_summary_table function."""
@@ -462,3 +498,52 @@ def test_setup_participants_firestore_connection_error(
462498
exit_code = setup_participants_from_csv(str(csv_file))
463499

464500
assert exit_code == 1
501+
502+
def test_setup_participants_csv_read_error(self, tmp_path: Path) -> None:
503+
"""Test CSV read error."""
504+
csv_file = tmp_path / "invalid.csv"
505+
csv_file.write_text("invalid,csv,data\nwith,bad,structure\n")
506+
507+
# Create malformed CSV that pandas can't parse properly
508+
with patch(
509+
"aieng_platform_onboard.admin.setup_participants.pd.read_csv",
510+
side_effect=Exception("CSV parse error"),
511+
):
512+
exit_code = setup_participants_from_csv(str(csv_file))
513+
514+
assert exit_code == 1
515+
516+
def test_setup_participants_with_failures(
517+
self, tmp_path: Path, mock_firestore_client: Mock
518+
) -> None:
519+
"""Test setup with some failed participants."""
520+
csv_file = tmp_path / "participants.csv"
521+
csv_file.write_text(
522+
"github_handle,team_name,email\nuser1,team-a,[email protected]"
523+
)
524+
525+
# Mock team existence check - team doesn't exist
526+
mock_team_doc = Mock()
527+
mock_team_doc.exists = False
528+
mock_team_ref = Mock()
529+
mock_team_ref.get.return_value = mock_team_doc
530+
531+
with (
532+
patch(
533+
"aieng_platform_onboard.admin.setup_participants.get_firestore_client",
534+
return_value=mock_firestore_client,
535+
),
536+
patch(
537+
"aieng_platform_onboard.admin.setup_participants.get_team_by_name",
538+
return_value=None,
539+
),
540+
):
541+
# Mock collection and document for team existence check
542+
mock_collection = Mock()
543+
mock_collection.document.return_value = mock_team_ref
544+
mock_firestore_client.collection.return_value = mock_collection
545+
546+
exit_code = setup_participants_from_csv(str(csv_file), dry_run=False)
547+
548+
# Should fail because team doesn't exist
549+
assert exit_code == 1

0 commit comments

Comments
 (0)