gva/gnuviechadmin/gvawebcore/tests/test_forms.py
Jan Dittberner 3d18392b67 Fix tests for Python 3
- drop Python 2 __future__ imports
- fix tests to handle new Django and Python 3 module names
- reformat changed files with black
2019-01-30 21:27:25 +01:00

30 lines
973 B
Python

"""
This module contains tests for :py:mod:`gvawebcore.forms`.
"""
from unittest import TestCase
from gvawebcore.forms import PASSWORD_MISMATCH_ERROR, PasswordModelFormMixin
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"])