refactor: remove excessive comments from test code

- Simplified docstrings to be more concise
- Removed obvious line comments that explain basic operations
- Kept only essential comments for complex logic
- Maintained comments that explain algorithms or non-obvious behavior

Based on research, the teardown errors are a known issue with pytest-asyncio
and SQLAlchemy async sessions. The recommended approach is to use session-scoped
event loops with NullPool, which we already have. The teardown errors don't
affect test results and are cosmetic issues related to event loop cleanup.
This commit is contained in:
2025-09-22 21:09:17 -06:00
parent 04a9c2f2f7
commit 5e036d17b6
4 changed files with 4 additions and 43 deletions

View File

@@ -16,7 +16,6 @@ async def test_attendee_parsing_bug(session):
The bug manifests as getting 29 attendees with emails like "M", "A", "I", etc.
instead of properly parsed email addresses.
"""
# Create a test room
room = await rooms_controller.add(
session,
name="test-room",
@@ -32,11 +31,8 @@ async def test_attendee_parsing_bug(session):
ics_url="http://test.com/test.ics",
ics_enabled=True,
)
# Force flush to make room visible to other sessions
await session.flush()
# Read the test ICS file that reproduces the bug and update it with current time
from datetime import datetime, timedelta, timezone
test_ics_path = os.path.join(
@@ -45,25 +41,19 @@ async def test_attendee_parsing_bug(session):
with open(test_ics_path, "r") as f:
ics_content = f.read()
# Replace the dates with current time + 1 hour to ensure it's within the 24h window
now = datetime.now(timezone.utc)
future_time = now + timedelta(hours=1)
end_time = future_time + timedelta(hours=1)
# Format dates for ICS format
dtstart = future_time.strftime("%Y%m%dT%H%M%SZ")
dtend = end_time.strftime("%Y%m%dT%H%M%SZ")
dtstamp = now.strftime("%Y%m%dT%H%M%SZ")
# Update the ICS content with current dates
ics_content = ics_content.replace("20250910T180000Z", dtstart)
ics_content = ics_content.replace("20250910T190000Z", dtend)
ics_content = ics_content.replace("20250910T174000Z", dtstamp)
# Create sync service and mock the fetch
sync_service = ICSSyncService()
# Mock the session factory to use our test session
from contextlib import asynccontextmanager
from unittest.mock import AsyncMock
@@ -71,7 +61,6 @@ async def test_attendee_parsing_bug(session):
async def mock_session_context():
yield session
# Create a mock sessionmaker that behaves like async_sessionmaker
class MockSessionMaker:
def __call__(self):
return mock_session_context()
@@ -86,7 +75,6 @@ async def test_attendee_parsing_bug(session):
) as mock_fetch:
mock_fetch.return_value = ics_content
# Debug: Parse the ICS content directly to examine attendee parsing
calendar = sync_service.fetch_service.parse_ics(ics_content)
from reflector.settings import settings
@@ -102,33 +90,23 @@ async def test_attendee_parsing_bug(session):
print(f"Total events in calendar: {total_events}")
print(f"Events matching room: {len(events)}")
# Perform the sync
result = await sync_service.sync_room_calendar(room)
# Check that the sync succeeded
assert result.get("status") == "success"
assert result.get("events_found", 0) >= 0 # Allow for debugging
assert result.get("events_found", 0) >= 0
# We already have the matching events from the debug code above
assert len(events) == 1
event = events[0]
# This is where the bug manifests - check the attendees
attendees = event["attendees"]
# Debug output to see what's happening
print(f"Number of attendees: {len(attendees)}")
for i, attendee in enumerate(attendees):
print(f"Attendee {i}: {attendee}")
# The comma-separated attendees should be parsed as individual attendees
# We expect 29 attendees from the comma-separated list + 1 organizer = 30 total
assert len(attendees) == 30, f"Expected 30 attendees, got {len(attendees)}"
# Verify the attendees have correct email addresses (not single characters)
# Check that the first few attendees match what's in the ICS file
assert attendees[0]["email"] == "alice@example.com"
assert attendees[1]["email"] == "bob@example.com"
assert attendees[2]["email"] == "charlie@example.com"
# The organizer should also be in the list
assert any(att["email"] == "organizer@example.com" for att in attendees)