Mercurial > p > roundup > code
comparison test/test_config.py @ 6331:c547e05d7a54
Test case where backend is missing from config.ini.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Tue, 02 Mar 2021 12:43:19 -0500 |
| parents | 6cf9f2f49b89 |
| children | c26b9ce33ae3 |
comparison
equal
deleted
inserted
replaced
| 6330:fbce23af2120 | 6331:c547e05d7a54 |
|---|---|
| 39 #config.LOGGING_FILENAME = "/tmp/logfile" | 39 #config.LOGGING_FILENAME = "/tmp/logfile" |
| 40 #config.LOGGING_LEVEL = "DEBUG" | 40 #config.LOGGING_LEVEL = "DEBUG" |
| 41 config.init_logging() | 41 config.init_logging() |
| 42 config.options['FOO'] = "value" | 42 config.options['FOO'] = "value" |
| 43 | 43 |
| 44 # for TrackerConfig test class | |
| 45 from roundup import instance | |
| 46 from . import db_test_base | |
| 47 | |
| 44 class ConfigTest(unittest.TestCase): | 48 class ConfigTest(unittest.TestCase): |
| 45 | 49 |
| 46 def test_badConfigKeyword(self): | 50 def test_badConfigKeyword(self): |
| 47 """Run configure tests looking for invalid option name | 51 """Run configure tests looking for invalid option name |
| 48 """ | 52 """ |
| 235 self.assertRaises(configuration.OptionValueError, | 239 self.assertRaises(configuration.OptionValueError, |
| 236 config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set, "fred") | 240 config._get_option('WEB_LOGIN_ATTEMPTS_MIN').set, "fred") |
| 237 | 241 |
| 238 self.assertAlmostEqual(config['WEB_LOGIN_ATTEMPTS_MIN'], 3.1415926, | 242 self.assertAlmostEqual(config['WEB_LOGIN_ATTEMPTS_MIN'], 3.1415926, |
| 239 places=6) | 243 places=6) |
| 244 | |
| 245 | |
| 246 class TrackerConfig(unittest.TestCase): | |
| 247 """ Arguably this should be tested in test_instance since it is triggered | |
| 248 by instance.open. But it raises an error in the configuration module | |
| 249 with a missing required param in config.ini.""" | |
| 250 | |
| 251 backend = 'anydbm' | |
| 252 | |
| 253 def setUp(self): | |
| 254 self.dirname = '_test_instance' | |
| 255 # set up and open a tracker | |
| 256 self.instance = db_test_base.setupTracker(self.dirname, self.backend) | |
| 257 | |
| 258 # open the database | |
| 259 self.db = self.instance.open('admin') | |
| 260 | |
| 261 self.db.commit() | |
| 262 self.db.close() | |
| 263 | |
| 264 def tearDown(self): | |
| 265 if self.db: | |
| 266 self.db.close() | |
| 267 try: | |
| 268 shutil.rmtree(self.dirname) | |
| 269 except OSError as error: | |
| 270 if error.errno not in (errno.ENOENT, errno.ESRCH): raise | |
| 271 | |
| 272 | |
| 273 def testNoDBInConfig(self): | |
| 274 # comment out the backend key in config.ini | |
| 275 import fileinput | |
| 276 for line in fileinput.input(os.path.join(self.dirname, "config.ini"), | |
| 277 inplace=True): | |
| 278 if line.startswith("backend = "): | |
| 279 continue | |
| 280 print(line) | |
| 281 | |
| 282 # this should fail as backend isn't defined. | |
| 283 self.assertRaises(configuration.OptionUnsetError, instance.open, | |
| 284 self.dirname) | |
| 285 | |
| 286 |
