Example #1
0
 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)
Example #2
0
    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)
Example #3
0
    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)
Example #4
0
    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)
Example #5
0
    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)
Example #6
0
    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)
Example #7
0
    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)
Example #8
0
    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)
Example #9
0
    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)
Example #10
0
    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)
Example #11
0
    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)
Example #12
0
    def test_default_params(self):
        env_store = Env()

        self.assertEqual(env_store.separator, None)
        self.assertEqual(env_store.match, None)
        self.assertEqual(env_store.whitelist, None)
        self.assertEqual(env_store.parse_values, False)
        self.assertEqual(env_store.to_lower, False)
        self.assertEqual(env_store.convert_underscores, False)
Example #13
0
    def test_optional_params(self):
        env_store = Env(separator=TEST_SEPARATOR,
                        match=TEST_MATCH,
                        whitelist=TEST_WHITELIST,
                        parse_values=TEST_PARSE_VALUES,
                        to_lower=TEST_TO_LOWER,
                        convert_underscores=TEST_CONVERT_UNDERSCORES)

        self.assertEqual(env_store.separator, TEST_SEPARATOR)
        self.assertEqual(env_store.match, TEST_MATCH)
        self.assertEqual(env_store.whitelist, TEST_WHITELIST)
        self.assertEqual(env_store.parse_values, TEST_PARSE_VALUES)
        self.assertEqual(env_store.to_lower, TEST_TO_LOWER)
        self.assertEqual(env_store.convert_underscores,
                         TEST_CONVERT_UNDERSCORES)
Example #14
0
 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)
Example #15
0
 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)
Example #16
0
 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)
Example #17
0
 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)