# Path: cyder/core/ctnr/models.py
# class Ctnr(BaseModel, ObjectUrlMixin):
#     pretty_type = 'container'
# 
#     id = models.AutoField(primary_key=True)
#     name = models.CharField(max_length=100, unique=True,
#                             validators=[validate_ctnr_name])
#     users = models.ManyToManyField(User, null=False, related_name='ctnrs',
#                                    through='CtnrUser', blank=True)
#     domains = models.ManyToManyField(Domain, null=False, blank=True)
#     ranges = models.ManyToManyField(Range, null=False, blank=True)
#     workgroups = models.ManyToManyField(Workgroup, null=False, blank=True)
#     description = models.CharField(max_length=200, blank=True)
#     email_contact = models.CharField(max_length=75, blank=True)
# 
#     search_fields = ('name', 'description', 'email_contact')
#     sort_fields = ('name',)
# 
#     class Meta:
#         app_label = 'cyder'
#         db_table = 'ctnr'
# 
#     @transaction_atomic
#     def save(self, *args, **kwargs):
#         self.full_clean()
# 
#         super(Ctnr, self).save(*args, **kwargs)
# 
# 
#     @transaction_atomic
#     def delete(self, *args, **kwargs):
#         UserProfile = get_model('cyder','userprofile')
#         for user_profile in UserProfile.objects.filter(default_ctnr_id=self.id):
#             user_profile.default_ctnr_id = 1
#             user_profile.save()
#         super(Ctnr, self).delete(*args, **kwargs)
# 
#     def __unicode__(self):
#         return self.name
# 
#     @staticmethod
#     def filter_by_ctnr(ctnr, objects=None):
#         return Ctnr.objects.filter(pk=ctnr.pk)
# 
#     def check_contains_obj(self, obj):
#         if self.name == "global":
#             return True
# 
#         if hasattr(obj, 'check_in_ctnr'):
#             return obj.check_in_ctnr(self)
# 
#         if isinstance(obj, Ctnr):
#             return obj == self
# 
#         if hasattr(obj, 'ctnr'):
#             return obj.ctnr == self
# 
#         for f in [self.users, self.domains, self.ranges, self.workgroups]:
#             m = f.model
#             if isinstance(obj, m):
#                 return f.filter(pk=obj.pk).exists()
# 
#         raise Exception("Permissions check on unknown object type: %s" % type(obj))
# 
#     def details(self):
#         data = super(Ctnr, self).details()
#         data['data'] = (
#             ('Name', 'name', self),
#             ('Description', 'description', self.description),
#         )
#         return data
# 
#     @staticmethod
#     def eg_metadata():
#         """EditableGrid metadata."""
#         return {'metadata': [
#             {'name': 'name', 'datatype': 'string', 'editable': True},
#             {'name': 'description', 'datatype': 'string', 'editable': True},
#         ]}
# 
#     def build_legacy_classes(self, ip_type):
#         if ip_type == '4':
#             ranges = self.ranges.filter(
#                 Q(range_type=DYNAMIC, dhcp_enabled=True) |
#                 Q(start_str='10.255.255.255'), ip_type='4')
#         elif ip_type == '6':
#             ranges = self.ranges.filter(
#                 ip_type='6', range_type=DYNAMIC, dhcp_enabled=True)
# 
#         build_str = ""
#         for range_ in ranges:
#             classname = '{0}:{1}:{2}'.format(
#                 self.name, range_.start_str, range_.end_str)
#             build_str += (
#                 'class "{0}" {{\n'
#                 '\tmatch hardware;\n'
#                 '}}\n'.format(classname))
#             clients = range_.dynamicinterface_set.filter(
#                 system__ctnr=self, dhcp_enabled=True).exclude(mac=None)
#             for client in clients:
#                 build_str += client.build_subclass(classname)
#         return build_str


from django.core.exceptions import ValidationError
from cyder.base.tests import ModelTestMixin
from cyder.core.ctnr.models import Ctnr
from cyder.cydns.address_record.models import AddressRecord
from cyder.cydns.cname.models import CNAME
from cyder.cydns.domain.models import Domain
from cyder.cydns.mx.models import MX
from cyder.cydns.nameserver.models import Nameserver
from cyder.cydns.sshfp.models import SSHFP
from cyder.cydns.soa.models import SOA
from cyder.cydns.srv.models import SRV
from cyder.cydns.txt.models import TXT
from cyder.cydns.tests.utils import create_zone
from .basedomain import BaseDomain
        Domain.objects.create(name="gaz")

    def test__name_to_master_domain(self):
        self.assertRaises(
            ValidationError, Domain.objects.create, name='foo.cn')

        Domain(name='cn').save()
        d = Domain.objects.create(name='foo.cn')
        self.assertRaises(
            ValidationError, Domain.objects.create, name='foo.cn')

    def test_create_domain(self):
        self.assertRaises(
            ValidationError, Domain.objects.create,
            name='foo.bar.oregonstate.edu')

    def test_remove_has_child_domain(self):
        Domain.objects.create(name='com')
        f_c = Domain.objects.create(name='foo.com')
        Domain.objects.create(name='boo.foo.com')
        self.assertRaises(ValidationError, f_c.delete)

    def test_invalid_add(self):
        bad_names = ('asfda.as df', '.', 'edu. ', '', '!@#$')

        for name in bad_names:
            self.assertRaises(
                ValidationError, Domain.objects.create, name=name)

    def test_has_records(self):

