pvl/hosts/tests.py
changeset 511 99043eab9140
parent 510 368a568412ed
child 513 3b45b4fd5102
equal deleted inserted replaced
510:368a568412ed 511:99043eab9140
    97 
    97 
    98     def testApplyHostsFileError(self):
    98     def testApplyHostsFileError(self):
    99         with self.assertRaises(config.HostConfigError):
    99         with self.assertRaises(config.HostConfigError):
   100             list(config.apply_hosts_files(self.options, ['nonexistant']))
   100             list(config.apply_hosts_files(self.options, ['nonexistant']))
   101 
   101 
   102     def testApplyHostsFile(self):
   102     def testApplyHostsConfig(self):
   103         conf_file = ConfFile('test', """
   103         conf_file = ConfFile('test', """
   104 [foo]
   104 [foo]
   105     ip = 127.0.0.1
   105     ip = 127.0.0.1
   106 
   106 
   107 [bar]
   107 [bar]
   108     ip = 127.0.0.2
   108     ip = 127.0.0.2
   109         """)
   109         """)
   110         expected = [
   110         
       
   111         self.assertHostsEqual(config.apply_hosts_config(self.options, conf_file), [
   111                 ('foo@test', dict(ip=ipaddr.IPAddress('127.0.0.1'))),
   112                 ('foo@test', dict(ip=ipaddr.IPAddress('127.0.0.1'))),
   112                 ('bar@test', dict(ip=ipaddr.IPAddress('127.0.0.2'))),
   113                 ('bar@test', dict(ip=ipaddr.IPAddress('127.0.0.2'))),
   113         ]
   114         ])
   114 
   115 
   115         self.assertHostsEqual(config.apply_hosts_config(self.options, conf_file), expected)
   116     def testApplyHostsConfigNested(self):
       
   117         conf_file = ConfFile('test', """
       
   118 [asdf]
       
   119     [[foo]]
       
   120         ip = 127.0.0.1
       
   121 
       
   122 [quux]
       
   123     [[bar]]
       
   124         ip = 127.0.0.2
       
   125         """)
       
   126 
       
   127         self.assertHostsEqual(config.apply_hosts_config(self.options, conf_file), [
       
   128                 ('foo@asdf.test', dict(ip=ipaddr.IPAddress('127.0.0.1'))),
       
   129                 ('bar@quux.test', dict(ip=ipaddr.IPAddress('127.0.0.2'))),
       
   130         ])
   116 
   131 
   117     def testApplyIncludes(self):
   132     def testApplyIncludes(self):
   118         self.assertHostsEqual(config.apply_hosts_files(self.options, ['etc/hosts/includes.test']), [
   133         self.assertHostsEqual(config.apply_hosts_files(self.options, ['etc/hosts/includes.test']), [
   119                 ('foo@includes.test', dict(
   134                 ('foo@includes.test', dict(
   120                     ip          = ipaddr.IPAddress('192.0.2.1'),
   135                     ip          = ipaddr.IPAddress('192.0.2.1'),
   127                 )),
   142                 )),
   128         ])
   143         ])
   129 
   144 
   130     def testApplyDirectory(self):
   145     def testApplyDirectory(self):
   131         self.assertHostsEqual(config.apply_hosts_files(self.options, ['etc/hosts/included.test/']), [
   146         self.assertHostsEqual(config.apply_hosts_files(self.options, ['etc/hosts/included.test/']), [
       
   147                 ('quux@asdf.included.test', dict(
       
   148                     ip          = ipaddr.IPAddress('192.0.2.5'),
       
   149                 )),
   132                 ('foo@included.test', dict(
   150                 ('foo@included.test', dict(
   133                     ip          = ipaddr.IPAddress('192.0.2.1'),
   151                     ip          = ipaddr.IPAddress('192.0.2.1'),
   134                 )),
   152                 )),
   135                 ('bar@included.test', dict(
   153                 ('bar@included.test', dict(
   136                     ip          = ipaddr.IPAddress('192.0.2.2'),
   154                     ip          = ipaddr.IPAddress('192.0.2.2'),