Commit 92bff1da93cdf5e7b05cfc341b6af595f0afb65c
1 parent
e9631d3c
Exists in
master
and in
4 other branches
Added test cases
Showing
2 changed files
with
46 additions
and
2 deletions
Show diff stats
colab/accounts/tests/test_forms.py
| ... | ... | @@ -6,16 +6,54 @@ Objective: Test parameters, and behavior. |
| 6 | 6 | import datetime |
| 7 | 7 | from mock import patch |
| 8 | 8 | |
| 9 | -from django.test import TestCase | |
| 9 | +from django.test import TestCase, override_settings | |
| 10 | 10 | from django.core.urlresolvers import reverse |
| 11 | 11 | |
| 12 | 12 | from colab.accounts.forms import UserCreationForm, UserChangeForm,\ |
| 13 | - UserUpdateForm, UserForm, get_lists_choices | |
| 13 | + UserUpdateForm, UserForm, get_lists_choices, SetPasswordForm | |
| 14 | 14 | from colab.accounts import forms as accounts_forms |
| 15 | 15 | from colab.accounts.models import User |
| 16 | 16 | from colab.accounts.utils import mailman |
| 17 | 17 | |
| 18 | 18 | |
| 19 | +class SetPasswordFormTestCase(TestCase): | |
| 20 | + | |
| 21 | + TEST_COLAB_APPS = { | |
| 22 | + 'test_plugin': { | |
| 23 | + 'password_validators': ( | |
| 24 | + 'colab.accounts.tests.utils.password_validator', | |
| 25 | + ) | |
| 26 | + } | |
| 27 | + } | |
| 28 | + | |
| 29 | + @property | |
| 30 | + def user(self): | |
| 31 | + return User.objects.create_user(username='test_user', | |
| 32 | + email='test@example.com') | |
| 33 | + | |
| 34 | + @property | |
| 35 | + def valid_form_data(self): | |
| 36 | + return {'new_password1': '12345', | |
| 37 | + 'new_password2': '12345'} | |
| 38 | + | |
| 39 | + def test_no_custom_validators(self): | |
| 40 | + form = SetPasswordForm(self.user, data=self.valid_form_data) | |
| 41 | + self.assertTrue(form.is_valid(), True) | |
| 42 | + | |
| 43 | + @override_settings(COLAB_APPS=TEST_COLAB_APPS) | |
| 44 | + @patch('colab.accounts.tests.utils.password_validator') | |
| 45 | + def test_custom_validator(self, validator): | |
| 46 | + form = SetPasswordForm(self.user, data=self.valid_form_data) | |
| 47 | + self.assertTrue(form.is_valid()) | |
| 48 | + validator.assert_called_with('12345') | |
| 49 | + | |
| 50 | + @override_settings(COLAB_APPS=TEST_COLAB_APPS) | |
| 51 | + def test_custom_validator_raise_error(self): | |
| 52 | + form = SetPasswordForm(self.user, data=self.valid_form_data) | |
| 53 | + self.assertFalse(form.is_valid()) | |
| 54 | + self.assertEqual(form.errors['new_password1'][0], 'Test error') | |
| 55 | + | |
| 56 | + | |
| 19 | 57 | class FormTest(TestCase): |
| 20 | 58 | |
| 21 | 59 | def setUp(self): | ... | ... |