import unittest from app.features.auth.security import validate_password_strength from app.features.auth.errors import WeakPasswordError class TestPasswordValidation(unittest.TestCase): def test_space_instead_of_special_char_fails(self): with self.assertRaises(WeakPasswordError) as ctx: validate_password_strength("Siraj 12345") self.assertIn("special character", str(ctx.exception)) def test_too_short_fails(self): with self.assertRaises(WeakPasswordError) as ctx: validate_password_strength("Short1!") self.assertIn("8 characters", str(ctx.exception)) def test_no_uppercase_fails(self): with self.assertRaises(WeakPasswordError) as ctx: validate_password_strength("lowercase1!") self.assertIn("uppercase", str(ctx.exception)) def test_no_digit_fails(self): with self.assertRaises(WeakPasswordError) as ctx: validate_password_strength("NoNumbers!") self.assertIn("number", str(ctx.exception)) def test_no_special_char_fails(self): with self.assertRaises(WeakPasswordError) as ctx: validate_password_strength("NoSpecial123") self.assertIn("special character", str(ctx.exception)) def test_emoji_instead_of_special_char_fails(self): with self.assertRaises(WeakPasswordError) as ctx: validate_password_strength("NoSpecial123😀") self.assertIn("special character", str(ctx.exception)) def test_valid_passwords_pass(self): # Must not raise any exceptions validate_password_strength("Siraj@12345") validate_password_strength("ValidPassword123!") validate_password_strength("P@ssw0rd2026") validate_password_strength("Strong#Pass1") if __name__ == "__main__": unittest.main()