Example #1
0
def test_truncate_request_to_string_casting(handler, logger, request_in,
                                            expected_request_out):

    filter_ = filters.TruncateRequestFilter(entrypoints=['spam'], max_len=24)

    logger.addFilter(filter_)

    extra = {
        constants.TRACE_KEY: {
            constants.STAGE_KEY: constants.Stage.request.value,
            constants.ENTRYPOINT_NAME_KEY: 'spam',
            constants.REQUEST_KEY: request_in,
        },
    }

    logger.info('request', extra=extra)

    data = getattr(handler.log_record, constants.TRACE_KEY)

    assert data[constants.REQUEST_KEY] == expected_request_out
Example #2
0
def test_truncate_request_ignores_response_data(handler, logger):

    filter_ = filters.TruncateRequestFilter(entrypoints=['^spam'], max_len=5)

    logger.addFilter(filter_)

    extra = {
        constants.TRACE_KEY: {
            constants.STAGE_KEY: constants.Stage.response.value,
            constants.ENTRYPOINT_NAME_KEY: 'spam',
            constants.RESPONSE_KEY: '123456789',
        },
    }

    logger.info('response', extra=extra)

    data = getattr(handler.log_record, constants.TRACE_KEY)

    assert data[constants.RESPONSE_KEY] == '123456789'
    assert constants.REQUEST_TRUNCATED_KEY not in data
    assert constants.REQUEST_LENGTH_KEY not in data
    assert constants.RESPONSE_TRUNCATED_KEY not in data
    assert constants.RESPONSE_LENGTH_KEY not in data
Example #3
0
def test_truncate_request(handler, logger, entrypoints, max_len,
                          expected_request, expected_request_length,
                          truncated):

    filter_ = filters.TruncateRequestFilter(entrypoints=entrypoints,
                                            max_len=max_len)

    logger.addFilter(filter_)

    extra = {
        constants.TRACE_KEY: {
            constants.STAGE_KEY: constants.Stage.request.value,
            constants.ENTRYPOINT_NAME_KEY: 'spam',
            constants.REQUEST_KEY: '123456789',
        },
    }

    logger.info('request', extra=extra)

    data = getattr(handler.log_record, constants.TRACE_KEY)

    assert data[constants.REQUEST_KEY] == expected_request
    assert data.get(constants.REQUEST_TRUNCATED_KEY, False) == truncated
    assert data.get(constants.REQUEST_LENGTH_KEY) == expected_request_length