Skip to content

Add capacity validation and extra tests#2

Merged
h-urena merged 1 commit into
mainfrom
accelerate-with-copilot
Jan 13, 2026
Merged

Add capacity validation and extra tests#2
h-urena merged 1 commit into
mainfrom
accelerate-with-copilot

Conversation

@h-urena
Copy link
Copy Markdown
Owner

@h-urena h-urena commented Jan 13, 2026

This pull request adds a check to prevent users from signing up for an activity that has reached its maximum capacity and introduces new tests to verify this behavior, as well as tests for static file serving and email validation.

Activity capacity enforcement:

  • Added a check in signup_for_activity (in src/app.py) to raise an HTTP 400 error if the activity is at full capacity, preventing further signups.

Testing improvements:

  • Added test_activity_capacity_limit in tests/test_app.py to verify that signups are blocked when an activity reaches its maximum number of participants.
  • Added test_static_files_served to ensure that HTML, CSS, and JS static files are correctly served by the application.
  • Added test_signup_empty_email to check application behavior when attempting to sign up with an empty email address.

- Add capacity limit validation to signup endpoint
- Add tests for capacity limits and static file serving
@h-urena h-urena requested a review from Copilot January 13, 2026 17:34
@h-urena h-urena merged commit b84d590 into main Jan 13, 2026
6 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds capacity validation to prevent activity signups when maximum capacity is reached, and introduces three new test cases to improve test coverage.

Changes:

  • Added capacity check in signup_for_activity to block signups when an activity is full
  • Added test to verify capacity limit enforcement
  • Added test to verify static file serving
  • Added test to check empty email behavior

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/app.py Added capacity validation before allowing signups
tests/test_app.py Added three new tests for capacity limits, static file serving, and empty email handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_app.py
Comment on lines +125 to +139
# 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"}
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.
Comment thread tests/test_app.py
Comment on lines +170 to +172
# 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] No newline at end of file
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.
Comment thread tests/test_app.py
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants