def list_tests(args): from vigilo.vigiconf.lib.confclasses.test import TestFactory testfactory = TestFactory(confdir=settings["vigiconf"].get("confdir")) available_hclasses = sorted(testfactory.get_hclasses()) wrapper = textwrap.TextWrapper( initial_indent=' ' * 4, subsequent_indent=' ' * 4, break_long_words=False, ) print _("Available host classes:") for line in wrapper.wrap(", ".join(available_hclasses) + "."): print line if not args.classes: hclasses = available_hclasses else: hclasses = set() for hclass in args.classes: if hclass not in available_hclasses: LOGGER.warning(_("No such host class '%s'"), hclass) else: hclasses.add(hclass) if not hclasses: return for hclass in hclasses: testnames = sorted(testfactory.get_testnames([hclass])) print "\n" + (_("Tests for host class '%s':") % hclass) for line in wrapper.wrap(", ".join(testnames) + "."): print line
class TestFactoryTest(unittest.TestCase): def setUp(self): setup_db() self.testfactory = TestFactory(confdir=settings["vigiconf"]["confdir"]) self.host = Host( conf.hostsConf, "dummy", "testserver1", "192.168.1.1", "Servers", ) def tearDown(self): teardown_db() def test_get_testnames(self): """Test for the get_testname method""" testnames = self.testfactory.get_testnames() self.assertTrue("UpTime" in testnames, "get_testnames does not work") def test_get_hclasses(self): """Test for the get_hclasses method""" hclasses = self.testfactory.get_hclasses() self.assertTrue("all" in hclasses, "get_hclasses does not work") def test_list_test_paths(self): """ La liste des chemins des tests doit contenir ceux de VigiConf et ceux de l'admin sys """ default_path = os.path.normpath(os.path.join( os.path.dirname(__file__), "..", "tests")) sysadmin_path = os.path.join(settings["vigiconf"]["confdir"], "tests") print self.testfactory.path self.assertTrue(len(self.testfactory.path) >= 2) self.assertEqual(self.testfactory.path[0], default_path) self.assertEqual(self.testfactory.path[-1], sysadmin_path)