blob: de2b7ad4449d61c7636b19096eb09dfe2007d24f [file] [log] [blame]
Steve McIntyre1f2f47f2014-12-10 23:27:38 +00001import unittest, os, sys
2vlandpath = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0])))
3sys.path.insert(0, vlandpath)
4sys.path.insert(0, "%s/.." % vlandpath)
5
6os.chdir(vlandpath)
7
8from config.config import VlanConfig
9from errors import CriticalError, InputError, ConfigError
10
11class MyTest(unittest.TestCase):
12
13 # Check that we raise on missing database section
14 def test_missing_database_section(self):
15 with self.assertRaisesRegexp(ConfigError, 'No database'):
16 config = VlanConfig(filenames=("/dev/null",))
17
18 # Check that we raise on missing database config values
19 def test_missing_database_config(self):
20 with self.assertRaisesRegexp(ConfigError, 'Invalid database'):
21 config = VlanConfig(filenames=("test-invalid-DB.cfg",))
22
23 # Check that we raise on missing database config values
24 def test_missing_dbname(self):
25 with self.assertRaisesRegexp(ConfigError, 'Database.*incomplete'):
26 config = VlanConfig(filenames=("test-missing-dbname.cfg",))
27
28 # Check that we raise on missing database config values
29 def test_missing_db_username(self):
30 with self.assertRaisesRegexp(ConfigError, 'Database.*incomplete'):
31 config = VlanConfig(filenames=("test-missing-db-username.cfg",))
32
33 # Check that we raise on repeated switch names
34 def test_missing_repeated_switch_names(self):
35 with self.assertRaisesRegexp(ConfigError, 'same name'):
36 config = VlanConfig(filenames=("test-reused-switch-names.cfg",))
37
38 # Check that we raise on unknown config section
39 def test_unknown_config(self):
40 with self.assertRaisesRegexp(ConfigError, 'Unrecognised config'):
41 config = VlanConfig(filenames=("test-unknown-section.cfg",))
42
43 # Check we get expected values on a known-good config
44 def test_known_good(self):
45 config = VlanConfig(filenames=("test-known-good.cfg",))
46 self.assertEqual(len(config.switches), 3)
47 self.assertEqual(config.switches["10.172.2.51"].username, 'cisco')
48 self.assertEqual(config.switches["baz"].driver, 'CiscoSX300')
49
50if __name__ == '__main__':
51 unittest.main()