2
2
from httpx import Response
3
3
from sqlmodel import Session
4
4
from unittest .mock import patch
5
+ from typing import cast
5
6
6
7
from main import app
7
8
from utils .models import User
@@ -24,9 +25,20 @@ def test_read_profile_authorized(auth_client: TestClient, test_user: User):
24
25
"""Test that authorized users can view their profile"""
25
26
response = auth_client .get (app .url_path_for ("read_profile" ))
26
27
assert response .status_code == 200
27
- # Check that the response contains the expected HTML content
28
- assert test_user .account .email in response .text
29
- assert test_user .name in response .text
28
+
29
+ # Get the response text
30
+ response_text = response .text
31
+
32
+ # Verify account exists
33
+ assert test_user .account is not None
34
+
35
+ # Verify email is in the response if it exists
36
+ if test_user .account .email is not None :
37
+ assert response_text .find (str (test_user .account .email )) != - 1
38
+
39
+ # Verify name is in the response if it exists
40
+ if test_user .name is not None :
41
+ assert response_text .find (str (test_user .name )) != - 1
30
42
31
43
32
44
def test_update_profile_unauthorized (unauth_client : TestClient ):
@@ -109,7 +121,7 @@ def test_delete_account_wrong_password(auth_client: TestClient, test_user: User)
109
121
response : Response = auth_client .post (
110
122
app .url_path_for ("delete_account" ),
111
123
data = {
112
- "email" : test_user .account .email ,
124
+ "email" : test_user .account .email if test_user . account else "" ,
113
125
"password" : "WrongPassword123!"
114
126
},
115
127
follow_redirects = False
@@ -128,7 +140,7 @@ def test_delete_account_success(auth_client: TestClient, test_user: User, sessio
128
140
response : Response = auth_client .post (
129
141
app .url_path_for ("delete_account" ),
130
142
data = {
131
- "email" : test_user .account .email ,
143
+ "email" : test_user .account .email if test_user . account else "" ,
132
144
"password" : "Test123!@#"
133
145
},
134
146
follow_redirects = False
@@ -155,7 +167,7 @@ def test_get_avatar_authorized(mock_validate, auth_client: TestClient, test_user
155
167
auth_client .post (
156
168
app .url_path_for ("update_profile" ),
157
169
data = {
158
- "name" : test_user .name
170
+ "name" : test_user .name or "" # Ensure name is not None
159
171
},
160
172
files = {
161
173
"avatar_file" : ("test_avatar.jpg" , b"fake image data" , "image/jpeg" )
0 commit comments