# 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.assertFalse(self._client._is_current_session_active())
        send_request.assert_called_once_with(
            "get", "https", "api/v1/sessions/current",
            headers={"X-LI-Session-Id": self._client._session_id})

    @mock.patch.object(loginsight.LogInsightClient,
                       "_is_current_session_active", return_value=True)
    @mock.patch.object(loginsight.LogInsightClient, "_send_request")
    def test_login_with_current_session_active(self, send_request,
                                               is_current_session_active):
        self._client.login()
        is_current_session_active.assert_called_once_with()
        send_request.assert_not_called()

    @mock.patch.object(loginsight.LogInsightClient,
                       "_is_current_session_active", return_value=False)
    @mock.patch.object(loginsight.LogInsightClient, "_send_request")
    def test_login(self, send_request, is_current_session_active):
        new_session_id = "569a80aa-be5c-49e5-82c1-bb62392d2667"
        resp = {"sessionId": new_session_id}
        send_request.return_value = resp

        self._client.login()
        is_current_session_active.assert_called_once_with()
        exp_body = {"username": self._username, "password": self._password}
        send_request.assert_called_once_with(
            "post", "https", "api/v1/sessions", body=exp_body)
        self.assertEqual(new_session_id, self._client._session_id)


# 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.assertFalse(self._client._is_current_session_active())
        send_request.assert_called_once_with(
            "get", "https", "api/v1/sessions/current",
            headers={"X-LI-Session-Id": self._client._session_id})

    @mock.patch.object(loginsight.LogInsightClient,
                       "_is_current_session_active", return_value=True)
    @mock.patch.object(loginsight.LogInsightClient, "_send_request")
    def test_login_with_current_session_active(self, send_request,
                                               is_current_session_active):
        self._client.login()
        is_current_session_active.assert_called_once_with()
        send_request.assert_not_called()

    @mock.patch.object(loginsight.LogInsightClient,
                       "_is_current_session_active", return_value=False)
    @mock.patch.object(loginsight.LogInsightClient, "_send_request")
    def test_login(self, send_request, is_current_session_active):
        new_session_id = "569a80aa-be5c-49e5-82c1-bb62392d2667"
        resp = {"sessionId": new_session_id}
        send_request.return_value = resp

        self._client.login()
        is_current_session_active.assert_called_once_with()
        exp_body = {"username": self._username, "password": self._password}
        send_request.assert_called_once_with(
            "post", "https", "api/v1/sessions", body=exp_body)
        self.assertEqual(new_session_id, self._client._session_id)


    @mock.patch.object(loginsight.LogInsightClient, "_send_request")