gva/gnuviechadmin/gvawebcore/tests/test_forms.py
Jan Dittberner 28fc535f9e Add tests for gvawebcore
This commit adds tests for gvawebcore.forms and gvawebcore.views.
2015-11-22 14:43:02 +00:00

29 lines
956 B
Python

"""
This module contains tests for :py:mod:`gvawebcore.forms`.
"""
from unittest import TestCase
from gvawebcore.forms import PasswordModelFormMixin, PASSWORD_MISMATCH_ERROR
class PasswordModelFormMixinTest(TestCase):
def test_form_properties(self):
form = PasswordModelFormMixin()
self.assertIn('password1', form.fields)
self.assertIn('password2', form.fields)
def test_clean_password_same(self):
form = PasswordModelFormMixin(data={
'password1': 'secret', 'password2': 'secret'})
self.assertTrue(form.is_valid())
self.assertEqual('secret', form.clean_password2())
def test_clean_password_different(self):
form = PasswordModelFormMixin(data={
'password1': 'onesecret', 'password2': 'other'})
self.assertFalse(form.is_valid())
self.assertIn('password2', form.errors)
self.assertIn(PASSWORD_MISMATCH_ERROR, form.errors['password2'])