<commit_before>from cyder.core.system.models import System
from cyder.cydhcp.interface.static_intr.models import StaticInterface
from cyder.cydns.domain.models import Domain
from cyder.api.v1.tests.base import APITests


class StaticInterfaceBase(APITests):
    model = StaticInterface

    def setUp(self):
        Domain.objects.get_or_create(name='arpa')
        self.system, _ = System.objects.get_or_create(name="TestSystem")
        super(StaticInterfaceBase, self).setUp()

    def create_data(self):
        return {
            'ctnr': self.ctnr,
            'description': 'Test Static Interface',
            'ttl': 420,
            'mac': '11:22:33:44:55:00',
            'system': self.system,
            'label': 'stat',
            'domain': self.domain,
            'dhcp_enabled': False,
            'dns_enabled': True,
        }


class StaticInterfaceV4API_Test(StaticInterfaceBase):
    __test__ = True

    def setUp(self):
        super(StaticInterfaceV4API_Test, self).setUp()
        Domain.objects.get_or_create(name='in-addr.arpa')
        Domain.objects.get_or_create(name='11.in-addr.arpa')

    def create_data(self):
        data = super(StaticInterfaceV4API_Test, self).create_data()
        data.update({
            'ip_str': '192.168.127.12',
            'ip_type': '4',
        })
        fack = self.model.objects.filter(**data)
        if fack:
            obj, _ = fack.all()[0]
        else:
            obj, _ = self.model.objects.get_or_create(**data)
        return obj


class StaticInterfaceV6API_Test(StaticInterfaceBase):
    __test__ = True

    def setUp(self):
        super(StaticInterfaceV6API_Test, self).setUp()
        Domain.objects.get_or_create(name='ip6.arpa')
        Domain.objects.get_or_create(name='2.ip6.arpa')

    def create_data(self):
        data = super(StaticInterfaceV6API_Test, self).create_data()
        data.update({
            'ip_str': '2001:0db8:85a3:0000:0000:8a2e:0370:7344',
            'ip_type': '6',
        })
        fack = self.model.objects.filter(**data).all()
        if fack:
            obj, _ = fack[0]
        else:
            obj, _ = self.model.objects.get_or_create(**data)
        return obj<commit_msg>api tests create ranges for interfaces<commit_after>from cyder.core.system.models import System
from cyder.cydhcp.interface.static_intr.models import StaticInterface
from cyder.cydhcp.range.models import Range
from cyder.cydhcp.network.models import Network
from cyder.cydns.domain.models import Domain
from cyder.api.v1.tests.base import APITests


class StaticInterfaceBase(APITests):
    model = StaticInterface

    def setUp(self):
        Domain.objects.get_or_create(name='arpa')
        self.system, _ = System.objects.get_or_create(name="TestSystem")
        super(StaticInterfaceBase, self).setUp()

    def create_data(self):
        return {
            'ctnr': self.ctnr,
            'description': 'Test Static Interface',
            'ttl': 420,
            'mac': '11:22:33:44:55:00',
            'system': self.system,
            'label': 'stat',
            'domain': self.domain,
            'dhcp_enabled': False,
            'dns_enabled': True,
        }


class StaticInterfaceV4API_Test(StaticInterfaceBase):
    __test__ = True

    def setUp(self):
        super(StaticInterfaceV4API_Test, self).setUp()
        Domain.objects.get_or_create(name='in-addr.arpa')
        Domain.objects.get_or_create(name='11.in-addr.arpa')
        self.net = Network(network_str='11.12.14.0/8', ip_type='4')
        self.net.update_network()
        self.net.save()
        self.range = Range(network=self.net, range_type='st',
                           ip_type='4', start_str='11.12.14.253',
                           end_str='11.12.14.254')
        self.range.save()

    def create_data(self):
        data = super(StaticInterfaceV4API_Test, self).create_data()
        data.update({
            'ip_str': '11.12.14.253',
            'ip_type': '4',
        })
        fack = self.model.objects.filter(**data)
        if fack:
            obj, _ = fack.all()[0]
        else:
            obj, _ = self.model.objects.get_or_create(**data)
        return obj


class StaticInterfaceV6API_Test(StaticInterfaceBase):
    __test__ = True

    def setUp(self):
        super(StaticInterfaceV6API_Test, self).setUp()
        Domain.objects.get_or_create(name='ip6.arpa')
        Domain.objects.get_or_create(name='2.ip6.arpa')
        self.net = Network(network_str='2001::/16', ip_type='6')
        self.net.update_network()
        self.net.save()
        self.range = Range(network=self.net, range_type='st',
                           ip_type='6', start_str='2001::1',
                           end_str='fd00:c2b6:b24b:be67:2827:688d:e6a1:6a3b')
        self.range.save()

    def create_data(self):
        data = super(StaticInterfaceV6API_Test, self).create_data()
        data.update({
            'ip_str': '2001:0db8:85a3:0000:0000:8a2e:0370:7344',
            'ip_type': '6',
        })
        fack = self.model.objects.filter(**data).all()
        if fack:
            obj, _ = fack[0]
        else:
            obj, _ = self.model.objects.get_or_create(**data)
        return obj
{'fraction_non_alphanumeric': 0.13018433179723501, 'fraction_numerical': 0.03763440860215054, 'mean_word_length': 2.3455362877328194, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 5, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5624036', 'n_tokens_mistral': 1818, 'n_tokens_neox': 1677, 'n_words': 260}