# 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 ipaddr import IPv6Address
from cyder.base.tests import TestCase
from cyder.core.ctnr.models import Ctnr
from cyder.cydns.domain.models import Domain
from cyder.cydns.nameserver.models import Nameserver
from cyder.cydns.ptr.models import PTR
from cyder.cydns.soa.models import SOA
from cyder.cydns.tests.utils import make_root
        Nameserver.objects.create(domain=new_domain, server='ns1.unused')
        s = old_domain.root_of_soa.get()
        s.root_domain = new_domain
        s.save()
        old_domain.nameserver_set.all().delete()

    def remove_zone(self, domain):
        domain.soa.delete()
        domain.nameserver_set.all().delete()

    def assertMembers(self, *pairs):
        for p, d in pairs:
            self.assertIn(
                p, d.reverse_ptr_set.all(),
                u'{} has reverse domain {}, not {}'.format(
                    repr(p), repr(p.reverse_domain), repr(d)))

    def test_add1(self):
        self.add_zone(self.one)

        self.assertMembers(
            (self.p2, self.two),
            (self.p3, self.two),
            (self.p4, self.four),
            (self.p5, self.four))

    def test_add3(self):
        self.add_zone(self.three)

        self.assertMembers(

# 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/ptr/tests/test_reverse_domain.py
from django.core.exceptions import ValidationError
from ipaddr import IPv6Address
from cyder.base.tests import TestCase
from cyder.core.ctnr.models import Ctnr
from cyder.cydns.domain.models import Domain
from cyder.cydns.nameserver.models import Nameserver
from cyder.cydns.ptr.models import PTR
from cyder.cydns.soa.models import SOA
from cyder.cydns.tests.utils import make_root

        Nameserver.objects.create(domain=new_domain, server='ns1.unused')
        s = old_domain.root_of_soa.get()
        s.root_domain = new_domain
        s.save()
        old_domain.nameserver_set.all().delete()

    def remove_zone(self, domain):
        domain.soa.delete()
        domain.nameserver_set.all().delete()

    def assertMembers(self, *pairs):
        for p, d in pairs:
            self.assertIn(
                p, d.reverse_ptr_set.all(),
                u'{} has reverse domain {}, not {}'.format(
                    repr(p), repr(p.reverse_domain), repr(d)))

    def test_add1(self):
        self.add_zone(self.one)

        self.assertMembers(
            (self.p2, self.two),
            (self.p3, self.two),
            (self.p4, self.four),
            (self.p5, self.four))

    def test_add3(self):
        self.add_zone(self.three)

        self.assertMembers(

            (self.p2, self.two),