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 from domains.models import MailDomain from osusers.models import User from managemails.models import ( MailAddress, Mailbox, ) Customer = get_user_model() @override_settings( CELERY_ALWAYS_EAGER=True, CELERY_CACHE_BACKEND='memory', 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(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(self.customer) mb = Mailbox.objects.create(username='test', osuser=user) mb.set_password('test') self.assertEqual(str(mb), 'test') 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')