84 lines
2.5 KiB
Python
84 lines
2.5 KiB
Python
"""
|
|
Tests for :py:mod:`domains.models`.
|
|
|
|
"""
|
|
from __future__ import absolute_import, unicode_literals
|
|
|
|
from mock import Mock, MagicMock, patch
|
|
|
|
from django.test import TestCase
|
|
from django.contrib.auth import get_user_model
|
|
|
|
from domains.models import (
|
|
DomainBase,
|
|
MailDomain,
|
|
HostingDomain,
|
|
)
|
|
from hostingpackages.models import (
|
|
CustomerHostingPackage,
|
|
HostingPackageTemplate,
|
|
)
|
|
|
|
|
|
User = get_user_model()
|
|
|
|
TEST_USER = 'test'
|
|
|
|
|
|
class DomainBaseTest(TestCase):
|
|
|
|
def test__str__(self):
|
|
db = DomainBase(domain='test')
|
|
self.assertEqual(str(db), 'test')
|
|
|
|
|
|
class MailDomainTest(TestCase):
|
|
|
|
def test__str__(self):
|
|
md = MailDomain.objects.create(domain='example.org')
|
|
self.assertEqual(str(md), 'example.org')
|
|
|
|
def test_get_mailaddresses(self):
|
|
md = MailDomain.objects.create(domain='example.org')
|
|
from managemails.models import MailAddress
|
|
addrmock = MailAddress(localpart='info')
|
|
md.mailaddress_set.add(addrmock)
|
|
self.assertIn(addrmock, md.get_mailaddresses())
|
|
self.assertIn(addrmock, md.mailaddresses)
|
|
|
|
|
|
class HostingDomainManagerTest(TestCase):
|
|
|
|
def _setup_hosting_package(self):
|
|
template = HostingPackageTemplate.objects.create(
|
|
name='testpackagetemplate', mailboxcount=0, diskspace=1,
|
|
diskspace_unit=0)
|
|
customer = User.objects.create_user(username=TEST_USER)
|
|
package = CustomerHostingPackage.objects.create_from_template(
|
|
customer, template, 'testpackage')
|
|
with patch('hostingpackages.models.settings') as hmsettings:
|
|
hmsettings.OSUSER_DEFAULT_GROUPS = []
|
|
package.save()
|
|
return package
|
|
|
|
def test_create_for_hosting_package_with_commit(self):
|
|
package = self._setup_hosting_package()
|
|
hostingdomain = HostingDomain.objects.create_for_hosting_package(
|
|
package, 'example.org', True)
|
|
|
|
self.assertIsNotNone(hostingdomain)
|
|
self.assertTrue(hostingdomain.customer, package.customer)
|
|
|
|
def test_create_for_hosting_package_no_commit(self):
|
|
package = self._setup_hosting_package()
|
|
hostingdomain = HostingDomain.objects.create_for_hosting_package(
|
|
package, 'example.org', False)
|
|
|
|
self.assertIsNotNone(hostingdomain)
|
|
self.assertTrue(hostingdomain.customer, package.customer)
|
|
|
|
class HostingDomainTest(TestCase):
|
|
|
|
def test__str__(self):
|
|
hostingdomain = HostingDomain(domain='test')
|
|
self.assertEqual(str(hostingdomain), 'test')
|