pvl/hosts/tests.py
changeset 472 814cc88c531b
parent 471 e4b4458d8061
child 473 68fd85d850ab
--- a/pvl/hosts/tests.py	Wed Feb 25 15:24:49 2015 +0200
+++ b/pvl/hosts/tests.py	Wed Feb 25 15:37:46 2015 +0200
@@ -255,7 +255,73 @@
         #self.assertZoneEquals(zone.host_forward(h, 'bar.domain'), {
         #    ('test', 'CNAME'): ['host.foo'],
         #})
- 
+
+    def testHostsForward(self):
+        hosts = [
+                host.Host.build('foo', 'domain',
+                    ip      = '192.0.2.1',
+                    ip6     = '2001:db8::192.0.2.1',
+                    alias   = 'test',
+                ),
+                host.Host.build('bar', 'domain',
+                    ip      = '192.0.2.2',
+                )
+        ]
+
+        self.assertZoneEquals(zone.apply_hosts_forward(self.options, hosts, 'domain'), {
+            ('foo', 'A'): ['192.0.2.1'],
+            ('foo', 'AAAA'): ['2001:db8::c000:201'],
+            ('test', 'CNAME'): ['foo'],
+            ('bar', 'A'): ['192.0.2.2'],
+        })
+
+    def testHostsConflict(self):
+        hosts = [
+                host.Host.build('foo', 'domain',
+                    ip      = '192.0.2.1',
+                ),
+                host.Host.build('foo', 'domain',
+                    ip      = '192.0.2.2',
+                )
+        ]
+        
+        with self.assertRaises(zone.HostZoneError):
+            self.assertZoneEquals(zone.apply_hosts_forward(self.options, hosts, 'domain'), { })
+
+    def testHostsAliasConflict(self):
+        hosts = [
+                host.Host.build('foo', 'domain',
+                    ip          = '192.0.2.1',
+                ),
+                host.Host.build('bar', 'domain',
+                    ip          = '192.0.2.2',
+                    alias       = 'foo',
+                )
+        ]
+        
+        # with A first
+        with self.assertRaises(zone.HostZoneError):
+            self.assertZoneEquals(zone.apply_hosts_forward(self.options, hosts, 'domain'), { })
+    
+        # also with CNAME first
+        with self.assertRaises(zone.HostZoneError):
+            self.assertZoneEquals(zone.apply_hosts_forward(self.options, reversed(hosts), 'domain'), { })
+
+    def testHostsAlias4Conflict(self):
+        hosts = [
+                host.Host.build('foo', 'domain',
+                    ip          = '192.0.2.1',
+                ),
+                host.Host.build('bar', 'domain',
+                    ip          = '192.0.2.2',
+                    alias4      = 'foo',
+                )
+        ]
+        
+        with self.assertRaises(zone.HostZoneError):
+            self.assertZoneEquals(zone.apply_hosts_forward(self.options, hosts, 'domain'), { })
+    
+
 class TestReverseZone(TestZoneMixin, unittest.TestCase):
     def setUp(self):
         self.options = Options()