Ejemplo n.º 1
0
    def write_fixture_wrapper(*args, **kw):
        kw['mock'] = _noop_mock
        response = func(*args, **kw)
        pattern_from_args = fill_pattern_from_args(pattern, func, *args, **kw)
        json_path = f'{fixture_output_path}/{pattern_from_args}.{suffix}'

        if not response:
            app.logger.warn(f'Error response, will not write fixture to {json_path}')
            return response

        response_body = response.json() if hasattr(response, 'json') else response
        with open(json_path, 'w', encoding='utf-8') as outfile:
            json.dump(response_body, outfile, indent=2)
            app.logger.debug(f'Wrote fixture to {json_path}')
        return response
Ejemplo n.º 2
0
 def register_fixture(*args, **kw):
     evaluated_pattern = fill_pattern_from_args(pattern, func, *args,
                                                **kw)
     return response_from_fixture(evaluated_pattern)