11import pytest
22from pydantic import ValidationError
33
4- from app .schemas .user import UserCreateRequest , UserRole , SignUpMethod
4+ from app .schemas .user import SignUpMethod , UserCreateRequest , UserRole
55
66
77class TestUserCreateRequestPasswordValidation :
@@ -11,13 +11,13 @@ def test_password_validation_success_valid_password(self):
1111 """Test that a valid password passes validation"""
1212 user_data = {
1313 "first_name" : "Test" ,
14- "last_name" : "User" ,
14+ "last_name" : "User" ,
15151616 "password" : "ValidPass123!" ,
1717 "role" : UserRole .PARTICIPANT ,
1818 "signup_method" : SignUpMethod .PASSWORD ,
1919 }
20-
20+
2121 # Should not raise any exception
2222 user_request = UserCreateRequest (** user_data )
2323 assert user_request .password == "ValidPass123!"
@@ -27,18 +27,18 @@ def test_password_validation_too_short(self):
2727 user_data = {
2828 "first_name" : "Test" ,
2929 "last_name" : "User" ,
30- 30+ 3131 "password" : "short1!" , # Only 7 characters
3232 "role" : UserRole .PARTICIPANT ,
3333 "signup_method" : SignUpMethod .PASSWORD ,
3434 }
35-
35+
3636 with pytest .raises (ValidationError ) as exc_info :
3737 UserCreateRequest (** user_data )
38-
38+
3939 # Check that the error message contains the expected validation message
4040 error_msg = str (exc_info .value )
41- assert "be at least 8 characters long" in error_msg
41+ assert "Password must be at least 8 characters long" in error_msg
4242
4343 def test_password_validation_missing_uppercase (self ):
4444 """Test that password without uppercase letter fails validation"""
@@ -50,12 +50,12 @@ def test_password_validation_missing_uppercase(self):
5050 "role" : UserRole .PARTICIPANT ,
5151 "signup_method" : SignUpMethod .PASSWORD ,
5252 }
53-
53+
5454 with pytest .raises (ValidationError ) as exc_info :
5555 UserCreateRequest (** user_data )
56-
56+
5757 error_msg = str (exc_info .value )
58- assert "contain at least one uppercase letter" in error_msg
58+ assert "Password must contain at least one uppercase letter" in error_msg
5959
6060 def test_password_validation_missing_lowercase (self ):
6161 """Test that password without lowercase letter fails validation"""
@@ -67,12 +67,12 @@ def test_password_validation_missing_lowercase(self):
6767 "role" : UserRole .PARTICIPANT ,
6868 "signup_method" : SignUpMethod .PASSWORD ,
6969 }
70-
70+
7171 with pytest .raises (ValidationError ) as exc_info :
7272 UserCreateRequest (** user_data )
73-
73+
7474 error_msg = str (exc_info .value )
75- assert "contain at least one lowercase letter" in error_msg
75+ assert "Password must contain at least one lowercase letter" in error_msg
7676
7777 def test_password_validation_missing_special_character (self ):
7878 """Test that password without special character fails validation"""
@@ -84,32 +84,32 @@ def test_password_validation_missing_special_character(self):
8484 "role" : UserRole .PARTICIPANT ,
8585 "signup_method" : SignUpMethod .PASSWORD ,
8686 }
87-
87+
8888 with pytest .raises (ValidationError ) as exc_info :
8989 UserCreateRequest (** user_data )
90-
90+
9191 error_msg = str (exc_info .value )
92- assert "contain at least one special character" in error_msg
92+ assert "Password must contain at least one special character" in error_msg
9393
9494 def test_password_validation_multiple_errors (self ):
9595 """Test that password with multiple issues returns all errors"""
9696 user_data = {
97- "first_name" : "Test" ,
97+ "first_name" : "Test" ,
9898 "last_name" : "User" ,
9999100100 "password" : "short" , # Too short, no uppercase, no special char
101101 "role" : UserRole .PARTICIPANT ,
102102 "signup_method" : SignUpMethod .PASSWORD ,
103103 }
104-
104+
105105 with pytest .raises (ValidationError ) as exc_info :
106106 UserCreateRequest (** user_data )
107-
107+
108108 error_msg = str (exc_info .value )
109109 # Should contain multiple validation errors
110- assert "be at least 8 characters long" in error_msg
111- assert "contain at least one uppercase letter" in error_msg
112- assert "contain at least one special character" in error_msg
110+ assert "Password must be at least 8 characters long" in error_msg
111+ assert "Password must contain at least one uppercase letter" in error_msg
112+ assert "Password must contain at least one special character" in error_msg
113113
114114 def test_password_validation_google_signup_no_password_required (self ):
115115 """Test that Google signup doesn't require password validation"""
@@ -121,7 +121,7 @@ def test_password_validation_google_signup_no_password_required(self):
121121 "role" : UserRole .PARTICIPANT ,
122122 "signup_method" : SignUpMethod .GOOGLE ,
123123 }
124-
124+
125125 # Should not raise any exception for Google signup
126126 user_request = UserCreateRequest (** user_data )
127127 assert user_request .password is None
@@ -131,31 +131,31 @@ def test_password_validation_edge_cases(self):
131131 # Test with exactly 8 characters
132132 user_data = {
133133 "first_name" : "Test" ,
134- "last_name" : "User" ,
134+ "last_name" : "User" ,
135135136136 "password" : "MinPass1!" , # Exactly 8 chars, meets all requirements
137137 "role" : UserRole .PARTICIPANT ,
138138 "signup_method" : SignUpMethod .PASSWORD ,
139139 }
140-
140+
141141 # Should not raise any exception
142142 user_request = UserCreateRequest (** user_data )
143143 assert user_request .password == "MinPass1!"
144144
145145 def test_password_validation_all_special_characters (self ):
146146 """Test that all allowed special characters work"""
147147 special_chars = ["!" , "@" , "#" , "$" , "%" , "^" , "&" , "*" ]
148-
148+
149149 for char in special_chars :
150150 user_data = {
151151 "first_name" : "Test" ,
152152 "last_name" : "User" ,
153- 153+ 154154 "password" : f"ValidPass1{ char } " ,
155155 "role" : UserRole .PARTICIPANT ,
156156 "signup_method" : SignUpMethod .PASSWORD ,
157157 }
158-
158+
159159 # Should not raise any exception
160160 user_request = UserCreateRequest (** user_data )
161- assert user_request .password == f"ValidPass1{ char } "
161+ assert user_request .password == f"ValidPass1{ char } "
0 commit comments