File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments