def test_parse_config(self): file_config = "TEST = 'run'" expected_config = {'TEST': 'run'} with provide_file_at_root('parse.py', file_config): out_config = parse_config('parse') self.assertEquals(out_config, expected_config)
def test_load_secret_keys_secrets_not_present(self): secrets = tempfile.NamedTemporaryFile() csrf = "notAvailable" application = mock_application() with open(secrets.name, 'w') as f: f.write('secret') with provide_file_at_root('config.py'): from run import load_secret_keys with self.assertRaises(SystemExit) as cmd: load_secret_keys(application, secrets.name, csrf) secrets.close() self.assertEqual(application.config['SECRET_KEY'], b'secret', 'secret key not loaded properly') self.assertEquals(cmd.exception.code, 1, 'function exited with a wrong code')
def test_load_secret_keys_csrf_not_present(self): secrets = "notAvailable" csrf = tempfile.NamedTemporaryFile() application = mock_application() with open(csrf.name, 'w') as f: f.write('csrf') with provide_file_at_root('config.py'): from run import load_secret_keys with self.assertRaises(SystemExit) as cmd: load_secret_keys(application, secrets, csrf.name) csrf.close() self.assertEquals(cmd.exception.code, 1, 'function exited with a wrong code') self.assertEqual(application.config['CSRF_SESSION_KEY'], b'csrf', 'csrf session key not loaded properly')
def test_load_secret_keys_files_present(self): secrets = tempfile.NamedTemporaryFile() csrf = tempfile.NamedTemporaryFile() application = mock_application() with open(secrets.name, 'w') as f: f.write('secret') with open(csrf.name, 'w') as f: f.write('csrf') with provide_file_at_root('config.py'): from run import load_secret_keys load_secret_keys(application, secrets.name, csrf.name) secrets.close() csrf.close() self.assertEqual(application.config['SECRET_KEY'], b'secret', 'secret key not loaded properly') self.assertEqual(application.config['CSRF_SESSION_KEY'], b'csrf', 'csrf session key not loaded properly')