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:
135
tests/integration/test_participant_list.py
Normal file
135
tests/integration/test_participant_list.py
Normal file
@@ -0,0 +1,135 @@
|
||||
"""Integration tests for participant list functionality."""
|
||||
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from flask import url_for
|
||||
|
||||
|
||||
def test_participant_list_shows_all_active(
|
||||
client, auth_participant, participant_factory
|
||||
):
|
||||
"""Test participant list shows all active participants."""
|
||||
# auth_participant fixture creates session and one participant
|
||||
exchange = auth_participant.exchange
|
||||
|
||||
# Create 2 more active participants
|
||||
participant_factory(exchange=exchange, name="Bob")
|
||||
participant_factory(exchange=exchange, name="Charlie")
|
||||
|
||||
response = client.get(url_for("participant.dashboard", id=exchange.id))
|
||||
|
||||
assert response.status_code == 200
|
||||
assert b"Bob" in response.data
|
||||
assert b"Charlie" in response.data
|
||||
assert b"Participants (3)" in response.data
|
||||
|
||||
|
||||
def test_participant_list_excludes_withdrawn(
|
||||
client, auth_participant, participant_factory
|
||||
):
|
||||
"""Test withdrawn participants are not shown."""
|
||||
exchange = auth_participant.exchange
|
||||
|
||||
# Create active and withdrawn participants
|
||||
participant_factory(exchange=exchange, name="Active")
|
||||
participant_factory(
|
||||
exchange=exchange, name="Withdrawn", withdrawn_at=datetime.now(UTC)
|
||||
)
|
||||
|
||||
response = client.get(url_for("participant.dashboard", id=exchange.id))
|
||||
|
||||
assert response.status_code == 200
|
||||
assert b"Active" in response.data
|
||||
assert b"Withdrawn" not in response.data
|
||||
# Count should be 2 (auth_participant + Active)
|
||||
assert b"Participants (2)" in response.data
|
||||
|
||||
|
||||
def test_participant_list_shows_self_badge(client, auth_participant):
|
||||
"""Test participant list marks current user with badge."""
|
||||
exchange = auth_participant.exchange
|
||||
|
||||
response = client.get(url_for("participant.dashboard", id=exchange.id))
|
||||
|
||||
assert response.status_code == 200
|
||||
# Should show the participant's name
|
||||
assert auth_participant.name.encode() in response.data
|
||||
# Should show "You" badge
|
||||
assert b"You" in response.data
|
||||
|
||||
|
||||
def test_participant_list_ordered_by_name(
|
||||
client, auth_participant, participant_factory
|
||||
):
|
||||
"""Test participants are shown in alphabetical order."""
|
||||
exchange = auth_participant.exchange
|
||||
|
||||
# Create participants with names that should be sorted
|
||||
participant_factory(exchange=exchange, name="Zoe")
|
||||
participant_factory(exchange=exchange, name="Alice")
|
||||
participant_factory(exchange=exchange, name="Bob")
|
||||
|
||||
response = client.get(url_for("participant.dashboard", id=exchange.id))
|
||||
|
||||
assert response.status_code == 200
|
||||
# Check order by finding positions in response
|
||||
data = response.data.decode()
|
||||
alice_pos = data.find("Alice")
|
||||
bob_pos = data.find("Bob")
|
||||
zoe_pos = data.find("Zoe")
|
||||
|
||||
# All should be present
|
||||
assert alice_pos > 0
|
||||
assert bob_pos > 0
|
||||
assert zoe_pos > 0
|
||||
|
||||
# Should be in alphabetical order
|
||||
assert alice_pos < bob_pos < zoe_pos
|
||||
|
||||
|
||||
def test_participant_list_empty_state(client, exchange_factory, participant_factory):
|
||||
"""Test message shown when only one participant."""
|
||||
exchange = exchange_factory(state="registration_open")
|
||||
participant = participant_factory(exchange=exchange)
|
||||
|
||||
# Create session for the only participant
|
||||
with client.session_transaction() as session:
|
||||
session["user_id"] = participant.id
|
||||
session["user_type"] = "participant"
|
||||
session["exchange_id"] = exchange.id
|
||||
|
||||
response = client.get(url_for("participant.dashboard", id=exchange.id))
|
||||
|
||||
assert response.status_code == 200
|
||||
assert b"Participants (1)" in response.data
|
||||
# Should show participant's own name
|
||||
assert participant.name.encode() in response.data
|
||||
|
||||
|
||||
def test_participant_list_requires_auth(client, exchange_factory):
|
||||
"""Test participant list requires authentication."""
|
||||
exchange = exchange_factory()
|
||||
|
||||
response = client.get(
|
||||
url_for("participant.dashboard", id=exchange.id), follow_redirects=False
|
||||
)
|
||||
|
||||
# Should redirect to login (or show error)
|
||||
assert response.status_code in [302, 403]
|
||||
|
||||
|
||||
def test_participant_list_different_exchange(
|
||||
client, auth_participant, exchange_factory, participant_factory
|
||||
):
|
||||
"""Test participants filtered by exchange."""
|
||||
exchange1 = auth_participant.exchange
|
||||
exchange2 = exchange_factory(state="registration_open")
|
||||
|
||||
# Create participant in different exchange
|
||||
participant_factory(exchange=exchange2, name="Other Exchange")
|
||||
|
||||
response = client.get(url_for("participant.dashboard", id=exchange1.id))
|
||||
|
||||
assert response.status_code == 200
|
||||
# Should not show participant from other exchange
|
||||
assert b"Other Exchange" not in response.data
|
||||
Reference in New Issue
Block a user