-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a couple of tests for the register form
- Loading branch information
1 parent
3dc5ddd
commit d1abe96
Showing
3 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from django.test import TestCase | ||
|
||
from users.forms import RegisterForm | ||
|
||
|
||
class RegisteFormTest(TestCase): | ||
def test_form_has_fields(self): | ||
"""Form should have the correct fields""" | ||
form = RegisterForm() | ||
|
||
expected = ['first_name', 'last_name', 'email', 'username', | ||
'facebook', 'phone', 'password1', 'password2'] | ||
|
||
self.assertSequenceEqual(expected, list(form.fields)) | ||
|
||
def test_form_validates_facebook_url(self): | ||
"""Form should execute at least a basic validation of the Facebook URL field""" | ||
form = self.make_validated_form(facebook='www.example.com') | ||
|
||
self.assertEqual(form.errors.as_data()['facebook'][0].message, | ||
'Por favor, insira uma URL válida do seu perfil no Facebook.') | ||
|
||
def test_form_validate_passwords(self): | ||
"""Both passwords provided by the user should be equal""" | ||
form = self.make_validated_form(password1='a', password2='b') | ||
|
||
self.assertEqual(form.errors.as_data()['password2'][0].message, | ||
'Os dois campos de senha não combinam.') | ||
|
||
@staticmethod | ||
def make_validated_form(**kwargs): | ||
valid = dict( | ||
first_name='Admin', | ||
last_name='Adminson', | ||
email='admin@example.com', | ||
username='admin', | ||
facebook='https://www.facebook.com/adminadminson', | ||
phone='99 9999-9999', | ||
password1='123456', | ||
password2='123456', | ||
) | ||
data = dict(valid, **kwargs) | ||
form = RegisterForm(data) | ||
form.is_valid() | ||
return form |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters