diff --git a/ihatemoney/forms.py b/ihatemoney/forms.py index a55166e8..4e241c86 100644 --- a/ihatemoney/forms.py +++ b/ihatemoney/forms.py @@ -228,13 +228,11 @@ class ProjectForm(EditProjectForm): ) raise ValidationError(Markup(message)) - @classmethod - def enable_captcha(cls): - captchaField = StringField( - _("Which is a real currency: Euro or Petro dollar?"), - validators=[DataRequired()], - ) - setattr(cls, "captcha", captchaField) + +class ProjectFormWithCaptcha(ProjectForm): + captcha = StringField( + _("Which is a real currency: Euro or Petro dollar?"), + ) def validate_captcha(form, field): if not field.data.lower() == _("euro"): diff --git a/ihatemoney/tests/main_test.py b/ihatemoney/tests/main_test.py index 3efc4bf2..9707bd8a 100644 --- a/ihatemoney/tests/main_test.py +++ b/ihatemoney/tests/main_test.py @@ -286,6 +286,7 @@ class CaptchaTestCase(IhatemoneyTestCase): assert len(models.Project.query.all()) == 1 def test_api_project_creation_does_not_need_captcha(self): + self.client.get("/") resp = self.client.post( "/api/projects", data={ diff --git a/ihatemoney/web.py b/ihatemoney/web.py index 2b38bfc9..fd9bafa2 100644 --- a/ihatemoney/web.py +++ b/ihatemoney/web.py @@ -47,6 +47,7 @@ from ihatemoney.forms import ( MemberForm, PasswordReminder, ProjectForm, + ProjectFormWithCaptcha, ResetPasswordForm, UploadForm, get_billform_for, @@ -264,8 +265,7 @@ def authenticate(project_id=None): def get_project_form(): if current_app.config.get("ENABLE_CAPTCHA", False): - ProjectForm.enable_captcha() - + return ProjectFormWithCaptcha() return ProjectForm()