feat: implement Phase 3 participant self-management (stories 4.5, 6.1)
Implemented features: - Story 4.5: View Participant List - participants can see other active participants - Story 6.1: Update Profile - participants can edit name and gift ideas before matching - Utility functions for state management and business logic - Comprehensive unit and integration tests New files: - src/utils/participant.py - Business logic utilities - src/templates/participant/profile_edit.html - Profile edit form - tests/unit/test_participant_utils.py - Unit tests for utilities - tests/integration/test_participant_list.py - Integration tests for participant list - tests/integration/test_profile_update.py - Integration tests for profile updates Modified files: - src/routes/participant.py - Added dashboard participant list and profile edit route - src/templates/participant/dashboard.html - Added participant list section and edit link - src/forms/participant.py - Added ProfileUpdateForm - src/app.py - Added participant.profile_edit to setup check exemptions - tests/conftest.py - Added exchange_factory, participant_factory, auth_participant fixtures All tests passing. Phase 3.3 (reminder preferences) and 3.4 (withdrawal) remain to be implemented. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -75,3 +75,97 @@ def admin(db):
|
||||
db.session.add(admin)
|
||||
db.session.commit()
|
||||
return admin
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def exchange_factory(db):
|
||||
"""Factory for creating test exchanges.
|
||||
|
||||
Args:
|
||||
db: Database instance.
|
||||
|
||||
Returns:
|
||||
Function that creates and returns Exchange instances.
|
||||
"""
|
||||
from datetime import UTC, datetime, timedelta
|
||||
|
||||
from src.models.exchange import Exchange
|
||||
|
||||
def _create(state="draft", **kwargs):
|
||||
exchange = Exchange(
|
||||
slug=kwargs.get("slug", Exchange.generate_slug()),
|
||||
name=kwargs.get("name", "Test Exchange"),
|
||||
budget=kwargs.get("budget", "$25-50"),
|
||||
max_participants=kwargs.get("max_participants", 50),
|
||||
registration_close_date=kwargs.get(
|
||||
"registration_close_date", datetime.now(UTC) + timedelta(days=7)
|
||||
),
|
||||
exchange_date=kwargs.get(
|
||||
"exchange_date", datetime.now(UTC) + timedelta(days=14)
|
||||
),
|
||||
timezone=kwargs.get("timezone", "UTC"),
|
||||
state=state,
|
||||
)
|
||||
db.session.add(exchange)
|
||||
db.session.commit()
|
||||
return exchange
|
||||
|
||||
return _create
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def participant_factory(db, exchange_factory):
|
||||
"""Factory for creating test participants.
|
||||
|
||||
Args:
|
||||
db: Database instance.
|
||||
exchange_factory: Exchange factory fixture.
|
||||
|
||||
Returns:
|
||||
Function that creates and returns Participant instances.
|
||||
"""
|
||||
from src.models.participant import Participant
|
||||
|
||||
counter = {"value": 0}
|
||||
|
||||
def _create(exchange=None, **kwargs):
|
||||
if not exchange:
|
||||
exchange = exchange_factory()
|
||||
|
||||
counter["value"] += 1
|
||||
participant = Participant(
|
||||
exchange_id=exchange.id,
|
||||
name=kwargs.get("name", f"Test Participant {counter['value']}"),
|
||||
email=kwargs.get("email", f"test{counter['value']}@example.com"),
|
||||
gift_ideas=kwargs.get("gift_ideas", "Test ideas"),
|
||||
reminder_enabled=kwargs.get("reminder_enabled", True),
|
||||
withdrawn_at=kwargs.get("withdrawn_at"),
|
||||
)
|
||||
db.session.add(participant)
|
||||
db.session.commit()
|
||||
return participant
|
||||
|
||||
return _create
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def auth_participant(client, exchange_factory, participant_factory):
|
||||
"""Create an authenticated participant session.
|
||||
|
||||
Args:
|
||||
client: Flask test client.
|
||||
exchange_factory: Exchange factory fixture.
|
||||
participant_factory: Participant factory fixture.
|
||||
|
||||
Returns:
|
||||
Authenticated participant instance.
|
||||
"""
|
||||
exchange = exchange_factory(state="registration_open")
|
||||
participant = participant_factory(exchange=exchange)
|
||||
|
||||
with client.session_transaction() as session:
|
||||
session["user_id"] = participant.id
|
||||
session["user_type"] = "participant"
|
||||
session["exchange_id"] = exchange.id
|
||||
|
||||
return participant
|
||||
|
||||
Reference in New Issue
Block a user