# Path: raxcli/config.py
# def get_config(app, default_values=None, config_path=DEFAULT_CONFIG_PATH,
#                env_prefix=DEFAULT_ENV_PREFIX, env_dict=None):
#     """
#     Return dictionary with configuration values for a provided app.
# 
#     @param  app: Name of the app configuration is being retrieved for.
#     @type   app: C{str}
# 
#     @param  default_values: Default configuration values.
#     @type   default_values: C{dict}
# 
#     @param  config_path: Path to the config file.
#     @type   config_path: C{str}
# 
#     @param  env_prefix: Environment variables prefix.
#     @type   env_prefix: C{str}
# 
#     @param  env_dict: Dictionary with environment variables. If not provided,
#                       os.environ is used.
#     @type   env_dict: C{dict}
# 
#     @return Configuration values.
#     @rtype: C{dict}
#     """
#     result = {}
# 
#     if env_dict is None:
#         env_dict = os.environ
# 
#     if default_values is None:
#         default_values = {}
# 
#     keys = [
#         ['global', 'username', 'username'],
#         ['global', 'api_key', 'api_key'],
#         ['global', 'verify_ssl', 'verify_ssl'],
#         ['global', 'auth_url', 'auth_url'],
#     ]
# 
#     env_keys = ['username', 'api_key', 'api_url', 'auth_url', 'verify_ssl']
# 
#     for key in env_keys:
#         env_key = env_prefix + key
#         env_key = env_key.upper()
# 
#         if env_key in env_dict:
#             result[key] = env_dict[env_key]
# 
#     config_path = env_dict.get(env_prefix + 'RAXRC', config_path)
# 
#     config = ConfigParser.ConfigParser()
#     config.read(config_path)
# 
#     for (config_section, config_key, key) in keys:
#         if key in result:
#             # Already specified as an env variable
#             continue
# 
#         # global section
#         try:
#             value = config.get(config_section, config_key)
#         except ConfigParser.Error:
#             pass
#         else:
#             result[key] = value
# 
#         # app specific section
#         try:
#             value = config.get(app, config_key)
#         except ConfigParser.Error:
#             pass
#         else:
#             result[key] = value
# 
#     if 'verify_ssl' in result:
#         result['verify_ssl'] = to_bolean(result['verify_ssl'],
#                                          default_value=True)
# 
#     for key, value in default_values.items():
#         if key not in result:
#             result[key] = value
# 
#     return result
# 
# DEFAULT_ENV_PREFIX = 'RAXCLI_'


import os
import sys
import unittest2 as unittest
from os.path import join as pjoin
from raxcli.config import get_config, DEFAULT_ENV_PREFIX
        self.assertEqual(config['auth_url'], 'http://www.foo.com/2')

    def test_config_from_file_only_app_section(self):
        path1 = os.path.join(FIXTURES_DIR, 'config4.ini')

        config = get_config(app='monitoring', config_path=path1)

        self.assertEqual(config['username'], 'username_mon')
        self.assertEqual(config['api_key'], 'api_key_mon')
        self.assertEqual(config['verify_ssl'], True)

    def test_config_from_file_default_values(self):
        path1 = os.path.join(FIXTURES_DIR, 'config5.ini')

        default_values = {'username': 'username_def', 'api_key': 'api_key_def',
                          'verify_ssl': True, 'auth_url': 'aurl_def'}
        config = get_config(app='monitoring', config_path=path1,
                            default_values=default_values)

        self.assertEqual(config['username'], 'username_def')
        self.assertEqual(config['api_key'], 'api_key_def')
        self.assertEqual(config['verify_ssl'], True)
        self.assertEqual(config['auth_url'], 'aurl_def')

    def test_config_from_file_default_values_and_env(self):
        path1 = os.path.join(FIXTURES_DIR, 'config5.ini')

        default_values = {'username': 'username_def', 'api_key': 'api_key_def',
                          'verify_ssl': True, 'auth_url': 'aurl_def'}
        env_dict = {}

