2015-10-15 21:50:18 +02:00
|
|
|
"""
|
|
|
|
Tests for :py:mod:`domains.models`.
|
|
|
|
|
|
|
|
"""
|
2019-01-30 21:27:25 +01:00
|
|
|
from unittest.mock import patch
|
2015-10-15 21:50:18 +02:00
|
|
|
|
2014-05-25 14:53:58 +02:00
|
|
|
from django.test import TestCase
|
2015-10-15 21:50:18 +02:00
|
|
|
from django.contrib.auth import get_user_model
|
|
|
|
|
2023-04-16 11:14:26 +02:00
|
|
|
from domains.models import HostingDomain, MailDomain
|
2015-10-15 21:50:18 +02:00
|
|
|
|
2023-04-16 11:14:26 +02:00
|
|
|
from hostingpackages.models import CustomerHostingPackage, HostingPackageTemplate
|
2015-10-15 21:50:18 +02:00
|
|
|
|
|
|
|
User = get_user_model()
|
2014-05-25 14:53:58 +02:00
|
|
|
|
2019-01-30 21:27:25 +01:00
|
|
|
TEST_USER = "test"
|
2015-10-15 21:50:18 +02:00
|
|
|
|
|
|
|
|
2014-05-25 14:53:58 +02:00
|
|
|
class MailDomainTest(TestCase):
|
2015-11-07 17:10:38 +01:00
|
|
|
def test___str__(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
md = MailDomain.objects.create(domain="example.org")
|
|
|
|
self.assertEqual(str(md), "example.org")
|
2015-10-15 21:50:18 +02:00
|
|
|
|
|
|
|
def test_get_mailaddresses(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
md = MailDomain.objects.create(domain="example.org")
|
2015-10-15 21:50:18 +02:00
|
|
|
from managemails.models import MailAddress
|
2019-01-30 21:27:25 +01:00
|
|
|
|
|
|
|
addrmock = MailAddress.objects.create(localpart="info", domain=md)
|
2015-10-15 21:50:18 +02:00
|
|
|
self.assertIn(addrmock, md.get_mailaddresses())
|
|
|
|
self.assertIn(addrmock, md.mailaddresses)
|
|
|
|
|
|
|
|
|
|
|
|
class HostingDomainManagerTest(TestCase):
|
|
|
|
def _setup_hosting_package(self):
|
|
|
|
template = HostingPackageTemplate.objects.create(
|
2019-01-30 21:27:25 +01:00
|
|
|
name="testpackagetemplate", mailboxcount=0, diskspace=1, diskspace_unit=0
|
|
|
|
)
|
2015-10-15 21:50:18 +02:00
|
|
|
customer = User.objects.create_user(username=TEST_USER)
|
|
|
|
package = CustomerHostingPackage.objects.create_from_template(
|
2019-01-30 21:27:25 +01:00
|
|
|
customer, template, "testpackage"
|
|
|
|
)
|
|
|
|
with patch("hostingpackages.models.settings") as hmsettings:
|
2015-10-15 21:50:18 +02:00
|
|
|
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(
|
2019-01-30 21:27:25 +01:00
|
|
|
package, "example.org", True
|
|
|
|
)
|
2015-10-15 21:50:18 +02:00
|
|
|
|
|
|
|
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(
|
2019-01-30 21:27:25 +01:00
|
|
|
package, "example.org", False
|
|
|
|
)
|
2015-10-15 21:50:18 +02:00
|
|
|
|
|
|
|
self.assertIsNotNone(hostingdomain)
|
|
|
|
self.assertTrue(hostingdomain.customer, package.customer)
|
|
|
|
|
2015-11-07 17:10:38 +01:00
|
|
|
|
2015-10-15 21:50:18 +02:00
|
|
|
class HostingDomainTest(TestCase):
|
2015-11-07 17:10:38 +01:00
|
|
|
def test___str__(self):
|
2019-01-30 21:27:25 +01:00
|
|
|
hostingdomain = HostingDomain(domain="test")
|
|
|
|
self.assertEqual(str(hostingdomain), "test")
|