-
Notifications
You must be signed in to change notification settings - Fork 0
Add capacity validation and extra tests #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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"} | ||||||||||||||
| ) | ||||||||||||||
| 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""" | ||||||||||||||
|
||||||||||||||
| """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
AI
Jan 13, 2026
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.