def testdirectorConfig(self): """Test the configuration set and machinery """ test_config = """ [director] disabled = 'no' [broker] disabled = 'no' [agency] disabled = 'no' [aardvark] order = 1 cat = swipe agent = myswipe [bat] order = 0 cat = swipe agent = myswipe """ # Reset and Check that no setup done is caught: config.clear() self.assertRaises(config.ConfigNotSetup, config.get_cfg) # Check we don't get and problems with files... config.set_cfg(test_config) c = config.get_cfg() # This should only contain 5 as the agents should be part of # the agency.agents member: self.assertEquals(len(c.cfg), 3) # This is the default order in which the objects should be recovered: self.assertEquals(c.cfg[0].name, 'director') self.assertEquals(c.cfg[0].order, 0) self.assertEquals(c.cfg[1].name, 'broker') self.assertEquals(c.cfg[1].order, 1) self.assertEquals(c.cfg[2].name, 'agency') self.assertEquals(c.cfg[2].order, 2) # Check the agents are present: agents = c.cfg[2].agents self.assertEquals(len(agents), 2) # Check the default ordering of the recovered agents: self.assertEquals(agents[0].name, 'bat') self.assertEquals(agents[0].order, 0) self.assertEquals(agents[1].name, 'aardvark') self.assertEquals(agents[1].order, 1)
def testConfigErrors(self): """Test the bad configuration handling """ # No director section test_config = "" config.clear() self.assertRaises(config.ConfigError, config.set_cfg, test_config) # Two+ director sections: test_config = """ [director] [director] """ config.clear() self.assertRaises(config.ConfigError, config.set_cfg, test_config) # Two+ broker sections: test_config = """ [director] [broker] [broker] """ config.clear() self.assertRaises(config.ConfigError, config.set_cfg, test_config) # Two+ agency sections: test_config = """ [director] [agency] [agency] """ config.clear() self.assertRaises(config.ConfigError, config.set_cfg, test_config) # Two+ webadmin sections: test_config = """ [director] [webadmin] [webadmin] """ config.clear() self.assertRaises(config.ConfigError, config.set_cfg, test_config)
def testdirectorConfigByNameRecovery(self): """Test that I can get named config objects from the global configuration. """ test_config = """ [director] disabled = 'no' [broker] disabled = 'no' [agency] disabled = 'no' [aardvark] order = 1 cat = swipe agent = myswipe [bat] order = 0 cat = swipe agent = myswipe """ config.clear() config.set_cfg(test_config) c = config.get_cfg() self.assertEquals(c.director is None, False) self.assertEquals(c.broker is None, False) self.assertEquals(c.agency is None, False) self.assertEquals(c.webadmin is None, True) # This is the default order in which the objects should be recovered: self.assertEquals(c.director.name, 'director') self.assertEquals(c.director.order, 0) # Check the agents are present: agents = c.agency.agents self.assertEquals(len(agents), 2) # Check the default ordering of the recovered agents: self.assertEquals(agents[0].name, 'bat') self.assertEquals(agents[0].order, 0) self.assertEquals(agents[1].name, 'aardvark') self.assertEquals(agents[1].order, 1)