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='2001:ffff:ffff:ffff:ffff:ffff:ffff:fffe')
        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

@@ -8,40 +8,177 @@
 der.
-core.system.models import System
+api.v1.tests.base import APITests%0Afrom cyder.core.system.models import System%0Afrom cyder.cydns.nameserver.models import Nameserver%0Afrom cyder.cydns.soa.models import SOA
 %0Afro
@@ -385,53 +385,8 @@
 ain%0A
-from cyder.api.v1.tests.base import APITests%0A
 %0A%0Acl
@@ -1221,32 +1221,44 @@
 r.arpa')%0A       
+ eleven, _ =
  Domain.objects.
@@ -1287,32 +1287,110 @@
 .in-addr.arpa')%0A
+        Nameserver.objects.get_or_create(domain=eleven, server=%22ns1.foo.com%22)%0A
         self.net
@@ -1674,24 +1674,24 @@
 12.14.254')%0A
-
         self
@@ -1695,32 +1695,174 @@
 elf.range.save()
+%0A        self.soa = SOA(primary='ns1.foo.com', contact='webmaster.foo.com',%0A                       root_domain=eleven)%0A        self.soa.save()
 %0A%0A    def create

Fix broken tests