Repository navigation
Improve student activity registration system #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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| fastapi | ||
| uvicorn | ||
| httpx | ||
| watchfiles | ||
| watchfiles | ||
| pytest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import copy | ||
|
|
||
| import pytest | ||
| from fastapi.testclient import TestClient | ||
|
|
||
| from src import app as app_module | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def client(): | ||
| return TestClient(app_module.app) | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def reset_activities(): | ||
| original_activities = copy.deepcopy(app_module.activities) | ||
| yield | ||
| app_module.activities.clear() | ||
| app_module.activities.update(copy.deepcopy(original_activities)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| from urllib.parse import quote | ||
|
|
||
|
|
||
| def test_get_activities_returns_activity_map(client): | ||
| response = client.get("/activities") | ||
|
|
||
| assert response.status_code == 200 | ||
| activities = response.json() | ||
| assert isinstance(activities, dict) | ||
| assert "Chess Club" in activities | ||
| assert "participants" in activities["Chess Club"] | ||
|
|
||
|
|
||
| def test_signup_adds_participant(client): | ||
| activity_name = "Chess Club" | ||
| email = "new-student@mergington.edu" | ||
|
|
||
| response = client.post( | ||
| f"/activities/{quote(activity_name, safe='')}/signup", | ||
| params={"email": email}, | ||
| ) | ||
|
|
||
| assert response.status_code == 200 | ||
| assert response.json() == {"message": f"Signed up {email} for {activity_name}"} | ||
|
|
||
| activities_response = client.get("/activities") | ||
| participants = activities_response.json()[activity_name]["participants"] | ||
| assert email in participants | ||
|
|
||
|
|
||
| def test_signup_unknown_activity_returns_404(client): | ||
| response = client.post( | ||
| f"/activities/{quote('Unknown Club', safe='')}/signup", | ||
| params={"email": "student@mergington.edu"}, | ||
| ) | ||
|
|
||
| assert response.status_code == 404 | ||
| assert response.json() == {"detail": "Activity not found"} | ||
|
|
||
|
|
||
| def test_signup_duplicate_participant_returns_400(client): | ||
| activity_name = "Chess Club" | ||
| existing_email = "michael@mergington.edu" | ||
|
|
||
| response = client.post( | ||
| f"/activities/{quote(activity_name, safe='')}/signup", | ||
| params={"email": existing_email}, | ||
| ) | ||
|
|
||
| assert response.status_code == 400 | ||
| assert response.json() == {"detail": "Student already signed up for this activity"} | ||
|
|
||
|
|
||
| def test_unregister_removes_participant(client): | ||
| activity_name = "Chess Club" | ||
| email = "temp-removal@mergington.edu" | ||
| encoded_activity = quote(activity_name, safe="") | ||
|
|
||
| signup_response = client.post( | ||
| f"/activities/{encoded_activity}/signup", | ||
| params={"email": email}, | ||
| ) | ||
| assert signup_response.status_code == 200 | ||
|
|
||
| delete_response = client.delete( | ||
| f"/activities/{encoded_activity}/participants", | ||
| params={"email": email}, | ||
| ) | ||
|
|
||
| assert delete_response.status_code == 200 | ||
| assert delete_response.json() == {"message": f"Unregistered {email} from {activity_name}"} | ||
|
|
||
| activities_response = client.get("/activities") | ||
| participants = activities_response.json()[activity_name]["participants"] | ||
| assert email not in participants | ||
|
|
||
|
|
||
| def test_unregister_unknown_activity_returns_404(client): | ||
| response = client.delete( | ||
| f"/activities/{quote('Unknown Club', safe='')}/participants", | ||
| params={"email": "student@mergington.edu"}, | ||
| ) | ||
|
|
||
| assert response.status_code == 404 | ||
| assert response.json() == {"detail": "Activity not found"} | ||
|
|
||
|
|
||
| def test_unregister_missing_participant_returns_404(client): | ||
| response = client.delete( | ||
| f"/activities/{quote('Chess Club', safe='')}/participants", | ||
| params={"email": "not-registered@mergington.edu"}, | ||
| ) | ||
|
|
||
| assert response.status_code == 404 | ||
| assert response.json() == {"detail": "Participant not found in this activity"} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.