Example #1
0
def test_empty_dps(mock_get):
    """
    Test that we get an exception if the dps array is empty in the JSON response
    """
    mock_get.return_value.content = '{"outputs":[{"id":"nyc:taxi:rides","result":[{ \
                                    "metric":"nyc.taxi.rides","tags":{"host":"localhost"}, \
                                    "aggregatedTags":[],"dps":[]}]}], \
                                    "hints":[],"query": {"querytext":"fetch(\'nyc.taxi.rides\')", \
                                    "startTime":1406831400, \
                                    "startTimeHumanReadableSYS":"July 31, 2014 6:30:00 PM UTC", \
                                    "startTimeHumanReadableIST":"August 1, 2014 12:00:00 AM IST", \
                                    "endTime":1407609000, "endTimeHumanReadableSYS":"August 9,2014 6:30:00 PM UTC", \
                                    "endTimeHumanReadableIST":"August 10, 2014 12:00:00 AM IST", \
                                    "digest":"Mdt8e+HDjnGByMMJdEnTnNdUxKo=:60845", "optionsdigest":"", \
                                    "options":"{}"},"query_stats":{"compactedRows":217, "processedRows":217, \
                                    "dataPointsProcessed":219, "numSeries":1, "queryTimeMillis":152, \
                                    "hbaseTimeMillis":21},"timing_diagnostics": \
                                    [{"tag":"QUERY_EXECUTION_TOTAL_TIME", "instanceCount":1, \
                                    "totalElapsedTimeMillis":152},{"tag":"AST_BUILD_TOTAL_TIME", \
                                    "instanceCount":1, "totalElapsedTimeMillis":29}, \
                                    {"tag":"AST_JYTHON_TOTAL_TIME", "instanceCount":1, \
                                    "totalElapsedTimeMillis":29},{"tag":"STATEMENT_VALIDATION_TOTAL_TIME", \
                                    "instanceCount":1, "totalElapsedTimeMillis":0}, \
                                    {"tag":"PLAN_BUILDING_TOTAL_TIME", "instanceCount":1, \
                                    "totalElapsedTimeMillis":0},{"tag":"QUERY_OPTIMIZATION_TIME", \
                                    "instanceCount":1, "totalElapsedTimeMillis":0}, \
                                    {"tag":"PLAN_EXECUTION_TOTAL_TIME", "instanceCount":1, \
                                    "totalElapsedTimeMillis":106},{"tag":"SCHEMA_SERVICE_FETCH_TOTAL_TIME", \
                                    "instanceCount":1, "totalElapsedTimeMillis":93}, \
                                    {"tag":"DATASOURCE_FETCH_RUN_TIME", "instanceCount":2, \
                                    "totalElapsedTimeMillis":32},{"tag":"TSD_HBASE_TIME", \
                                    "instanceCount":2, "totalElapsedTimeMillis":21}, \
                                    {"tag":"DATASOURCE_FETCH_DP_DECODE_TIME", "instanceCount":2, \
                                    "totalElapsedTimeMillis":52},{"tag":"DATASOURCE_FETCH_DP_DECODE_GET_TAGS_TIME", \
                                    "instanceCount":2, "totalElapsedTimeMillis":51}, \
                                    {"tag":"DATASOURCE_FETCH_DP_DECODE_GET_DPS_TIME", "instanceCount":2, \
                                    "totalElapsedTimeMillis":0},{"tag":"DATASOURCE_FETCH_DP_DECODE_CORE_PROCESSING_TIME", \
                                    "instanceCount":4, "totalElapsedTimeMillis":0}, \
                                    {"tag":"DATASOURCE_FETCH_DP_DECODE_DS_WAIT_TIME", "instanceCount":4, \
                                    "totalElapsedTimeMillis":0},{"tag":"DATASOURCE_FETCH_TOTAL_TIME", \
                                    "instanceCount":1, "totalElapsedTimeMillis":12}, \
                                    {"tag":"PLAN_EXECUTION_JPY_REMOVE_DF_TOTAL_TIME", "instanceCount":1, \
                                    "totalElapsedTimeMillis":17},{"tag":"RESULT_DATA_MARSHALLING_TIME", \
                                    "instanceCount":1, "totalElapsedTimeMillis":0}]}'

    mock_get.return_value.status_code = 200
    token = 'sdksdk203afdsfj_sadasd3939'
    client = Apptuit(sanitize_mode=None, token=token)
    query = "fetch('nyc.taxi.rides')"
    start = 1406831400
    end = 1407609000
    client.query(query, start, end)
Example #2
0
def test_multiple_retries_request_err(mock_get):
    """
    Test that the query API attempts retries when an error is returned from
    the backend API. Since we patch the status code as 504 and create an HTTPError
    as a side effect of the get call, we cannot verify that the retries succeed.
    """
    mock_get.side_effect = requests.exceptions.RequestException
    token = 'sdksdk203afdsfj_sadasd3939'
    client = Apptuit(sanitize_mode=None, token=token)
    query = "fetch('nyc.taxi.rides')"
    start = 1406831400
    end = 1407609000
    with assert_raises(requests.exceptions.RequestException):
        client.query(query, start, end, retry_count=3)
    assert_equals(mock_get.call_count, 4)
Example #3
0
def test_get_error_retry_with_SSLError(mock_get):
    """
    Test that when the retry_count is 0 for the query API we get an exception
    """
    mock_get.return_value.content = get_mock_response()
    mock_get.return_value.status_code = 404
    err_response = Response()
    err_response.status_code = 505
    mock_get.return_value.raise_for_status.side_effect = requests.exceptions.SSLError(response=err_response)
    token = 'sdksdk203afdsfj_sadasd3939'
    client = Apptuit(sanitize_mode=None, token=token)
    query = "fetch('nyc.taxi.rides')"
    start = 1406831400
    end = 1407609000
    with assert_raises(ApptuitException):
        client.query(query, start, end, retry_count=2)
    assert_equals(1, mock_get.call_count)
Example #4
0
def do_query(mock_get):
    """
    Execute the query API and return the mock response
    """
    mock_get.return_value.content = get_mock_response()
    mock_get.return_value.status_code = 200
    token = 'sdksdk203afdsfj_sadasd3939'
    client = Apptuit(sanitize_mode=None, token=token)
    query = "fetch('nyc.taxi.rides')"
    start = 1406831400
    end = 1407609000
    return client.query(query, start, end)