gva/gnuviechadmin/managemails/tests/test_models.py

46 lines
1.3 KiB
Python
Raw Normal View History

2014-05-24 13:56:45 +02:00
from django.test import TestCase
from django.test.utils import override_settings
2015-02-01 20:12:23 +01:00
from django.contrib.auth import get_user_model
2014-05-24 13:56:45 +02:00
from passlib.hash import sha512_crypt
from domains.models import MailDomain
from osusers.models import User
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
@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)
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))
def test___str__(self):
2015-02-01 20:12:23 +01:00
user = User.objects.create_user(self.customer)
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')