Skip to content

Commit

Permalink
Adds a couple of tests for the register form
Browse files Browse the repository at this point in the history
  • Loading branch information
dirtycoder committed Nov 14, 2016
1 parent 3dc5ddd commit d1abe96
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
Empty file added pets/users/tests/__init__.py
Empty file.
45 changes: 45 additions & 0 deletions pets/users/tests/test_form_register.py
@@ -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
2 changes: 1 addition & 1 deletion pets/users/tests.py → pets/users/tests/tests.py
Expand Up @@ -4,7 +4,7 @@

from users.forms import RegisterForm, UpdateUserForm
from users.validators import validate_facebook_url
from .models import OwnerProfile
from users.models import OwnerProfile


class UserRegistrationTest(TestCase):
Expand Down

0 comments on commit d1abe96

Please sign in to comment.