fix tests
This commit is contained in:
parent
e87e4ca268
commit
e913b1f771
2 changed files with 34 additions and 11 deletions
|
@ -6,6 +6,7 @@ from django.utils.html import format_html
|
|||
from django.utils.translation import ugettext as _
|
||||
|
||||
from django.contrib.admin import AdminSite
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
from mock import Mock
|
||||
|
||||
|
@ -24,6 +25,8 @@ from managemails.models import (
|
|||
Mailbox,
|
||||
)
|
||||
|
||||
Customer = get_user_model()
|
||||
|
||||
|
||||
class ReadOnlyPasswordHashWidgetTest(TestCase):
|
||||
def test_render(self):
|
||||
|
@ -52,7 +55,13 @@ class ReadOnlyPasswordHashFieldTest(TestCase):
|
|||
self.assertFalse(field._has_changed('new', 'old'))
|
||||
|
||||
|
||||
class MailboxCreationFormTest(TestCase):
|
||||
class CustomerTestCase(TestCase):
|
||||
def setUp(self):
|
||||
super(CustomerTestCase, self).setUp()
|
||||
self.customer = Customer.objects.create(username='test')
|
||||
|
||||
|
||||
class MailboxCreationFormTest(CustomerTestCase):
|
||||
def test_clean_password2_same(self):
|
||||
form = MailboxCreationForm()
|
||||
form.cleaned_data = {'password1': 'secret', 'password2': 'secret'}
|
||||
|
@ -76,7 +85,7 @@ class MailboxCreationFormTest(TestCase):
|
|||
BROKER_BACKEND='memory'
|
||||
)
|
||||
def test_save_commit(self):
|
||||
user = User.objects.create_user()
|
||||
user = User.objects.create_user(customer=self.customer)
|
||||
form = MailboxCreationForm(data={
|
||||
'osuser': user.uid,
|
||||
'password1': 'secret',
|
||||
|
@ -93,7 +102,7 @@ class MailboxCreationFormTest(TestCase):
|
|||
BROKER_BACKEND='memory'
|
||||
)
|
||||
def test_save_no_commit(self):
|
||||
user = User.objects.create_user()
|
||||
user = User.objects.create_user(customer=self.customer)
|
||||
form = MailboxCreationForm(data={
|
||||
'osuser': user.uid,
|
||||
'password1': 'secret',
|
||||
|
@ -105,14 +114,16 @@ class MailboxCreationFormTest(TestCase):
|
|||
len(Mailbox.objects.filter(osuser=user)), 0)
|
||||
|
||||
|
||||
class MailboxChangeFormTest(TestCase):
|
||||
class MailboxChangeFormTest(CustomerTestCase):
|
||||
@override_settings(
|
||||
CELERY_ALWAYS_EAGER=True,
|
||||
CELERY_CACHE_BACKEND='memory',
|
||||
BROKER_BACKEND='memory'
|
||||
)
|
||||
def test_clean_password(self):
|
||||
mailbox = Mailbox(username='test', osuser=User.objects.create_user())
|
||||
mailbox = Mailbox(
|
||||
username='test',
|
||||
osuser=User.objects.create_user(customer=self.customer))
|
||||
mailbox.set_password('test')
|
||||
mailbox.save()
|
||||
form = MailboxChangeForm(instance=mailbox, data={'password': 'blub'})
|
||||
|
@ -133,8 +144,9 @@ class ActivationChangeMixinTest(TestCase):
|
|||
querysetmock.update.called_with(active=False)
|
||||
|
||||
|
||||
class MailBoxAdminTest(TestCase):
|
||||
class MailBoxAdminTest(CustomerTestCase):
|
||||
def setUp(self):
|
||||
super(MailBoxAdminTest, self).setUp()
|
||||
site = AdminSite()
|
||||
self.mbadmin = MailboxAdmin(Mailbox, site)
|
||||
|
||||
|
@ -149,7 +161,9 @@ class MailBoxAdminTest(TestCase):
|
|||
BROKER_BACKEND='memory'
|
||||
)
|
||||
def test_get_fieldsets_with_object(self):
|
||||
mailbox = Mailbox(username='test', osuser=User.objects.create_user())
|
||||
mailbox = Mailbox(
|
||||
username='test',
|
||||
osuser=User.objects.create_user(customer=self.customer))
|
||||
mailbox.set_password('test')
|
||||
mailbox.save()
|
||||
self.assertEqual(
|
||||
|
@ -169,13 +183,15 @@ class MailBoxAdminTest(TestCase):
|
|||
BROKER_BACKEND='memory'
|
||||
)
|
||||
def test_get_form_with_object(self):
|
||||
mailbox = Mailbox(username='test', osuser=User.objects.create_user())
|
||||
mailbox = Mailbox(
|
||||
username='test',
|
||||
osuser=User.objects.create_user(customer=self.customer))
|
||||
mailbox.set_password('test')
|
||||
mailbox.save()
|
||||
form = self.mbadmin.get_form(Mock, mailbox)
|
||||
self.assertEqual(
|
||||
form.Meta.fields,
|
||||
['username', 'password', 'osuser', 'active']
|
||||
['osuser', 'username', 'password', 'active']
|
||||
)
|
||||
|
||||
def test_admin_for_mailbox(self):
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from django.test import TestCase
|
||||
from django.test.utils import override_settings
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
from passlib.hash import sha512_crypt
|
||||
|
||||
|
@ -11,6 +12,8 @@ from managemails.models import (
|
|||
Mailbox,
|
||||
)
|
||||
|
||||
Customer = get_user_model()
|
||||
|
||||
|
||||
@override_settings(
|
||||
CELERY_ALWAYS_EAGER=True,
|
||||
|
@ -18,14 +21,18 @@ from managemails.models import (
|
|||
BROKER_BACKEND='memory'
|
||||
)
|
||||
class MailboxTest(TestCase):
|
||||
def setUp(self):
|
||||
super(MailboxTest, self).setUp()
|
||||
self.customer = Customer.objects.create_user('test')
|
||||
|
||||
def test_set_password(self):
|
||||
user = User.objects.create_user()
|
||||
user = User.objects.create_user(self.customer)
|
||||
mb = Mailbox.objects.create(username='test', osuser=user)
|
||||
mb.set_password('test')
|
||||
self.assertTrue(sha512_crypt.verify('test', mb.password))
|
||||
|
||||
def test___str__(self):
|
||||
user = User.objects.create_user()
|
||||
user = User.objects.create_user(self.customer)
|
||||
mb = Mailbox.objects.create(username='test', osuser=user)
|
||||
mb.set_password('test')
|
||||
self.assertEqual(str(mb), 'test')
|
||||
|
|
Loading…
Reference in a new issue