def test_config(self): config.set("test_flag", False) config.save() # Get a hash of the file with open(config.config_path) as f: file_hash = hash(f.read()) # Get a value r = config.get("test_flag") not_r = not r # Innit should not override the existing value config.init("test_flag", not_r) self.assertNotEqual(not_r, config.get("test_flag")) config.set("test_flag", not_r) # Ensure everything is still as it was with open(config.config_path) as f: self.assertEqual(file_hash, hash(f.read())) # Now try to save it config.save() with open(config.config_path) as f: self.assertNotEqual(file_hash, hash(f.read())) # Now try to set a new property config.delete("test_flag2") self.assertEqual(config.check("test_flag2"), False) # Lets set it and then delete it, just to be sure config.set("test_flag2", False) self.assertEqual(config.check("test_flag2"), True) # Now save it, it should have a diffrent hash config.save() with open(config.config_path) as f: self.assertNotEqual(file_hash, hash(f.read())) # Delete the check config.delete("test_flag2") # Check it's all back to how it started config.set("test_flag", False) config.save() with open(config.config_path) as f: self.assertEqual(file_hash, hash(f.read()))
else: host = config.get('db_host') username = config.get('db_username') password = config.get('db_password') dbname = config.get('db_name') except KeyError as e: # We set all the needed keys to be blank and allow # the program to error when making the connection host = "" username = "" password = "" dbname = "" config.init("mock_db_host", "localhost") config.init("mock_db_username", "username") config.init("mock_db_password", "password") config.init("mock_db_name", "profiteer") config.init("db_host", "localhost") config.init("db_username", "username") config.init("db_password", "password") config.init("db_name", "profiteer_mock") config.init("use_mock_db", False) config.save() except Exception as e: raise