@@ -56,6 +56,58 @@ class RecaptchaTestForm(Form):
5656 form = RecaptchaTestForm ({"g-recaptcha-response" : "dummy token" })
5757 self .assertTrue (form .is_valid ())
5858
59+ @mock .patch ('requests.post' )
60+ def test_settings_score_threshold (self , requests_post ):
61+
62+ recaptcha_response = {
63+ 'success' : True ,
64+ 'score' : 0.6
65+ }
66+ requests_post .return_value .json = lambda : recaptcha_response
67+
68+ class RecaptchaTestForm (Form ):
69+ recaptcha = ReCaptchaField ()
70+ form = RecaptchaTestForm ({"g-recaptcha-response" : "dummy token" })
71+ self .assertTrue (form .is_valid ())
72+
73+ @mock .patch ('requests.post' )
74+ def test_settings_score_threshold_override_fields (self , requests_post ):
75+
76+ recaptcha_response = {
77+ 'success' : True ,
78+ 'score' : 0.6
79+ }
80+ requests_post .return_value .json = lambda : recaptcha_response
81+
82+ with self .settings (RECAPTCHA_SCORE_THRESHOLD = 0.7 ):
83+ class RecaptchaTestForm (Form ):
84+ recaptcha = ReCaptchaField ()
85+
86+ form = RecaptchaTestForm ({"g-recaptcha-response" : "dummy token" })
87+ self .assertFalse (form .is_valid ())
88+
89+ @mock .patch ('requests.post' )
90+ def test_settings_score_threshold_override_each_fields (self , requests_post ):
91+
92+ recaptcha_response = {
93+ 'success' : True ,
94+ 'score' : 0.4
95+ }
96+ requests_post .return_value .json = lambda : recaptcha_response
97+
98+ with self .settings (RECAPTCHA_SCORE_THRESHOLD = 0.7 ):
99+ class RecaptchaTestForm (Form ):
100+ recaptcha = ReCaptchaField ()
101+
102+ class RecaptchaOverrideTestForm (Form ):
103+ recaptcha = ReCaptchaField (score_threshold = 0.3 )
104+
105+ form1 = RecaptchaTestForm ({"g-recaptcha-response" : "dummy token" })
106+ self .assertFalse (form1 .is_valid ())
107+
108+ form2 = RecaptchaOverrideTestForm ({"g-recaptcha-response" : "dummy token" })
109+ self .assertTrue (form2 .is_valid ())
110+
59111 @mock .patch ('requests.post' )
60112 def test_validate_success (self , requests_post ):
61113
0 commit comments