2015-11-22 15:43:02 +01:00
|
|
|
"""
|
|
|
|
This module contains tests for :py:mod:`gvawebcore.forms`.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
from unittest import TestCase
|
|
|
|
|
2019-01-30 21:27:25 +01:00
|
|
|
from gvawebcore.forms import PASSWORD_MISMATCH_ERROR, PasswordModelFormMixin
|
2015-11-22 15:43:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
class PasswordModelFormMixinTest(TestCase):
|
|
|
|
def test_form_properties(self):
|
|
|
|
form = PasswordModelFormMixin()
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertIn("password1", form.fields)
|
|
|
|
self.assertIn("password2", form.fields)
|
2015-11-22 15:43:02 +01:00
|
|
|
|
|
|
|
def test_clean_password_same(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
form = PasswordModelFormMixin(
|
|
|
|
data={"password1": "secret", "password2": "secret"}
|
|
|
|
)
|
2015-11-22 15:43:02 +01:00
|
|
|
self.assertTrue(form.is_valid())
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertEqual("secret", form.clean_password2())
|
2015-11-22 15:43:02 +01:00
|
|
|
|
|
|
|
def test_clean_password_different(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
form = PasswordModelFormMixin(
|
|
|
|
data={"password1": "onesecret", "password2": "other"}
|
|
|
|
)
|
2015-11-22 15:43:02 +01:00
|
|
|
self.assertFalse(form.is_valid())
|
2019-01-30 21:27:25 +01:00
|
|
|
self.assertIn("password2", form.errors)
|
|
|
|
self.assertIn(PASSWORD_MISMATCH_ERROR, form.errors["password2"])
|