How to use the catcher.utils.misc.fill_template 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 / sh_step.py View on Github external
def action(self, includes: dict, variables: dict) -> dict or tuple:
        cmd = fill_template(self._cmd, variables)
        return_code, stdout, stderr = external_utils.run_cmd(cmd.split(' '),
                                                             variables,
                                                             fill_template(self._path, variables))
        if return_code != int(fill_template(self._return_code, variables)):
            debug('Process return code {}.\nStderr is {}\nStdout is {}'.format(return_code, stderr, stdout))
            raise Exception(stderr)
        return variables, stdout
github comtihon / catcher / catcher / steps / sh_step.py View on Github external
def action(self, includes: dict, variables: dict) -> dict or tuple:
        cmd = fill_template(self._cmd, variables)
        return_code, stdout, stderr = external_utils.run_cmd(cmd.split(' '),
                                                             variables,
                                                             fill_template(self._path, variables))
        if return_code != int(fill_template(self._return_code, variables)):
            debug('Process return code {}.\nStderr is {}\nStdout is {}'.format(return_code, stderr, stdout))
            raise Exception(stderr)
        return variables, stdout
github comtihon / catcher / catcher / steps / sh_step.py View on Github external
def action(self, includes: dict, variables: dict) -> dict or tuple:
        cmd = fill_template(self._cmd, variables)
        return_code, stdout, stderr = external_utils.run_cmd(cmd.split(' '),
                                                             variables,
                                                             fill_template(self._path, variables))
        if return_code != int(fill_template(self._return_code, variables)):
            debug('Process return code {}.\nStderr is {}\nStdout is {}'.format(return_code, stderr, stdout))
            raise Exception(stderr)
        return variables, stdout
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 / check.py View on Github external
def operation(self, variables: dict):
        body = self.subject[self.body]
        source = fill_template(self.determine_source(body), variables)
        subject = fill_template(body['the'], variables)
        result = subject in source
        if self.negative:
            result = not result
        if not result:
            debug(str(subject) + ' is not in ' + str(source))
        return result
github comtihon / catcher / catcher / steps / check.py View on Github external
def operation(self, variables: dict) -> bool:
        if isinstance(self.subject, str):
            subject = fill_template(self.subject, variables)
            source = True
        else:
            body = self.subject[self.body]
            if isinstance(body, str):
                body = Equals.to_long_form(body, True)
            subject = fill_template(body['the'], variables)
            source = fill_template(self.determine_source(body), variables)
        result = source == subject
        if self.negative:
            result = not result
        if not result:
            debug(str(source) + ' is not equal to ' + str(subject))
        return result
github comtihon / catcher / catcher / steps / http.py View on Github external
def action(self, includes: dict, variables: dict) -> Union[tuple, dict]:
        url = fill_template(self.url, variables)
        session = Http.sessions.get(self.session, requests.Session())
        r = None
        try:
            r = session.request(self.method, url, **self._form_request(url, variables))
            if self._should_fail:  # fail expected
                raise RuntimeError('Request expected to fail, but it doesn\'t')
        except requests.exceptions.ConnectionError as e:
            debug(str(e))
            if self._should_fail:  # fail expected
                return variables
        self.__fix_cookies(url, session)
        if self.session is not None:  # save session if name is specified
            Http.sessions[self.session] = session
        if r is None:
            raise Exception('No response received')
        debug(r.text)
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 / 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