# Path: cyder/core/ctnr/models.py
# class Ctnr(BaseModel, ObjectUrlMixin):
#     pretty_type = 'container'
# 
#     id = models.AutoField(primary_key=True)
#     name = models.CharField(max_length=100, unique=True,
#                             validators=[validate_ctnr_name])
#     users = models.ManyToManyField(User, null=False, related_name='ctnrs',
#                                    through='CtnrUser', blank=True)
#     domains = models.ManyToManyField(Domain, null=False, blank=True)
#     ranges = models.ManyToManyField(Range, null=False, blank=True)
#     workgroups = models.ManyToManyField(Workgroup, null=False, blank=True)
#     description = models.CharField(max_length=200, blank=True)
#     email_contact = models.CharField(max_length=75, blank=True)
# 
#     search_fields = ('name', 'description', 'email_contact')
#     sort_fields = ('name',)
# 
#     class Meta:
#         app_label = 'cyder'
#         db_table = 'ctnr'
# 
#     @transaction_atomic
#     def save(self, *args, **kwargs):
#         self.full_clean()
# 
#         super(Ctnr, self).save(*args, **kwargs)
# 
# 
#     @transaction_atomic
#     def delete(self, *args, **kwargs):
#         UserProfile = get_model('cyder','userprofile')
#         for user_profile in UserProfile.objects.filter(default_ctnr_id=self.id):
#             user_profile.default_ctnr_id = 1
#             user_profile.save()
#         super(Ctnr, self).delete(*args, **kwargs)
# 
#     def __unicode__(self):
#         return self.name
# 
#     @staticmethod
#     def filter_by_ctnr(ctnr, objects=None):
#         return Ctnr.objects.filter(pk=ctnr.pk)
# 
#     def check_contains_obj(self, obj):
#         if self.name == "global":
#             return True
# 
#         if hasattr(obj, 'check_in_ctnr'):
#             return obj.check_in_ctnr(self)
# 
#         if isinstance(obj, Ctnr):
#             return obj == self
# 
#         if hasattr(obj, 'ctnr'):
#             return obj.ctnr == self
# 
#         for f in [self.users, self.domains, self.ranges, self.workgroups]:
#             m = f.model
#             if isinstance(obj, m):
#                 return f.filter(pk=obj.pk).exists()
# 
#         raise Exception("Permissions check on unknown object type: %s" % type(obj))
# 
#     def details(self):
#         data = super(Ctnr, self).details()
#         data['data'] = (
#             ('Name', 'name', self),
#             ('Description', 'description', self.description),
#         )
#         return data
# 
#     @staticmethod
#     def eg_metadata():
#         """EditableGrid metadata."""
#         return {'metadata': [
#             {'name': 'name', 'datatype': 'string', 'editable': True},
#             {'name': 'description', 'datatype': 'string', 'editable': True},
#         ]}
# 
#     def build_legacy_classes(self, ip_type):
#         if ip_type == '4':
#             ranges = self.ranges.filter(
#                 Q(range_type=DYNAMIC, dhcp_enabled=True) |
#                 Q(start_str='10.255.255.255'), ip_type='4')
#         elif ip_type == '6':
#             ranges = self.ranges.filter(
#                 ip_type='6', range_type=DYNAMIC, dhcp_enabled=True)
# 
#         build_str = ""
#         for range_ in ranges:
#             classname = '{0}:{1}:{2}'.format(
#                 self.name, range_.start_str, range_.end_str)
#             build_str += (
#                 'class "{0}" {{\n'
#                 '\tmatch hardware;\n'
#                 '}}\n'.format(classname))
#             clients = range_.dynamicinterface_set.filter(
#                 system__ctnr=self, dhcp_enabled=True).exclude(mac=None)
#             for client in clients:
#                 build_str += client.build_subclass(classname)
#         return build_str


# Path: cyder/cydns/domain/tests/basic_tests.py
from django.core.exceptions import ValidationError
from cyder.base.tests import ModelTestMixin
from cyder.core.ctnr.models import Ctnr
from cyder.cydns.address_record.models import AddressRecord
from cyder.cydns.cname.models import CNAME
from cyder.cydns.domain.models import Domain
from cyder.cydns.mx.models import MX
from cyder.cydns.nameserver.models import Nameserver
from cyder.cydns.sshfp.models import SSHFP
from cyder.cydns.soa.models import SOA
from cyder.cydns.srv.models import SRV
from cyder.cydns.txt.models import TXT
from cyder.cydns.tests.utils import create_zone
from .basedomain import BaseDomain

        Domain.objects.create(name="gaz")

    def test__name_to_master_domain(self):
        self.assertRaises(
            ValidationError, Domain.objects.create, name='foo.cn')

        Domain(name='cn').save()
        d = Domain.objects.create(name='foo.cn')
        self.assertRaises(
            ValidationError, Domain.objects.create, name='foo.cn')

    def test_create_domain(self):
        self.assertRaises(
            ValidationError, Domain.objects.create,
            name='foo.bar.oregonstate.edu')

    def test_remove_has_child_domain(self):
        Domain.objects.create(name='com')
        f_c = Domain.objects.create(name='foo.com')
        Domain.objects.create(name='boo.foo.com')
        self.assertRaises(ValidationError, f_c.delete)

    def test_invalid_add(self):
        bad_names = ('asfda.as df', '.', 'edu. ', '', '!@#$')

        for name in bad_names:
            self.assertRaises(
                ValidationError, Domain.objects.create, name=name)

    def test_has_records(self):

        ctnr = Ctnr.objects.get(name='test_ctnr')