# Path: raxcli/config.py
# def get_config(app, default_values=None, config_path=DEFAULT_CONFIG_PATH,
#                env_prefix=DEFAULT_ENV_PREFIX, env_dict=None):
#     """
#     Return dictionary with configuration values for a provided app.
# 
#     @param  app: Name of the app configuration is being retrieved for.
#     @type   app: C{str}
# 
#     @param  default_values: Default configuration values.
#     @type   default_values: C{dict}
# 
#     @param  config_path: Path to the config file.
#     @type   config_path: C{str}
# 
#     @param  env_prefix: Environment variables prefix.
#     @type   env_prefix: C{str}
# 
#     @param  env_dict: Dictionary with environment variables. If not provided,
#                       os.environ is used.
#     @type   env_dict: C{dict}
# 
#     @return Configuration values.
#     @rtype: C{dict}
#     """
#     result = {}
# 
#     if env_dict is None:
#         env_dict = os.environ
# 
#     if default_values is None:
#         default_values = {}
# 
#     keys = [
#         ['global', 'username', 'username'],
#         ['global', 'api_key', 'api_key'],
#         ['global', 'verify_ssl', 'verify_ssl'],
#         ['global', 'auth_url', 'auth_url'],
#     ]
# 
#     env_keys = ['username', 'api_key', 'api_url', 'auth_url', 'verify_ssl']
# 
#     for key in env_keys:
#         env_key = env_prefix + key
#         env_key = env_key.upper()
# 
#         if env_key in env_dict:
#             result[key] = env_dict[env_key]
# 
#     config_path = env_dict.get(env_prefix + 'RAXRC', config_path)
# 
#     config = ConfigParser.ConfigParser()
#     config.read(config_path)
# 
#     for (config_section, config_key, key) in keys:
#         if key in result:
#             # Already specified as an env variable
#             continue
# 
#         # global section
#         try:
#             value = config.get(config_section, config_key)
#         except ConfigParser.Error:
#             pass
#         else:
#             result[key] = value
# 
#         # app specific section
#         try:
#             value = config.get(app, config_key)
#         except ConfigParser.Error:
#             pass
#         else:
#             result[key] = value
# 
#     if 'verify_ssl' in result:
#         result['verify_ssl'] = to_bolean(result['verify_ssl'],
#                                          default_value=True)
# 
#     for key, value in default_values.items():
#         if key not in result:
#             result[key] = value
# 
#     return result
# 
# DEFAULT_ENV_PREFIX = 'RAXCLI_'


# Path: tests/test_config_parser.py
import os
import sys
import unittest2 as unittest
from os.path import join as pjoin
from raxcli.config import get_config, DEFAULT_ENV_PREFIX

        self.assertEqual(config['auth_url'], 'http://www.foo.com/2')

    def test_config_from_file_only_app_section(self):
        path1 = os.path.join(FIXTURES_DIR, 'config4.ini')

        config = get_config(app='monitoring', config_path=path1)

        self.assertEqual(config['username'], 'username_mon')
        self.assertEqual(config['api_key'], 'api_key_mon')
        self.assertEqual(config['verify_ssl'], True)

    def test_config_from_file_default_values(self):
        path1 = os.path.join(FIXTURES_DIR, 'config5.ini')

        default_values = {'username': 'username_def', 'api_key': 'api_key_def',
                          'verify_ssl': True, 'auth_url': 'aurl_def'}
        config = get_config(app='monitoring', config_path=path1,
                            default_values=default_values)

        self.assertEqual(config['username'], 'username_def')
        self.assertEqual(config['api_key'], 'api_key_def')
        self.assertEqual(config['verify_ssl'], True)
        self.assertEqual(config['auth_url'], 'aurl_def')

    def test_config_from_file_default_values_and_env(self):
        path1 = os.path.join(FIXTURES_DIR, 'config5.ini')

        default_values = {'username': 'username_def', 'api_key': 'api_key_def',
                          'verify_ssl': True, 'auth_url': 'aurl_def'}
        env_dict = {}

        env_dict[DEFAULT_ENV_PREFIX + 'USERNAME'] = 'username_env'