mirror of
https://github.com/jlengrand/getting-started-with-github-copilot.git
synced 2026-03-10 08:21:18 +00:00
Add tests for activity signup and unregister functionality
This commit is contained in:
45
tests/test_app.py
Normal file
45
tests/test_app.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from src.app import app
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
def test_get_activities():
|
||||
response = client.get("/activities")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert isinstance(data, dict)
|
||||
assert "Chess Club" in data
|
||||
|
||||
def test_signup_for_activity():
|
||||
email = "newstudent@mergington.edu"
|
||||
activity = "Chess Club"
|
||||
response = client.post(f"/activities/{activity}/signup?email={email}")
|
||||
assert response.status_code == 200
|
||||
assert email in response.json()["message"]
|
||||
# Try signing up again (should fail)
|
||||
response2 = client.post(f"/activities/{activity}/signup?email={email}")
|
||||
assert response2.status_code == 400
|
||||
|
||||
def test_unregister_from_activity():
|
||||
email = "newstudent@mergington.edu"
|
||||
activity = "Chess Club"
|
||||
# Unregister
|
||||
response = client.post(f"/activities/{activity}/unregister?email={email}")
|
||||
assert response.status_code == 200
|
||||
assert email in response.json()["message"]
|
||||
# Try unregistering again (should fail)
|
||||
response2 = client.post(f"/activities/{activity}/unregister?email={email}")
|
||||
assert response2.status_code == 404
|
||||
|
||||
def test_signup_invalid_activity():
|
||||
response = client.post("/activities/Nonexistent/signup?email=test@mergington.edu")
|
||||
assert response.status_code == 404
|
||||
|
||||
def test_unregister_invalid_activity():
|
||||
response = client.post("/activities/Nonexistent/unregister?email=test@mergington.edu")
|
||||
assert response.status_code == 404
|
||||
|
||||
def test_unregister_invalid_participant():
|
||||
response = client.post("/activities/Chess Club/unregister?email=notfound@mergington.edu")
|
||||
assert response.status_code == 404
|
||||
Reference in New Issue
Block a user