2014-05-24 13:56:45 +02:00
|
|
|
from django.test import TestCase
|
2014-06-01 18:29:41 +02:00
|
|
|
from django.test.utils import override_settings
|
2015-02-01 20:12:23 +01:00
|
|
|
from django.contrib.auth import get_user_model
|
2014-06-01 18:29:41 +02:00
|
|
|
|
2014-05-24 13:56:45 +02:00
|
|
|
from passlib.hash import sha512_crypt
|
|
|
|
|
2014-05-25 15:17:08 +02:00
|
|
|
from domains.models import MailDomain
|
2014-05-25 14:53:58 +02:00
|
|
|
from osusers.models import User
|
2014-06-01 18:29:41 +02:00
|
|
|
|
2014-05-24 13:56:45 +02:00
|
|
|
from managemails.models import (
|
|
|
|
MailAddress,
|
|
|
|
Mailbox,
|
|
|
|
)
|
|
|
|
|
2015-02-01 20:12:23 +01:00
|
|
|
Customer = get_user_model()
|
|
|
|
|
2014-05-24 13:56:45 +02:00
|
|
|
|
2014-06-01 18:29:41 +02:00
|
|
|
@override_settings(
|
|
|
|
CELERY_ALWAYS_EAGER=True,
|
|
|
|
CELERY_CACHE_BACKEND='memory',
|
|
|
|
BROKER_BACKEND='memory'
|
|
|
|
)
|
2014-05-24 13:56:45 +02:00
|
|
|
class MailboxTest(TestCase):
|
2015-02-01 20:12:23 +01:00
|
|
|
def setUp(self):
|
|
|
|
super(MailboxTest, self).setUp()
|
|
|
|
self.customer = Customer.objects.create_user('test')
|
|
|
|
|
2014-05-24 13:56:45 +02:00
|
|
|
def test_set_password(self):
|
2015-02-01 20:12:23 +01:00
|
|
|
user = User.objects.create_user(self.customer)
|
2014-05-25 14:53:58 +02:00
|
|
|
mb = Mailbox.objects.create(username='test', osuser=user)
|
2014-05-24 13:56:45 +02:00
|
|
|
mb.set_password('test')
|
|
|
|
self.assertTrue(sha512_crypt.verify('test', mb.password))
|
|
|
|
|
2014-06-01 18:29:41 +02:00
|
|
|
def test___str__(self):
|
2015-02-01 20:12:23 +01:00
|
|
|
user = User.objects.create_user(self.customer)
|
2014-06-01 18:29:41 +02:00
|
|
|
mb = Mailbox.objects.create(username='test', osuser=user)
|
|
|
|
mb.set_password('test')
|
|
|
|
self.assertEqual(str(mb), 'test')
|
|
|
|
|
2014-05-24 13:56:45 +02:00
|
|
|
|
|
|
|
class MailAddressTest(TestCase):
|
|
|
|
def test__str__(self):
|
|
|
|
md = MailDomain.objects.create(domain='example.org')
|
|
|
|
ma = MailAddress.objects.create(localpart='test', domain=md)
|
|
|
|
self.assertEqual(str(ma), 'test@example.org')
|