Skip to content

Commit

Permalink
Merge pull request #4910 from dojutsu-user/validate-profile-form-fields
Browse files Browse the repository at this point in the history
Validate profile form fields
  • Loading branch information
humitos committed Dec 3, 2018
2 parents 273776c + 7348234 commit 3800d75
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions readthedocs/core/forms.py
Expand Up @@ -18,8 +18,8 @@


class UserProfileForm(forms.ModelForm):
first_name = CharField(label=_('First name'), required=False)
last_name = CharField(label=_('Last name'), required=False)
first_name = CharField(label=_('First name'), required=False, max_length=30)
last_name = CharField(label=_('Last name'), required=False, max_length=30)

class Meta(object):
model = UserProfile
Expand Down
21 changes: 21 additions & 0 deletions readthedocs/rtd_tests/tests/test_profile_views.py
Expand Up @@ -35,6 +35,27 @@ def test_edit_profile(self):
self.assertEqual(self.user.last_name, 'Docs')
self.assertEqual(self.user.profile.homepage, 'readthedocs.org')

def test_edit_profile_with_invalid_values(self):
resp = self.client.get(
reverse('profiles_profile_edit'),
)
self.assertTrue(resp.status_code, 200)

resp = self.client.post(
reverse('profiles_profile_edit'),
data={
'first_name': 'a' * 31,
'last_name': 'b' * 31,
'homepage': 'c' * 101,
}
)

FORM_ERROR_FORMAT = 'Ensure this value has at most {} characters (it has {}).'

self.assertFormError(resp, form='form', field='first_name', errors=FORM_ERROR_FORMAT.format(30, 31))
self.assertFormError(resp, form='form', field='last_name', errors=FORM_ERROR_FORMAT.format(30, 31))
self.assertFormError(resp, form='form', field='homepage', errors=FORM_ERROR_FORMAT.format(100, 101))

def test_delete_account(self):
resp = self.client.get(
reverse('delete_account')
Expand Down

0 comments on commit 3800d75

Please sign in to comment.