-
I'm trying to write unit tests for my forms. and I don't know how to test or bypass Recaptcha in my tests. form.pyclass UserLoginForm(forms.Form):
email = forms.EmailField()
password = forms.CharField(
widget=forms.widgets.PasswordInput()
)
captcha = ReCaptchaField(
widget = ReCaptchaV2Checkbox(api_params={'hl' : 'FA'}),
) test_forms.pyclass TestUserLoginForm:
def test_valid_login(self, raw_normal_user):
form = UserLoginForm(raw_normal_user)
form.is_valid() # Result: False
print(form.errors.items()) # this line has a error # Result: dict_items([('captcha', ['This field is required.'])])
assert form.cleaned_data == {
"email": "[email protected]",
"password": "test123password",
} So my question is how can I write a test for Recaptcha or bypass it? |
Beta Was this translation helpful? Give feedback.
Answered by
imanhpr
Jun 12, 2022
Replies: 1 comment
-
I found a way to bypass it but I don't know if it's good or bad. # raw_normal_user is a pytest fixture
def test_valid_login(self, raw_normal_user):
form = UserLoginForm(raw_normal_user)
print(form.errors.pop('captcha')) # This line deletes the captcha error
assert form.is_valid()
assert form.cleaned_data == {
"email": "[email protected]",
"password": "test123password",
} If you found a better solution please suggest me. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
imanhpr
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found a way to bypass it but I don't know if it's good or bad.
If you found a better solution please suggest me.