# Path: freezer_api/common/config.py
# CONF = cfg.CONF
# AUTH_GROUP, AUTH_OPTS = opts.list_auth_token_opts()[0]
# _DB_DRIVERS = [
#     cfg.StrOpt("backend",
#                help="Database backend section name. This section will "
#                     "be loaded by the proper driver to connect to "
#                     "the database."
#                ),
#     cfg.StrOpt('driver',
#                # default='freezer_api.storage.elastic.ElasticSearchEngine',
#                default='elasticsearch',
#                help="Database driver to be used."
#                )
# ]
#     _COMMON = [
#         cfg.IPOpt('bind-host',
#                   default='0.0.0.0',
#                   dest='bind_host',
#                   help='IP address to listen on. Default is 0.0.0.0'),
#         cfg.PortOpt('bind-port',
#                     default=9090,
#                     dest='bind_port',
#                     help='Port number to listen on. Default is 9090'
#                     ),
#         cfg.BoolOpt('enable_v1_api',
#                     default=False,
#                     help="""Default False, That is the v2 Freezer API
#                     will be deployed. When this option is set
#                     to ``True``, Freezer-api service will respond
#                     to requests on registered endpoints conforming
#                     to the v1 OpenStack Freezer api.
#                     The v1 OpenStack Freezer API functions
#                     as follows:
#                         * Multi-tenancy is not supported under this
#                          api version.
#                         * Everything is user based.
#                         * Freezer api v1 supports Oslo.db.
#                         * Use elasticsearch db with v1 api version
#                     The v2 OpenStack Freezer API functions
#                     as follows:
#                         * Multi-tenancy is supported under this api version.
#                         * Freezer api v2 supports Oslo.db.
#                         * Recommended to use oslo.db with api v2
#                     Possible values:
#                         * True
#                         * False
#                     """)
#     ]
#     _DEFAULT_LOG_LEVELS = ['amqp=WARN', 'amqplib=WARN', 'boto=WARN',
#                            'stevedore=WARN', 'oslo_log=INFO',
#                            'iso8601=WARN', 'elasticsearch=WARN',
#                            'requests.packages.urllib3.connectionpool=WARN',
#                            'urllib3.connectionpool=WARN', 'websocket=WARN',
#                            'keystonemiddleware=WARN', 'routes.middleware=WARN']
#     _DEFAULT_LOGGING_CONTEXT_FORMAT = ('%(asctime)s.%(msecs)03d %(process)d '
#                                        '%(levelname)s %(name)s [%(request_id)s'
#                                        ' %(user_identity)s] %(instance)s '
#                                        '%(message)s')
#     _OPTS = {
#         None: api_common_opts(),
#         'paste_deploy': paste_deploy,
#         AUTH_GROUP: AUTH_OPTS
#     }
# def api_common_opts():
# def register_db_drivers_opt():
# def parse_args(args=[]):
# def setup_logging():
# def find_paste_config():
# def list_opts():
# def set_lib_defaults():
# 
# Path: freezer_api/policy.py
# DEFAULT_POLICY_FILE = 'policy.yaml'
# ENFORCER = None
#         ENFORCER = policy.Enforcer(conf)
# def setup_policy(conf):
# def enforce(rule):
#     def decorator(func):
#         def handler(*args, **kwargs):


import copy
import io
import os
import uuid
import fixtures
import testtools
from oslo_config import cfg
from oslo_config import fixture as cfg_fixture
from freezer_api.common import config
from freezer_api import policy


def get_fake_session_id():
    return uuid.uuid4().hex


class FakeReqResp(object):
    def __init__(self, method='GET', body=''):
        self.method = method
        self.body = body
        self.stream = io.BytesIO(body)
        self.content_length = len(body)
        self.context = {}
        self.header = {}

    def get_header(self, key):
        return self.header.get(key, None)


class FreezerBaseTestCase(testtools.TestCase):
    def setUp(self):
        super(FreezerBaseTestCase, self).setUp()

        self._config_fixture = self.useFixture(cfg_fixture.Config())
        config.parse_args(args=[])
        self.addCleanup(CONF.reset)
        self.test_dir = self.useFixture(fixtures.TempDir()).path
        self.conf_dir = os.path.join(self.test_dir, 'etc')
        os.makedirs(self.conf_dir)
        policy.ENFORCER = None

