Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require first and last name in user profile. #53

Merged
merged 1 commit into from
Sep 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/forms.py
Expand Up @@ -83,6 +83,14 @@ class Meta: #pylint: disable=no-init,missing-docstring,old-style-class,too-few-
only = ['first_name', 'last_name', 'position', 'organization',
'organization_type', 'city', 'country', 'projects',
'has_picture']
field_args = {
'first_name': {
'validators': [Required()]
},
'last_name': {
'validators': [Required()]
},
}

picture = FileField(
label=lazy_gettext('User Picture'),
Expand Down
11 changes: 11 additions & 0 deletions app/tests/test_views.py
Expand Up @@ -170,17 +170,28 @@ def test_get_is_ok(self):
self.login()
self.assert200(self.client.get('/me'))

def test_invalid_form_shows_errors(self):
self.login()
res = self.client.post('/me', data={
'first_name': '',
'expertise_domain_names': 'Agriculture',
})
self.assertEqual(self.last_created_user.expertise_domain_names, [])
assert "please correct errors" in res.data

def test_updating_profile_works(self):
self.login()
user = self.last_created_user
res = self.client.post('/me', data={
'first_name': 'John2',
'last_name': 'Doe2',
'expertise_domain_names': 'Agriculture',
'locales': 'af'
}, follow_redirects=True)
assert 'Your profile has been saved' in res.data
self.assert200(res)
self.assertEqual(user.first_name, 'John2')
self.assertEqual(user.last_name, 'Doe2')
self.assertEqual(user.expertise_domain_names, ['Agriculture'])
self.assertEqual(len(user.locales), 1)
self.assertEqual(str(user.locales[0]), 'af')
Expand Down