Commit a27468ebd824339737532cb5d6cccb6c8ee0378c

Authored by Alexandre Barbosa
1 parent 7b60bcd1

Adding tests to ColabPasswordChangeForm

Signed-off-by: Alexandre Barbosa <alexandreab@live.com>
Signed-off-by: Lucas Moura <lucas.moura128@gmail.com>
Showing 1 changed file with 39 additions and 8 deletions   Show diff stats
colab/accounts/tests/test_forms.py
... ... @@ -9,8 +9,10 @@ from mock import patch
9 9 from django.test import TestCase, override_settings
10 10 from django.core.urlresolvers import reverse
11 11  
12   -from colab.accounts.forms import UserCreationForm, UserChangeForm,\
13   - UserUpdateForm, UserForm, get_lists_choices, ColabSetPasswordForm
  12 +from colab.accounts.forms import (UserCreationForm, UserChangeForm,
  13 + UserUpdateForm, UserForm, get_lists_choices,
  14 + ColabSetPasswordForm,
  15 + ColabPasswordChangeForm)
14 16 from colab.accounts import forms as accounts_forms
15 17 from colab.accounts.models import User
16 18 from colab.accounts.utils import mailman
... ... @@ -47,12 +49,6 @@ class SetPasswordFormTestCase(TestCase):
47 49 self.assertTrue(form.is_valid())
48 50 validator.assert_called_with('12345')
49 51  
50   - @override_settings(COLAB_APPS=TEST_COLAB_APPS)
51   - def test_custom_validator_raise_error(self):
52   - form = ColabSetPasswordForm(self.user, data=self.valid_form_data)
53   - self.assertFalse(form.is_valid())
54   - self.assertEqual(form.errors['new_password2'][0], 'Test error')
55   -
56 52  
57 53 class FormTest(TestCase):
58 54  
... ... @@ -221,3 +217,38 @@ class FormTest(TestCase):
221 217 ('listB', u'listB (B)'),
222 218 ('listC', u'listC (C)'),
223 219 ('listD', u'listD (D)')])
  220 +
  221 +
  222 +class ChangePasswordFormTestCase(TestCase):
  223 +
  224 + TEST_COLAB_APPS = {
  225 + 'test_plugin': {
  226 + 'password_validators': (
  227 + 'colab.accounts.tests.utils.password_validator',
  228 + )
  229 + }
  230 + }
  231 +
  232 + @property
  233 + def user(self):
  234 + u = User.objects.create_user(username='test_user',
  235 + email='test@example.com')
  236 + u.set_password("123colab4")
  237 + return u
  238 +
  239 + @property
  240 + def valid_form_data(self):
  241 + return {'old_password': '123colab4',
  242 + 'new_password1': '12345',
  243 + 'new_password2': '12345'}
  244 +
  245 + def test_no_custom_validators(self):
  246 + form = ColabPasswordChangeForm(self.user, data=self.valid_form_data)
  247 + self.assertTrue(form.is_valid(), True)
  248 +
  249 + @override_settings(COLAB_APPS=TEST_COLAB_APPS)
  250 + @patch('colab.accounts.tests.utils.password_validator')
  251 + def test_custom_validator(self, validator):
  252 + form = ColabPasswordChangeForm(self.user, data=self.valid_form_data)
  253 + self.assertTrue(form.is_valid())
  254 + validator.assert_called_with('12345')
... ...