# Path: freezer_api/common/config.py
# CONF = cfg.CONF
# AUTH_GROUP, AUTH_OPTS = opts.list_auth_token_opts()[0]
# _DB_DRIVERS = [
#     cfg.StrOpt("backend",
#                help="Database backend section name. This section will "
#                     "be loaded by the proper driver to connect to "
#                     "the database."
#                ),
#     cfg.StrOpt('driver',
#                # default='freezer_api.storage.elastic.ElasticSearchEngine',
#                default='elasticsearch',
#                help="Database driver to be used."
#                )
# ]
#     _COMMON = [
#         cfg.IPOpt('bind-host',
#                   default='0.0.0.0',
#                   dest='bind_host',
#                   help='IP address to listen on. Default is 0.0.0.0'),
#         cfg.PortOpt('bind-port',
#                     default=9090,
#                     dest='bind_port',
#                     help='Port number to listen on. Default is 9090'
#                     ),
#         cfg.BoolOpt('enable_v1_api',
#                     default=False,
#                     help="""Default False, That is the v2 Freezer API
#                     will be deployed. When this option is set
#                     to ``True``, Freezer-api service will respond
#                     to requests on registered endpoints conforming
#                     to the v1 OpenStack Freezer api.
#                     The v1 OpenStack Freezer API functions
#                     as follows:
#                         * Multi-tenancy is not supported under this
#                          api version.
#                         * Everything is user based.
#                         * Freezer api v1 supports Oslo.db.
#                         * Use elasticsearch db with v1 api version
#                     The v2 OpenStack Freezer API functions
#                     as follows:
#                         * Multi-tenancy is supported under this api version.
#                         * Freezer api v2 supports Oslo.db.
#                         * Recommended to use oslo.db with api v2
#                     Possible values:
#                         * True
#                         * False
#                     """)
#     ]
#     _DEFAULT_LOG_LEVELS = ['amqp=WARN', 'amqplib=WARN', 'boto=WARN',
#                            'stevedore=WARN', 'oslo_log=INFO',
#                            'iso8601=WARN', 'elasticsearch=WARN',
#                            'requests.packages.urllib3.connectionpool=WARN',
#                            'urllib3.connectionpool=WARN', 'websocket=WARN',
#                            'keystonemiddleware=WARN', 'routes.middleware=WARN']
#     _DEFAULT_LOGGING_CONTEXT_FORMAT = ('%(asctime)s.%(msecs)03d %(process)d '
#                                        '%(levelname)s %(name)s [%(request_id)s'
#                                        ' %(user_identity)s] %(instance)s '
#                                        '%(message)s')
#     _OPTS = {
#         None: api_common_opts(),
#         'paste_deploy': paste_deploy,
#         AUTH_GROUP: AUTH_OPTS
#     }
# def api_common_opts():
# def register_db_drivers_opt():
# def parse_args(args=[]):
# def setup_logging():
# def find_paste_config():
# def list_opts():
# def set_lib_defaults():
# 
# Path: freezer_api/policy.py
# DEFAULT_POLICY_FILE = 'policy.yaml'
# ENFORCER = None
#         ENFORCER = policy.Enforcer(conf)
# def setup_policy(conf):
# def enforce(rule):
#     def decorator(func):
#         def handler(*args, **kwargs):


# Path: freezer_api/tests/unit/common.py
import copy
import io
import os
import uuid
import fixtures
import testtools
from oslo_config import cfg
from oslo_config import fixture as cfg_fixture
from freezer_api.common import config
from freezer_api import policy



def get_fake_session_id():
    return uuid.uuid4().hex


class FakeReqResp(object):
    def __init__(self, method='GET', body=''):
        self.method = method
        self.body = body
        self.stream = io.BytesIO(body)
        self.content_length = len(body)
        self.context = {}
        self.header = {}

    def get_header(self, key):
        return self.header.get(key, None)


class FreezerBaseTestCase(testtools.TestCase):
    def setUp(self):
        super(FreezerBaseTestCase, self).setUp()

        self._config_fixture = self.useFixture(cfg_fixture.Config())
        config.parse_args(args=[])
        self.addCleanup(CONF.reset)
        self.test_dir = self.useFixture(fixtures.TempDir()).path
        self.conf_dir = os.path.join(self.test_dir, 'etc')
        os.makedirs(self.conf_dir)
        policy.ENFORCER = None

        policy.setup_policy(CONF)