pvl.hosts.hosts: fix sort_key()
authorTero Marttila <tero.marttila@aalto.fi>
Tue, 24 Feb 2015 17:45:45 +0200
changeset 441 f058fff1f272
parent 440 1d755df7bf97
child 442 487d4b5faad4
pvl.hosts.hosts: fix sort_key()
pvl/hosts/host.py
pvl/hosts/tests.py
--- a/pvl/hosts/host.py	Tue Feb 24 17:35:36 2015 +0200
+++ b/pvl/hosts/host.py	Tue Feb 24 17:45:45 2015 +0200
@@ -188,7 +188,7 @@
         """
 
         if self.ip :
-            return host.ip
+            return self.ip
         else :
             # sorts first
             return ipaddr.IPAddress(0)
--- a/pvl/hosts/tests.py	Tue Feb 24 17:35:36 2015 +0200
+++ b/pvl/hosts/tests.py	Tue Feb 24 17:45:45 2015 +0200
@@ -18,6 +18,19 @@
     def setUp(self):
         self.options = Options()
 
+    def testApply(self):
+        expected = [
+            ('foo', 'test', ipaddr.IPAddress('127.0.0.1')),
+            ('bar', 'test', ipaddr.IPAddress('127.0.0.2')),
+        ]
+
+        for expect, host in zip(expected, config.apply(self.options, ['etc/hosts/test'])):
+            hostname, domain, ip = expect
+
+            self.assertEquals(str(host), hostname)
+            self.assertEquals(host.domain, domain)
+            self.assertEquals(host.ip, ip)
+ 
     def testApplyHostsError(self):
         with self.assertRaises(config.HostConfigError):
             list(config.apply_hosts(self.options, ['nonexistant']))