add osuser.tests.test_admin.UserCreationFormTest

This commit is contained in:
Jan Dittberner 2014-06-01 22:20:28 +02:00
parent 5cc86b4790
commit 3db6b99a00

View file

@ -1,5 +1,7 @@
from django.test import TestCase from django import forms
from django.contrib.admin import AdminSite from django.contrib.admin import AdminSite
from django.test import TestCase
from django.test.utils import override_settings
from mock import patch, Mock from mock import patch, Mock
@ -7,6 +9,8 @@ from osusers.models import (
User, User,
) )
from osusers.admin import ( from osusers.admin import (
PASSWORD_MISMATCH_ERROR,
UserCreationForm,
UserTaskResultInline, UserTaskResultInline,
) )
@ -29,3 +33,34 @@ class TaskResultInlineTest(TestCase):
UserTaskResultInline(User, self.site).has_add_permission( UserTaskResultInline(User, self.site).has_add_permission(
self, Mock(name='request')) self, Mock(name='request'))
) )
class UserCreationFormTest(TestCase):
def test_clean_password2_same(self):
form = UserCreationForm()
form.cleaned_data = {'password1': 'secret', 'password2': 'secret'}
self.assertEqual(form.clean_password2(), 'secret')
def test_clean_password2_empty(self):
form = UserCreationForm()
form.cleaned_data = {}
self.assertIsNone(form.clean_password2())
def test_clean_password2_mismatch(self):
form = UserCreationForm()
form.cleaned_data = {'password1': 'secretx', 'password2': 'secrety'}
with self.assertRaises(forms.ValidationError) as cm:
form.clean_password2()
self.assertEqual(cm.exception.message, PASSWORD_MISMATCH_ERROR)
@override_settings(
CELERY_ALWAYS_EAGER=True,
CELERY_CACHE_BACKEND='memory',
BROKER_BACKEND='memory'
)
def test_save_commit(self):
form = UserCreationForm()
form.cleaned_data = {'password1': 'secret', 'password2': 'secret'}
user = form.save()
self.assertIsNotNone(user)
self.assertEqual(User.objects.get(pk=user.uid), user)