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
4 changes: 4 additions & 0 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ def signup_for_activity(activity_name: str, email: str):
# Get the specific activity
activity = activities[activity_name]

# Check if activity is at capacity
if len(activity["participants"]) >= activity["max_participants"]:
raise HTTPException(status_code=400, detail="Activity is at full capacity")

# Add student
#Validate student hasn't already signed up
if email in activity["participants"]:
Expand Down
53 changes: 52 additions & 1 deletion tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,55 @@ def test_root_redirect():
client_no_redirect = TestClient(app, follow_redirects=False)
response = client_no_redirect.get("/")
assert response.status_code == 307 # Temporary redirect
assert "/static/index.html" in response.headers["location"]
assert "/static/index.html" in response.headers["location"]

def test_activity_capacity_limit():
"""Test that signup fails when activity reaches max capacity"""
# Use an activity with low capacity
activity_name = "Chess Club" # Has max_participants: 12, but already has 2 participants

# Fill up the remaining spots (12 - 2 = 10 spots left)
for i in range(10):
response = client.post(
f"/activities/{activity_name}/signup",
params={"email": f"student{i}@test.edu"}
)
assert response.status_code == 200

# Try to sign up one more (should fail)
response = client.post(
f"/activities/{activity_name}/signup",
params={"email": "overflow@test.edu"}
Comment on lines +125 to +139
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test assumes Chess Club has exactly 2 participants at the start, but since tests share state and there's no test isolation mechanism, previous tests may have modified the participants list. This test could fail or behave unpredictably depending on test execution order. Consider using a fresh activity or resetting state in a fixture, or selecting an activity that isn't used by other tests.

Suggested change
# Use an activity with low capacity
activity_name = "Chess Club" # Has max_participants: 12, but already has 2 participants
# Fill up the remaining spots (12 - 2 = 10 spots left)
for i in range(10):
response = client.post(
f"/activities/{activity_name}/signup",
params={"email": f"student{i}@test.edu"}
)
assert response.status_code == 200
# Try to sign up one more (should fail)
response = client.post(
f"/activities/{activity_name}/signup",
params={"email": "overflow@test.edu"}
# Use an activity with known capacity
activity_name = "Chess Club"
# Get current state of the activity to avoid assumptions about initial participants
activities_response = client.get("/activities")
assert activities_response.status_code == 200
activities_data = activities_response.json()
assert activity_name in activities_data
activity = activities_data[activity_name]
max_participants = activity["max_participants"]
current_participants = len(activity["participants"])
# Fill up the remaining spots based on current state
remaining_spots = max(0, max_participants - current_participants)
for i in range(remaining_spots):
response = client.post(
f"/activities/{activity_name}/signup",
params={"email": f"capacity_test_student{i}@test.edu"}
)
assert response.status_code == 200
# Try to sign up one more (should fail due to capacity limit)
response = client.post(
f"/activities/{activity_name}/signup",
params={"email": "overflow_capacity_test@test.edu"}

Copilot uses AI. Check for mistakes.
)
assert response.status_code == 400
data = response.json()
assert "capacity" in data["detail"].lower() or "full" in data["detail"].lower()

def test_static_files_served():
"""Test that static files are served correctly"""
# Test HTML file
response = client.get("/static/index.html")
assert response.status_code == 200
assert "Mergington High School" in response.text
assert "Extracurricular Activities" in response.text

# Test CSS file
response = client.get("/static/styles.css")
assert response.status_code == 200
assert "box-sizing" in response.text

# Test JS file
response = client.get("/static/app.js")
assert response.status_code == 200
assert "DOMContentLoaded" in response.text

def test_signup_empty_email():
"""Test signup with empty email"""
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring doesn't describe what the expected behavior should be when signing up with an empty email. Update the docstring to clarify whether empty emails should be accepted or rejected.

Suggested change
"""Test signup with empty email"""
"""Test that signing up with an empty email is handled gracefully.
The application may either reject the request with a 400 error or accept it
with a 200 response, but it must not crash when an empty email is provided.
"""

Copilot uses AI. Check for mistakes.
activity_name = "Basketball Team"
response = client.post(
f"/activities/{activity_name}/signup",
params={"email": ""}
)
# This should either fail validation or succeed depending on implementation
# For now, just check it doesn't crash
assert response.status_code in [200, 400]
Comment on lines +170 to +172
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is too permissive and doesn't actually validate the expected behavior for empty email addresses. It should either verify that empty emails are rejected with a 400 status (if validation is intended) or succeed with 200 (if empty emails are allowed). The current assertion provides no meaningful coverage.

Copilot uses AI. Check for mistakes.
Loading