vcr.request.Request

Here are the examples of the python api vcr.request.Request taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

0 Source : ipyrest.py
with MIT License
from deeplook

def execute_request(url: str,
                    method: str = 'get',
                    headers: Dict = {},
                    params: Dict = {},
                    json: Dict = {},

                    recorder: Optional[vcr.VCR] = recorder,
                    cassette_path: str = '',
                    logger: Optional[MyLogger] = None) -> Tuple[requests.models.Response, bool]:
    """
    Execute a HTTP request and return response defined by the `requests` package.
    """
    if logger:
        logger.logger.info(
            'execute_request {} {}'.format(recorder, cassette_path))

    is_cached = False
    method_func = requests.__getattribute__(method.lower())
    if cassette_path and recorder:
        from vcr.cassette import Cassette
        from vcr.request import Request
        logger.logger.info('imported vcr')
        req = Request(method.upper(), url,
                      'irrelevant body?', {'some': 'header'})
        logger.logger.info('req ' + str(req))
        c_path = os.path.join(recorder.cassette_library_dir, cassette_path)
        logger.logger.info(c_path)
        logger.logger.info(Cassette(None).load(path=c_path))
        if req in Cassette(None).load(path=c_path):
            is_cached = True
        with recorder.use_cassette(c_path):
            logger.logger.info('running...')
            if json:
                resp = method_func(url, headers=headers, params=params, json=json)
            else:
                resp = method_func(url, headers=headers, params=params)
            logger.logger.info('got it...')
    else:
        if json:
            resp = method_func(url, headers=headers, params=params, json=json)
        else:
            resp = method_func(url, headers=headers, params=params)
    # FIXME: requests.post('http://httpbin.org/post', json={"key": "value"})
    return resp, is_cached


def mask_credentials(text: str, field_names: List[str]) -> str: