Skip to content

Commit 9d8c5b3

Browse files
Added tests for a couple read routes in main.py
1 parent 5805368 commit 9d8c5b3

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/test_main.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from fastapi.testclient import TestClient
2+
3+
from utils.models import User
4+
from main import app
5+
6+
7+
def test_read_profile_unauthorized(unauth_client: TestClient):
8+
"""Test that unauthorized users cannot view profile"""
9+
response = unauth_client.get(app.url_path_for(
10+
"read_profile"), follow_redirects=False)
11+
assert response.status_code == 303 # Redirect to login
12+
assert response.headers["location"] == app.url_path_for("read_login")
13+
14+
15+
def test_read_profile_authorized(auth_client: TestClient, test_user: User):
16+
"""Test that authorized users can view their profile"""
17+
response = auth_client.get(app.url_path_for("read_profile"))
18+
assert response.status_code == 200
19+
# Check that the response contains the expected HTML content
20+
assert test_user.email in response.text
21+
assert test_user.name in response.text

0 commit comments

Comments
 (0)