from django.core.exceptions import ValidationError

from cyder.cydns.address_record.models import AddressRecord
from .basestatic import BaseStaticTests


class AStaticRegTests(BaseStaticTests):
    def test_conflict(self):
        # Add an intr and make sure A can't exist.
        domain = self.f_c
        ip_str = "10.0.0.2"

        def i():
            return self.create_si(
                mac="11:22:33:44:55:66",
                label="foo4",
                domain=domain,
                ip_str=ip_str,
            )
        i.name = 'StaticInterface'

        def a():
            return AddressRecord.objects.create(
                label="foo5",
                domain=domain,
                ip_str=ip_str,
                ctnr=self.ctnr,
            )
        a.name = 'AddressRecord'

        self.assertObjectsConflict((i, a))

    def test_conflict_add_intr_first(self):
        # Add an intr and update an existing A to conflict. Test for exception.
        label = "fo99"
        domain = self.f_c

        self.create_si(
            mac="12:22:33:44:55:66",
            label=label,
            domain=domain,
            ip_str='10.0.0.2',
        )

        a = AddressRecord.objects.create(
            label=label,
            domain=domain,
            ip_str='10.0.0.3',
            ctnr=self.ctnr,
        )

        a.ip_str = "10.0.0.2"
        self.assertRaises(ValidationError, a.save)

    def test_conflict_add_A_first(self):
        # Add an A and update and existing intr to conflict. Test for
        # exception.
        label = "foo98"
        domain = self.f_c

        AddressRecord.objects.create(
            label=label,
            domain=domain,
            ip_str='10.0.0.2',
            ctnr=self.ctnr,
        )

        intr = self.create_si(
            mac="11:22:33:44:55:66",
            label=label,
            domain=domain,
            ip_str='10.0.0.3',
        )

        intr.ip_str = "10.0.0.2"
        self.assertRaises(ValidationError, intr.save)

@@ -967,31 +967,8 @@
 on.%0A
-        label = %22fo99%22%0A
     
@@ -981,32 +981,32 @@
 main = self.f_c%0A
+
 %0A        self.cr
@@ -1061,37 +1061,38 @@
           label=
-label
+%22fo99%22
 ,%0A            do
@@ -1198,37 +1198,39 @@
           label=
-label
+%22fo999%22
 ,%0A            do
@@ -1530,32 +1530,8 @@
 on.%0A
-        label = %22foo98%22%0A
     
@@ -1601,37 +1601,39 @@
           label=
-label
+%22foo98%22
 ,%0A            do
@@ -1801,21 +1801,24 @@
   label=
-label
+%22foo987%22
 ,%0A      

make interface/ar conflict tests even more strict