def test_get_idempotent(self): pconf.store.env.os.environ = TEST_ENV_VARS env_store = Env() result = env_store.get() self.assertEqual(result, TEST_ENV_VARS) self.assertIsInstance(result, dict) pconf.store.env.os.environ = TEST_ENV_BASE_VARS result = env_store.get() self.assertEqual(result, TEST_ENV_VARS) self.assertIsInstance(result, dict)
def test_convert_underscore_and_separator(self): pconf.store.env.os.environ = TEST_ENV_VARS env_store = Env(separator=TEST_SEPARATOR, convert_underscores=TEST_CONVERT_UNDERSCORES) result = env_store.get() self.assertEqual(result, TEST_ENV_CONVERTED_SEPARATED) self.assertIsInstance(result, dict)
def test_separator(self): pconf.store.env.os.environ = TEST_ENV_VARS env_store = Env(separator=TEST_SEPARATOR) result = env_store.get() self.assertEqual(result, TEST_SEPARATED_VARS) self.assertIsInstance(result, dict)
def test_match(self): pconf.store.env.os.environ = TEST_ENV_VARS env_store = Env(match=TEST_MATCH) result = env_store.get() self.assertEqual(result, TEST_ENV_MATCHED_VARS) self.assertIsInstance(result, dict)
def test_whitelist(self): pconf.store.env.os.environ = TEST_ENV_VARS env_store = Env(whitelist=TEST_WHITELIST) result = env_store.get() self.assertEqual(result, TEST_ENV_WHITELIST_VARS) self.assertIsInstance(result, dict)
def test_docker_secrets_invalid_postfix(self): pconf.store.env.os.environ = TEST_ENV_DOCKER_SECRETS_INVALID_POSTFIX env_store = Env(docker_secrets=TEST_DOCKER_SECRETS_INVALID_POSTFIX) result = env_store.get() self.assertEqual(result, {}) self.assertIsInstance(result, dict)
def test_whitelist_and_match(self): pconf.store.env.os.environ = TEST_ENV_VARS env_store = Env(match=TEST_MATCH, whitelist=TEST_WHITELIST) result = env_store.get() self.assertEqual( result, dict(TEST_ENV_MATCHED_VARS, **TEST_ENV_WHITELIST_VARS)) self.assertIsInstance(result, dict)
def test_get_all_vars(self): pconf.store.env.os.environ = TEST_ENV_VARS env_store = Env() result = env_store.get() self.assertEqual(result, TEST_ENV_VARS) self.assertIsInstance(result, dict)
def test_docker_secrets_nonexistent_file(self, mock_open): simplefilter("ignore") pconf.store.env.os.environ = TEST_ENV_DOCKER_SECRETS env_store = Env(docker_secrets=TEST_DOCKER_SECRETS) result = env_store.get() self.assertEqual(result, {}) self.assertIsInstance(result, dict)
def test_docker_secrets(self): pconf.store.env.os.environ = TEST_ENV_DOCKER_SECRETS env_store = Env(docker_secrets=TEST_DOCKER_SECRETS) result = env_store.get() self.assertEqual(list(result.keys()), list(TEST_DOCKER_SECRETS_RESULT.keys())) self.assertEqual(result, TEST_DOCKER_SECRETS_RESULT) self.assertIsInstance(result, dict)
def test_parse_and_split_order(self): pconf.store.env.os.environ = TEST_ENV_VARS try: env_store = Env(separator=TEST_SEPARATOR, parse_values=TEST_PARSE_VALUES) except AttributeError: self.fail("Parsing environment variables raised AttributeError") result = env_store.get() self.assertEqual(result, TEST_SEPARATED_VARS) self.assertIsInstance(result, dict)
def test_convert_underscore_replacement(self): pconf.store.env.os.environ = TEST_ENV_VARS env_store = Env(convert_underscores=TEST_CONVERT_UNDERSCORES) result = env_store.get() self.assertEqual(result, TEST_ENV_CONVERTED) self.assertIsInstance(result, dict)
def test_lowercase_and_separator(self): pconf.store.env.os.environ = TEST_ENV_UPPERCASE env_store = Env(separator=TEST_SEPARATOR, to_lower=TEST_TO_LOWER) result = env_store.get() self.assertEqual(result, TEST_SEPARATED_VARS) self.assertIsInstance(result, dict)
def test_lowercase_conversion(self): pconf.store.env.os.environ = TEST_ENV_UPPERCASE env_store = Env(to_lower=TEST_TO_LOWER) result = env_store.get() self.assertEqual(result, TEST_ENV_VARS) self.assertIsInstance(result, dict)
def test_parse_values(self): pconf.store.env.os.environ = TEST_ENV_TYPED_VARS env_store = Env(parse_values=TEST_PARSE_VALUES) result = env_store.get() self.assertEqual(result, TEST_ENV_TYPED_VARS_PARSED) self.assertIsInstance(result, dict)