# Path: monitoring/api/client.py
# def _get_auth_params_from_request(request):
#     """Extracts the properties from the request object needed by the monascaclient call below.
# 
#      These will be used to memoize the calls to monascaclient
#     """
# 
#     LOG.debug('Extracting intel from request')
#     return (
#         request.user.user_domain_id,
#         request.user.token.id,
#         request.user.tenant_id,
#         request.user.token.project.get('domain_id'),
#         base.url_for(request, MONITORING_SERVICE),
#         base.url_for(request, KEYSTONE_SERVICE)
#     )
# 
# Path: monitoring/api/client.py
# def _get_to_verify(insecure, cacert):
#     to_verify = cacert
# 
#     if insecure:
#         to_verify = False
# 
#     return to_verify
# 
# Path: monitoring/api/client.py
# @memoized.memoized
# def monascaclient(request, version=None):
# 
#     (
#         user_domain_id,
#         token_id,
#         project_id,
#         project_domain_id,
#         monasca_url,
#         auth_url
#     ) = _get_auth_params_from_request(request)
# 
#     # NOTE(trebskit) this is bit hacky, we should
#     # go straight into using numbers as version representation
#     version = (VERSIONS.get_active_version()['version']
#                if not version else version)
# 
#     LOG.debug('Monasca::Client <Url: %s> <Version: %s>'
#               % (monasca_url, version))
# 
#     to_verify = _get_to_verify(INSECURE, CACERT)
# 
#     c = mon_client.Client(api_version=version,
#                           token=token_id,
#                           project_id=project_id,
#                           user_domain_id=user_domain_id,
#                           project_domain_id=project_domain_id,
#                           verify=to_verify,
#                           auth_url=auth_url,
#                           endpoint=monasca_url)
#     return c
# 
# Path: monitoring/test/helpers.py
# class MonitoringTestsMixin(object):
# class TestCase(MonitoringTestsMixin, helpers.TestCase):
# class BaseAdminViewTests(MonitoringTestsMixin, helpers.BaseAdminViewTests):
# class APITestCase(MonitoringTestsMixin, helpers.APITestCase):
#     def _setup_test_data(self):


from django.conf import settings as d_settings
from django.test.utils import override_settings
from unittest.mock import Mock
from unittest.mock import patch
from monascaclient import client as mon_client
from monascaclient import v2_0
from monitoring.api.client import _get_auth_params_from_request
from monitoring.api.client import _get_to_verify
from monitoring.api.client import monascaclient as api_mon_client
from monitoring.test import helpers
        (
            version,
            token,
            project_id,
            user_domain_id,
            project_domain_id,
            verify,
            auth_url,
            endpoint
        ) = _mock_client_args(cert)

        the_client = mon_client.Client(
            api_version=version,
            token=token,
            project_id=project_id,
            user_domain_id=user_domain_id,
            project_domain_id=project_domain_id,
            verify=verify,
            auth_url=auth_url,
            endpoint=endpoint
        )

        self.assertIsNotNone(the_client)
        mock_session.assert_called_with(_expected_session_args(cert))

    @patch('monascaclient.client.Client')
    def test_api_monascaclient_calls_client_with_correct_parameters(self, mock_Client):
        with patch('openstack_dashboard.api.base.url_for',
                   side_effect=_mock_url_for):
            with patch('monitoring.api.client._get_auth_params_from_request',

# Path: monitoring/api/client.py
# def _get_auth_params_from_request(request):
#     """Extracts the properties from the request object needed by the monascaclient call below.
# 
#      These will be used to memoize the calls to monascaclient
#     """
# 
#     LOG.debug('Extracting intel from request')
#     return (
#         request.user.user_domain_id,
#         request.user.token.id,
#         request.user.tenant_id,
#         request.user.token.project.get('domain_id'),
#         base.url_for(request, MONITORING_SERVICE),
#         base.url_for(request, KEYSTONE_SERVICE)
#     )
# 
# Path: monitoring/api/client.py
# def _get_to_verify(insecure, cacert):
#     to_verify = cacert
# 
#     if insecure:
#         to_verify = False
# 
#     return to_verify
# 
# Path: monitoring/api/client.py
# @memoized.memoized
# def monascaclient(request, version=None):
# 
#     (
#         user_domain_id,
#         token_id,
#         project_id,
#         project_domain_id,
#         monasca_url,
#         auth_url
#     ) = _get_auth_params_from_request(request)
# 
#     # NOTE(trebskit) this is bit hacky, we should
#     # go straight into using numbers as version representation
#     version = (VERSIONS.get_active_version()['version']
#                if not version else version)
# 
#     LOG.debug('Monasca::Client <Url: %s> <Version: %s>'
#               % (monasca_url, version))
# 
#     to_verify = _get_to_verify(INSECURE, CACERT)
# 
#     c = mon_client.Client(api_version=version,
#                           token=token_id,
#                           project_id=project_id,
#                           user_domain_id=user_domain_id,
#                           project_domain_id=project_domain_id,
#                           verify=to_verify,
#                           auth_url=auth_url,
#                           endpoint=monasca_url)
#     return c
# 
# Path: monitoring/test/helpers.py
# class MonitoringTestsMixin(object):
# class TestCase(MonitoringTestsMixin, helpers.TestCase):
# class BaseAdminViewTests(MonitoringTestsMixin, helpers.BaseAdminViewTests):
# class APITestCase(MonitoringTestsMixin, helpers.APITestCase):
#     def _setup_test_data(self):


# Path: monitoring/test/test_client.py
from django.conf import settings as d_settings
from django.test.utils import override_settings
from unittest.mock import Mock
from unittest.mock import patch
from monascaclient import client as mon_client
from monascaclient import v2_0
from monitoring.api.client import _get_auth_params_from_request
from monitoring.api.client import _get_to_verify
from monitoring.api.client import monascaclient as api_mon_client
from monitoring.test import helpers

        (
            version,
            token,
            project_id,
            user_domain_id,
            project_domain_id,
            verify,
            auth_url,
            endpoint
        ) = _mock_client_args(cert)

        the_client = mon_client.Client(
            api_version=version,
            token=token,
            project_id=project_id,
            user_domain_id=user_domain_id,
            project_domain_id=project_domain_id,
            verify=verify,
            auth_url=auth_url,
            endpoint=endpoint
        )

        self.assertIsNotNone(the_client)
        mock_session.assert_called_with(_expected_session_args(cert))

    @patch('monascaclient.client.Client')
    def test_api_monascaclient_calls_client_with_correct_parameters(self, mock_Client):
        with patch('openstack_dashboard.api.base.url_for',
                   side_effect=_mock_url_for):
            with patch('monitoring.api.client._get_auth_params_from_request',

                       side_effect=_get_auth_params_from_request):