# Path: barbicanclient/client.py
# LOG = logging.getLogger(__name__)
# _DEFAULT_SERVICE_TYPE = 'key-manager'
# _DEFAULT_SERVICE_INTERFACE = 'public'
# _DEFAULT_API_VERSION = 'v1'
# _SUPPORTED_API_VERSION_MAP = {'v1': 'barbicanclient.v1.client.Client'}
# class _HTTPClient(adapter.Adapter):
# class _LazyImporter(object):
#     def __init__(self, session, project_id=None, **kwargs):
#     def request(self, *args, **kwargs):
#     def get(self, *args, **kwargs):
#     def post(self, path, *args, **kwargs):
#     def _fix_path(self, path):
#     def _get_raw(self, path, *args, **kwargs):
#     def _check_status_code(self, resp):
#     def _get_error_message(self, resp):
# def Client(version=None, session=None, *args, **kwargs):
# def env(*vars, **kwargs):
#     def __init__(self, module):
#     def __getattr__(self, name):
# 
# Path: barbicanclient/exceptions.py
# class BarbicanException(Exception):
# class PayloadException(BarbicanException):
# class UnsupportedVersion(BarbicanException):
# class HTTPError(Exception):
# class HTTPServerError(HTTPError):
# class HTTPClientError(HTTPError):
# class HTTPAuthError(HTTPError):
#     def __init__(self, message, status_code=0):
#     def __init__(self, message, status_code=401):


from unittest import mock
from keystoneauth1 import session
from requests_mock.contrib import fixture
from barbicanclient import client
from barbicanclient import exceptions
import testtools

    def test_gets_error_message_from_content_when_no_json(self):
        resp = mock.MagicMock()
        resp.json.side_effect = ValueError()
        resp.content = content = 'content'
        msg = self.httpclient._get_error_message(resp)
        self.assertEqual(content, msg)

    def test_gets_error_message_from_description_in_json(self):
        resp = mock.MagicMock()
        resp.json.return_value = {'title': 'test_text',
                                  'description': 'oopsie'}
        msg = self.httpclient._get_error_message(resp)
        self.assertEqual('test_text: oopsie', msg)


class BaseEntityResource(testtools.TestCase):

    def _setUp(self, entity, entity_id='abcd1234-eabc-5678-9abc-abcdef012345'):
        super(BaseEntityResource, self).setUp()
        self.responses = self.useFixture(fixture.Fixture())
        self.endpoint = 'http://localhost:9311'
        self.project_id = '1234567'

        self.entity = entity
        self.entity_id = entity_id
        self.entity_base = self.endpoint + "/v1/" + self.entity
        self.entity_href = self.entity_base + "/" + self.entity_id
        self.entity_payload_href = self.entity_href + "/payload"


# Path: barbicanclient/client.py
# LOG = logging.getLogger(__name__)
# _DEFAULT_SERVICE_TYPE = 'key-manager'
# _DEFAULT_SERVICE_INTERFACE = 'public'
# _DEFAULT_API_VERSION = 'v1'
# _SUPPORTED_API_VERSION_MAP = {'v1': 'barbicanclient.v1.client.Client'}
# class _HTTPClient(adapter.Adapter):
# class _LazyImporter(object):
#     def __init__(self, session, project_id=None, **kwargs):
#     def request(self, *args, **kwargs):
#     def get(self, *args, **kwargs):
#     def post(self, path, *args, **kwargs):
#     def _fix_path(self, path):
#     def _get_raw(self, path, *args, **kwargs):
#     def _check_status_code(self, resp):
#     def _get_error_message(self, resp):
# def Client(version=None, session=None, *args, **kwargs):
# def env(*vars, **kwargs):
#     def __init__(self, module):
#     def __getattr__(self, name):
# 
# Path: barbicanclient/exceptions.py
# class BarbicanException(Exception):
# class PayloadException(BarbicanException):
# class UnsupportedVersion(BarbicanException):
# class HTTPError(Exception):
# class HTTPServerError(HTTPError):
# class HTTPClientError(HTTPError):
# class HTTPAuthError(HTTPError):
#     def __init__(self, message, status_code=0):
#     def __init__(self, message, status_code=401):


# Path: barbicanclient/tests/test_client.py
from unittest import mock
from keystoneauth1 import session
from requests_mock.contrib import fixture
from barbicanclient import client
from barbicanclient import exceptions
import testtools


    def test_gets_error_message_from_content_when_no_json(self):
        resp = mock.MagicMock()
        resp.json.side_effect = ValueError()
        resp.content = content = 'content'
        msg = self.httpclient._get_error_message(resp)
        self.assertEqual(content, msg)

    def test_gets_error_message_from_description_in_json(self):
        resp = mock.MagicMock()
        resp.json.return_value = {'title': 'test_text',
                                  'description': 'oopsie'}
        msg = self.httpclient._get_error_message(resp)
        self.assertEqual('test_text: oopsie', msg)


class BaseEntityResource(testtools.TestCase):

    def _setUp(self, entity, entity_id='abcd1234-eabc-5678-9abc-abcdef012345'):
        super(BaseEntityResource, self).setUp()
        self.responses = self.useFixture(fixture.Fixture())
        self.endpoint = 'http://localhost:9311'
        self.project_id = '1234567'

        self.entity = entity
        self.entity_id = entity_id
        self.entity_base = self.endpoint + "/v1/" + self.entity
        self.entity_href = self.entity_base + "/" + self.entity_id
        self.entity_payload_href = self.entity_href + "/payload"


        self.client = client.Client(endpoint=self.endpoint,