# 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, TestCase
from cyder.core.ctnr.models import Ctnr
from cyder.cydns.sshfp.models import SSHFP
from cyder.cydns.domain.models import Domain
                fingerprint_type=1, algorithm_number=1),
            self.create_sshfp(
                label="asdf2", domain=self.o_e,
                key="8d97e98f8af710c7e7fe703abc8f639e0ee507c4",
                fingerprint_type=1, algorithm_number=1),
            self.create_sshfp(
                label="df", domain=self.o_e,
                key="8d97e98f8af710c7e7fe703abc8f639e0ee507c4",
                fingerprint_type=1, algorithm_number=1),
            self.create_sshfp(
                label="12314", domain=self.o_e,
                key="8d97e98f8af710c7e7fe703abc8f639e0ee507c4",
                fingerprint_type=1, algorithm_number=1),
        )

    def test_domain_ctnr(self):
        key = '8d97e98f8af710c7e7fe703abc8f639e0ee507c4'

        ctnr1 = Ctnr.objects.create(name='test_ctnr1')
        ctnr1.domains.add(self.o_e)

        SSHFP.objects.create(
            label='foo',
            domain=self.o_e,
            key=key,
            algorithm_number=1,
            fingerprint_type=1,
            ctnr=ctnr1,
        )


# 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/sshfp/tests/test_models.py
from django.core.exceptions import ValidationError
from cyder.base.tests import ModelTestMixin, TestCase
from cyder.core.ctnr.models import Ctnr
from cyder.cydns.sshfp.models import SSHFP
from cyder.cydns.domain.models import Domain

                fingerprint_type=1, algorithm_number=1),
            self.create_sshfp(
                label="asdf2", domain=self.o_e,
                key="8d97e98f8af710c7e7fe703abc8f639e0ee507c4",
                fingerprint_type=1, algorithm_number=1),
            self.create_sshfp(
                label="df", domain=self.o_e,
                key="8d97e98f8af710c7e7fe703abc8f639e0ee507c4",
                fingerprint_type=1, algorithm_number=1),
            self.create_sshfp(
                label="12314", domain=self.o_e,
                key="8d97e98f8af710c7e7fe703abc8f639e0ee507c4",
                fingerprint_type=1, algorithm_number=1),
        )

    def test_domain_ctnr(self):
        key = '8d97e98f8af710c7e7fe703abc8f639e0ee507c4'

        ctnr1 = Ctnr.objects.create(name='test_ctnr1')
        ctnr1.domains.add(self.o_e)

        SSHFP.objects.create(
            label='foo',
            domain=self.o_e,
            key=key,
            algorithm_number=1,
            fingerprint_type=1,
            ctnr=ctnr1,
        )


        ctnr2 = Ctnr.objects.create(name='test_ctnr2')