# Path: osprofiler/drivers/loginsight.py
# LOG = log.getLogger(__name__)
#     LI_OSPROFILER_AGENT_ID = "F52D775B-6017-4787-8C8A-F21AE0AEC057"
#     SESSIONS_PATH = "api/v1/sessions"
#     CURRENT_SESSIONS_PATH = "api/v1/sessions/current"
#     EVENTS_INGEST_PATH = "api/v1/events/ingest/%s" % LI_OSPROFILER_AGENT_ID
#     QUERY_EVENTS_BASE_PATH = "api/v1/events"
# class LogInsightDriver(base.Driver):
# class LogInsightClient(object):
#     def __init__(
#             self, connection_str, project=None, service=None, host=None,
#             **kwargs):
#     def get_name(cls):
#     def notify(self, info):
#         def _create_field(name, content):
#     def get_report(self, base_id):
#     def __init__(self, host, username, password, api_port=9000,
#                  api_ssl_port=9543, query_timeout=60000):
#     def _build_base_url(self, scheme):
#     def _check_response(self, resp):
#     def _send_request(
#             self, method, scheme, path, headers=None, body=None, params=None):
#     def _get_auth_header(self):
#     def _trunc_session_id(self):
#     def _is_current_session_active(self):
#     def login(self):
#     def send_event(self, event):
#     def query_events(self, params):
#         def _query_events():
# 
# Path: osprofiler/exc.py
# class CommandError(Exception):
# class LogInsightAPIError(Exception):
# class LogInsightLoginTimeout(Exception):
#     def __init__(self, message=None):
#     def __str__(self):
# 
# Path: osprofiler/tests/test.py
# class TestCase(testcase.TestCase):
# class FunctionalTestCase(TestCase):
#     def setUp(self):


import json
import ddt
from unittest import mock
from osprofiler.drivers import loginsight
from osprofiler import exc
from osprofiler.tests import test
        self._client._session_id = "4ff800d1-3175-4b49-9209-39714ea56416"

    def test_check_response_login_timeout(self):
        resp = mock.Mock(status_code=440)
        self.assertRaises(
            exc.LogInsightLoginTimeout, self._client._check_response, resp)

    def test_check_response_api_error(self):
        resp = mock.Mock(status_code=401, ok=False)
        resp.text = json.dumps(
            {"errorMessage": "Invalid username or password.",
             "errorCode": "FIELD_ERROR"})
        e = self.assertRaises(
            exc.LogInsightAPIError, self._client._check_response, resp)
        self.assertEqual("Invalid username or password.", str(e))

    @mock.patch("requests.Request")
    @mock.patch("json.dumps")
    @mock.patch.object(loginsight.LogInsightClient, "_check_response")
    def test_send_request(self, check_resp, json_dumps, request_class):
        req = mock.Mock()
        request_class.return_value = req
        prep_req = mock.sentinel.prep_req
        req.prepare = mock.Mock(return_value=prep_req)

        data = mock.sentinel.data
        json_dumps.return_value = data

        self._client._session = mock.Mock()
        resp = mock.Mock()

# Path: osprofiler/drivers/loginsight.py
# LOG = log.getLogger(__name__)
#     LI_OSPROFILER_AGENT_ID = "F52D775B-6017-4787-8C8A-F21AE0AEC057"
#     SESSIONS_PATH = "api/v1/sessions"
#     CURRENT_SESSIONS_PATH = "api/v1/sessions/current"
#     EVENTS_INGEST_PATH = "api/v1/events/ingest/%s" % LI_OSPROFILER_AGENT_ID
#     QUERY_EVENTS_BASE_PATH = "api/v1/events"
# class LogInsightDriver(base.Driver):
# class LogInsightClient(object):
#     def __init__(
#             self, connection_str, project=None, service=None, host=None,
#             **kwargs):
#     def get_name(cls):
#     def notify(self, info):
#         def _create_field(name, content):
#     def get_report(self, base_id):
#     def __init__(self, host, username, password, api_port=9000,
#                  api_ssl_port=9543, query_timeout=60000):
#     def _build_base_url(self, scheme):
#     def _check_response(self, resp):
#     def _send_request(
#             self, method, scheme, path, headers=None, body=None, params=None):
#     def _get_auth_header(self):
#     def _trunc_session_id(self):
#     def _is_current_session_active(self):
#     def login(self):
#     def send_event(self, event):
#     def query_events(self, params):
#         def _query_events():
# 
# Path: osprofiler/exc.py
# class CommandError(Exception):
# class LogInsightAPIError(Exception):
# class LogInsightLoginTimeout(Exception):
#     def __init__(self, message=None):
#     def __str__(self):
# 
# Path: osprofiler/tests/test.py
# class TestCase(testcase.TestCase):
# class FunctionalTestCase(TestCase):
#     def setUp(self):


# Path: osprofiler/tests/unit/drivers/test_loginsight.py
import json
import ddt
from unittest import mock
from osprofiler.drivers import loginsight
from osprofiler import exc
from osprofiler.tests import test

        self._client._session_id = "4ff800d1-3175-4b49-9209-39714ea56416"

    def test_check_response_login_timeout(self):
        resp = mock.Mock(status_code=440)
        self.assertRaises(
            exc.LogInsightLoginTimeout, self._client._check_response, resp)

    def test_check_response_api_error(self):
        resp = mock.Mock(status_code=401, ok=False)
        resp.text = json.dumps(
            {"errorMessage": "Invalid username or password.",
             "errorCode": "FIELD_ERROR"})
        e = self.assertRaises(
            exc.LogInsightAPIError, self._client._check_response, resp)
        self.assertEqual("Invalid username or password.", str(e))

    @mock.patch("requests.Request")
    @mock.patch("json.dumps")
    @mock.patch.object(loginsight.LogInsightClient, "_check_response")
    def test_send_request(self, check_resp, json_dumps, request_class):
        req = mock.Mock()
        request_class.return_value = req
        prep_req = mock.sentinel.prep_req
        req.prepare = mock.Mock(return_value=prep_req)

        data = mock.sentinel.data
        json_dumps.return_value = data

        self._client._session = mock.Mock()
        resp = mock.Mock()

        self._client._session.send = mock.Mock(return_value=resp)