diff --git a/colab/accounts/forms.py b/colab/accounts/forms.py index c80f974..0223222 100644 --- a/colab/accounts/forms.py +++ b/colab/accounts/forms.py @@ -2,6 +2,7 @@ from collections import OrderedDict +from django.http import HttpRequest from django import forms from django.contrib.auth import authenticate, get_user_model from django.contrib.auth.forms import ReadOnlyPasswordHashField @@ -60,8 +61,51 @@ class UserForm(forms.ModelForm): if not username: raise forms.ValidationError(_('This field cannot be blank.')) return username - - + + def clean_first_name(self): + first_name = self.cleaned_data["first_name"].strip() + if not first_name: + raise forms.ValidationError(_('This field cannot be blank.')) + return first_name + + def clean_last_name(self): + last_name = self.cleaned_data["last_name"].strip() + if not last_name: + raise forms.ValidationError(_('This field cannot be blank.')) + return last_name + + def clean_twitter(self): + twitter = self.cleaned_data["twitter"] + if twitter is not None and twitter.isspace(): + return self.initial.get("twitter") + return twitter + + def clean_facebook(self): + facebook = self.cleaned_data["facebook"] + if facebook is not None and facebook.isspace(): + return self.initial.get("facebook") + return facebook + + def clean_webpage(self): + webpage = self.cleaned_data["webpage"].strip() + return webpage + + def clean_role(self): + role = self.cleaned_data["role"].strip() + return role + + def clean_institution(self): + institution = self.cleaned_data["institution"].strip() + return institution + + def clean_bio(self): + bio = self.cleaned_data["bio"].strip() + return bio + + def clean_github(self): + github = self.cleaned_data["github"].strip() + return github + class UserUpdateForm(UserForm): bio = forms.CharField( widget=forms.Textarea(attrs={'rows': '6', 'maxlength': '200'}), diff --git a/colab/accounts/tests/test_user.py b/colab/accounts/tests/test_user.py index 14b9d72..26e889d 100644 --- a/colab/accounts/tests/test_user.py +++ b/colab/accounts/tests/test_user.py @@ -116,11 +116,6 @@ class UserTest(TestCase): self.validate_mandatory_fields('USERtestCoLaB', 'COLAB', ' ', ' ') self.user.delete() - def test_update_user_mandatory_invalid_using_number(self): - self.authenticate_user() - self.validate_mandatory_fields('USERtestCoLaB', 'COLAB', '123', '456') - self.user.delete() - def test_update_user_institution(self): self.authenticate_user() self.validate_non_mandatory_fields('institution', 'fga', 'fga') @@ -148,11 +143,7 @@ class UserTest(TestCase): def test_update_user_institution_invalid_whitespace(self): self.authenticate_user() - self.validate_non_mandatory_fields('institution', None, ' ') - - def test_update_user_institution_invalid_using_number(self): - self.authenticate_user() - self.validate_non_mandatory_fields('institution', None, '123') + self.validate_non_mandatory_fields('institution', '', ' ') self.user.delete() def test_update_user_role(self): @@ -182,12 +173,7 @@ class UserTest(TestCase): def test_update_user_role_invalid_whitespace(self): self.authenticate_user() - self.validate_non_mandatory_fields('role', None, ' ') - self.user.delete() - - def test_update_user_role_invalid_using_number(self): - self.authenticate_user() - self.validate_non_mandatory_fields('role', None, '123') + self.validate_non_mandatory_fields('role', '', ' ') self.user.delete() def test_update_user_twitter(self): @@ -226,11 +212,6 @@ class UserTest(TestCase): self.validate_non_mandatory_fields('twitter', 'usertestcolab', ' ') self.user.delete() - def test_update_user_twitter_invalid_using_number(self): - self.authenticate_user() - self.validate_non_mandatory_fields('twitter', 'usertestcolab', '123') - self.user.delete() - ''' Max_lenght is the maximmum size accept by Faceebook. Tests related with twitter should have internet connection, @@ -267,11 +248,6 @@ class UserTest(TestCase): self.validate_non_mandatory_fields('facebook', 'usertestcolab', ' ') self.user.delete() - def test_update_user_facebook_invalid_using_number(self): - self.authenticate_user() - self.validate_non_mandatory_fields('facebook', 'usertestcolab', '123') - self.user.delete() - def test_update_user_gtalk(self): self.authenticate_user() self.validate_non_mandatory_fields('google_talk', 'gtalk@colab.com.br', @@ -332,7 +308,7 @@ class UserTest(TestCase): def test_update_user_github_invalid_whitespace(self): self.authenticate_user() - self.validate_non_mandatory_fields('github', None, ' ') + self.validate_non_mandatory_fields('github', '', ' ') self.user.delete() def test_update_user_webpage(self): @@ -362,7 +338,7 @@ class UserTest(TestCase): def test_update_user_webpage_invalid_whitespace(self): self.authenticate_user() - self.validate_non_mandatory_fields('webpage', None, ' ') + self.validate_non_mandatory_fields('webpage', '', ' ') self.user.delete() def test_update_user_bio(self): @@ -392,5 +368,5 @@ class UserTest(TestCase): def test_update_user_bio_invalid_whitespace(self): self.authenticate_user() - self.validate_non_mandatory_fields('bio', None, ' ') + self.validate_non_mandatory_fields('bio', '', ' ') self.user.delete() diff --git a/colab/accounts/tests/test_view_signup.py b/colab/accounts/tests/test_view_signup.py index f445144..47084db 100644 --- a/colab/accounts/tests/test_view_signup.py +++ b/colab/accounts/tests/test_view_signup.py @@ -5,7 +5,7 @@ This test related with accounts/views.py from django.test import TestCase, Client from colab.accounts.models import User - +from django.core.cache import cache class TestSignUpView(TestCase): @@ -38,7 +38,9 @@ class TestSignUpView(TestCase): self.client.logout() def test_user_not_authenticated(self): - response = self.client.get("/account/register/") - self.assertEquals(302, response.status_code) - url = "http://testserver/account/login" - self.assertEquals(url, response.url) + with self.settings(BROWSERID_ENABLE=True): + cache.clear() + response = self.client.get("/account/register/") + self.assertEquals(302, response.status_code) + url = "http://testserver/account/login" + self.assertEquals(url, response.url) -- libgit2 0.21.2