Exemplo n.º 1
0
    def test_raise(self, status_code, error_code, expected_exception,
                   requests_mock):
        response_mock = mock.Mock()
        response_mock.status_code = status_code
        response_mock.json.return_value = {
            'error': {
                'code': error_code,
                'details': 'Details',
                'message': 'Message'
            }
        }
        session_mock = mock.Mock()
        session_mock.request.return_value = response_mock
        requests_mock.Session.return_value = session_mock

        api_client = ManagementAPIClient()
        with self.assertRaises(expected_exception) as cm:
            api_client.request('GET', url='/')

        self.assertEqual(cm.exception.details, 'Details')
        self.assertEqual(cm.exception.message, 'Message')
Exemplo n.º 2
0
def query_log_iter(from_, to, hashids=None, **opts):
    """
    Returns an iterator with all the queries done to the search API in a
    period.
    """
    query_params = parse_query_params({
        'from': from_,
        'to': to,
        'hashid': hashids
    })

    api_client = ManagementAPIClient(stream=True, **opts)
    return api_client.request('GET', '/api/v2/stats/query_log', query_params)