Skip to content

Commit

Permalink
Refactor: move https_required back to global scope
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Moura <pmoura@redhat.com>
  • Loading branch information
phsmoura committed Jun 19, 2024
1 parent 37065eb commit 6ba57bc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
13 changes: 7 additions & 6 deletions noggin/form/edit_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@ def _validate(form, field):
raise ValidationError(_("This does not look like a valid server name."))


class UserSettingsProfileForm(BaseForm):
def _https_required(form, field):
if not field.data.startswith('https://'):
raise ValidationError('URL should start with "https://".')
def https_required(form, field):
if not field.data.startswith('https://'):
raise ValidationError('URL should start with "https://".')


class UserSettingsProfileForm(BaseForm):
firstname = StringField(
_('First Name'),
validators=[DataRequired(message=_('First name must not be empty'))],
Expand Down Expand Up @@ -131,7 +132,7 @@ def _https_required(form, field):
validators=[
Optional(),
URL(message=_('Valid URL required')),
_https_required,
https_required,
],
widget=FieldWithClearButtonWidget(URLField.widget),
),
Expand All @@ -143,7 +144,7 @@ def _https_required(form, field):
validators=[
Optional(),
URL(message=_('Valid URL required')),
_https_required,
https_required,
],
widget=FieldWithClearButtonWidget(URLField.widget),
),
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/form/test_edit_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from wtforms import Form
from wtforms.validators import ValidationError

from noggin.form.edit_user import UserSettingsProfileForm
from noggin.form.edit_user import UserSettingsProfileForm, https_required


Obj = namedtuple("Obj", ["ircnick"])
Expand Down Expand Up @@ -120,9 +120,9 @@ def test_form_edit_user_https_required(data, expected):

if expected:
try:
UserSettingsProfileForm._https_required(form, field)
https_required(form, field)
except ValidationError:
pytest.fail("Unexpected ValidationError raised.")
else:
with pytest.raises(ValidationError):
UserSettingsProfileForm._https_required(form, field)
https_required(form, field)

0 comments on commit 6ba57bc

Please sign in to comment.