# Path: castellan/common/exception.py
# _FATAL_EXCEPTION_FORMAT_ERRORS = False
# class RedirectException(Exception):
# class CastellanException(Exception):
# class Forbidden(CastellanException):
# class KeyManagerError(CastellanException):
# class ManagedObjectNotFoundError(CastellanException):
# class InvalidManagedObjectDictError(CastellanException):
# class UnknownManagedObjectTypeError(CastellanException):
# class AuthTypeInvalidError(CastellanException):
# class InsufficientCredentialDataError(CastellanException):
#     def __init__(self, url):
#     def __init__(self, message_arg=None, *args, **kwargs):
# 
# Path: castellan/common/utils.py
# LOG = logging.getLogger(__name__)
# OPT_GROUP = 'key_manager'
# def credential_factory(conf=None, context=None):
# 
# Path: castellan/tests/base.py
# class TestCase(base.BaseTestCase):
# class CertificateTestCase(TestCase):
# class KeyTestCase(TestCase):
#     def _create_cert(self):
#     def setUp(self):
#     def _create_key(self):
#     def setUp(self):


from castellan.common import exception
from castellan.common import utils
from castellan.tests import base
from oslo_config import cfg
from oslo_config import fixture as config_fixture
from oslo_context import context

    def setUp(self):
        super(TestUtils, self).setUp()
        self.config_fixture = self.useFixture(config_fixture.Config(CONF))
        CONF.register_opts(utils.credential_opts, group=utils.OPT_GROUP)

    def test_token_credential(self):
        token_value = 'ec9799cd921e4e0a8ab6111c08ebf065'

        self.config_fixture.config(
            auth_type='token',
            token=token_value,
            group='key_manager'
        )

        token_context = utils.credential_factory(conf=CONF)
        token_context_class = token_context.__class__.__name__

        self.assertEqual('Token', token_context_class)
        self.assertEqual(token_value, token_context.token)

    def test_token_credential_with_context(self):
        token_value = 'ec9799cd921e4e0a8ab6111c08ebf065'
        ctxt = context.RequestContext(auth_token=token_value)

        self.config_fixture.config(
            auth_type='token',
            group='key_manager'
        )


# Path: castellan/common/exception.py
# _FATAL_EXCEPTION_FORMAT_ERRORS = False
# class RedirectException(Exception):
# class CastellanException(Exception):
# class Forbidden(CastellanException):
# class KeyManagerError(CastellanException):
# class ManagedObjectNotFoundError(CastellanException):
# class InvalidManagedObjectDictError(CastellanException):
# class UnknownManagedObjectTypeError(CastellanException):
# class AuthTypeInvalidError(CastellanException):
# class InsufficientCredentialDataError(CastellanException):
#     def __init__(self, url):
#     def __init__(self, message_arg=None, *args, **kwargs):
# 
# Path: castellan/common/utils.py
# LOG = logging.getLogger(__name__)
# OPT_GROUP = 'key_manager'
# def credential_factory(conf=None, context=None):
# 
# Path: castellan/tests/base.py
# class TestCase(base.BaseTestCase):
# class CertificateTestCase(TestCase):
# class KeyTestCase(TestCase):
#     def _create_cert(self):
#     def setUp(self):
#     def _create_key(self):
#     def setUp(self):


# Path: castellan/tests/unit/test_utils.py
from castellan.common import exception
from castellan.common import utils
from castellan.tests import base
from oslo_config import cfg
from oslo_config import fixture as config_fixture
from oslo_context import context


    def setUp(self):
        super(TestUtils, self).setUp()
        self.config_fixture = self.useFixture(config_fixture.Config(CONF))
        CONF.register_opts(utils.credential_opts, group=utils.OPT_GROUP)

    def test_token_credential(self):
        token_value = 'ec9799cd921e4e0a8ab6111c08ebf065'

        self.config_fixture.config(
            auth_type='token',
            token=token_value,
            group='key_manager'
        )

        token_context = utils.credential_factory(conf=CONF)
        token_context_class = token_context.__class__.__name__

        self.assertEqual('Token', token_context_class)
        self.assertEqual(token_value, token_context.token)

    def test_token_credential_with_context(self):
        token_value = 'ec9799cd921e4e0a8ab6111c08ebf065'
        ctxt = context.RequestContext(auth_token=token_value)

        self.config_fixture.config(
            auth_type='token',
            group='key_manager'
        )


        token_context = utils.credential_factory(conf=CONF, context=ctxt)