2015-10-15 21:50:18 +02:00
|
|
|
"""
|
|
|
|
Tests for :py:mod:`domains.models`.
|
|
|
|
|
|
|
|
"""
|
|
|
|
from __future__ import absolute_import, unicode_literals
|
|
|
|
|
2015-12-05 14:47:41 +01:00
|
|
|
from 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
|
|
|
|
|
|
|
|
from domains.models import (
|
2015-11-07 17:10:38 +01:00
|
|
|
DNSComment,
|
|
|
|
DNSCryptoKey,
|
|
|
|
DNSDomain,
|
|
|
|
DNSDomainMetadata,
|
|
|
|
DNSRecord,
|
|
|
|
DNSSupermaster,
|
|
|
|
DNSTSIGKey,
|
2015-10-15 21:50:18 +02:00
|
|
|
DomainBase,
|
|
|
|
HostingDomain,
|
2015-11-07 17:10:38 +01:00
|
|
|
MailDomain,
|
2015-10-15 21:50:18 +02:00
|
|
|
)
|
|
|
|
from hostingpackages.models import (
|
|
|
|
CustomerHostingPackage,
|
|
|
|
HostingPackageTemplate,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
User = get_user_model()
|
2014-05-25 14:53:58 +02:00
|
|
|
|
2015-10-15 21:50:18 +02:00
|
|
|
TEST_USER = 'test'
|
|
|
|
|
|
|
|
|
|
|
|
class DomainBaseTest(TestCase):
|
|
|
|
|
2015-11-07 17:10:38 +01:00
|
|
|
def test___str__(self):
|
2015-10-15 21:50:18 +02:00
|
|
|
db = DomainBase(domain='test')
|
|
|
|
self.assertEqual(str(db), 'test')
|
2014-05-25 14:53:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
class MailDomainTest(TestCase):
|
2015-10-15 21:50:18 +02:00
|
|
|
|
2015-11-07 17:10:38 +01:00
|
|
|
def test___str__(self):
|
2014-05-25 14:53:58 +02: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):
|
|
|
|
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)
|
|
|
|
|
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):
|
2015-10-15 21:50:18 +02:00
|
|
|
hostingdomain = HostingDomain(domain='test')
|
|
|
|
self.assertEqual(str(hostingdomain), 'test')
|
2015-11-07 17:10:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
class DNSDomainTest(TestCase):
|
|
|
|
|
|
|
|
def test___str__(self):
|
|
|
|
dnsdomain = DNSDomain(domain='test')
|
|
|
|
self.assertEqual(str(dnsdomain), 'test')
|
|
|
|
|
|
|
|
|
|
|
|
class DNSRecordTest(TestCase):
|
|
|
|
|
|
|
|
def test___str__(self):
|
|
|
|
dnsrecord = DNSRecord(
|
|
|
|
name='localhost', recordtype='A', content='127.0.0.1')
|
|
|
|
self.assertEqual(str(dnsrecord), 'localhost IN A 127.0.0.1')
|
|
|
|
|
|
|
|
|
|
|
|
class DNSSupermasterTest(TestCase):
|
|
|
|
|
|
|
|
def test___str__(self):
|
|
|
|
dnssupermaster = DNSSupermaster(
|
|
|
|
ip='127.0.0.1', nameserver='dns.example.org')
|
|
|
|
self.assertEqual(str(dnssupermaster), '127.0.0.1 dns.example.org')
|
|
|
|
|
|
|
|
|
|
|
|
class DNSCommentTest(TestCase):
|
|
|
|
|
|
|
|
def test___str__(self):
|
|
|
|
dnscomment = DNSComment(
|
|
|
|
name='localhost', commenttype='A', comment='good stuff')
|
|
|
|
self.assertEqual(str(dnscomment), 'localhost IN A: good stuff')
|
|
|
|
|
|
|
|
|
|
|
|
class DNSDomainMetadataTest(TestCase):
|
|
|
|
|
|
|
|
def test___str__(self):
|
|
|
|
dnsdomain = DNSDomain(domain='test')
|
|
|
|
dnsdomainmetadata = DNSDomainMetadata(
|
|
|
|
domain=dnsdomain, kind='SOA-EDIT', content='INCEPTION')
|
|
|
|
self.assertEqual(str(dnsdomainmetadata), 'test SOA-EDIT INCEPTION')
|
|
|
|
|
|
|
|
|
|
|
|
class DNSCryptoKeyTest(TestCase):
|
|
|
|
|
|
|
|
def test___str__(self):
|
|
|
|
dnsdomain = DNSDomain(domain='test')
|
|
|
|
dnscryptokey = DNSCryptoKey(domain=dnsdomain, content='testvalue')
|
|
|
|
self.assertEqual(str(dnscryptokey), 'test testvalue')
|
|
|
|
|
|
|
|
|
|
|
|
class DNSTSIGKeyTest(TestCase):
|
|
|
|
|
|
|
|
def test___str__(self):
|
|
|
|
dnstsigkey = DNSTSIGKey(
|
|
|
|
name='testkey', algorithm='hmac-md5', secret='dummykey')
|
|
|
|
self.assertEqual(str(dnstsigkey), 'testkey hmac-md5 XXXX')
|