How to use the catcher.utils.file_utils.read_file function in catcher

To help you get started, we’ve selected a few catcher examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github comtihon / catcher / catcher / steps / http.py View on Github external
def __prepare_file(file: dict, variables: dict):
        resources = variables['RESOURCES_DIR']
        [file_key] = [k for k in file.keys() if k != 'type']
        filepath = file[file_key]
        file_type = file.get('type', 'text/plain')
        filename = file_utils.get_filename(filepath)
        file = fill_template_str(file_utils.read_file(os.path.join(resources, filepath)), variables)
        return file_key, (filename, file, file_type)
github comtihon / catcher / catcher / steps / http.py View on Github external
def __form_body(self, variables) -> tuple:
        if self.method == 'get':
            return False, None
        body = self.body
        if body is None and self.file is not None:
            resources = variables['RESOURCES_DIR']
            body = file_utils.read_file(fill_template_str(os.path.join(resources, self.file), variables))
        if isinstance(body, dict) or isinstance(body, list):  # dump body to json to be able fill templates in
            body = json.dumps(body)
        if body is None:
            return False, None
        isjson = 'tojson' in body
        return isjson, fill_template(body, variables, isjson=isjson)
github comtihon / catcher / catcher / steps / echo.py View on Github external
def action(self, includes: dict, variables: dict) -> tuple:
        if self.source_file:  # read from file
            resources = variables['RESOURCES_DIR']
            out = fill_template_str(read_file(os.path.join(resources, self.source_file)), variables)
        else:
            out = fill_template(self.source, variables)
        if self.dst is None:
            info(out)
        else:
            dst = fill_template(self.dst, variables)
            with open(join(self.path, dst), 'w') as f:
                f.write(str(out))
        return variables, out
github comtihon / catcher / catcher / steps / kafka.py View on Github external
def __form_body(self, variables):
        data = self.data
        if data is None:
            data = read_file(fill_template_str(self.file, variables))
        return fill_template_str(data, variables)