How to use the scanapi.errors.BadConfigurationError function in scanapi

To help you get started, we’ve selected a few scanapi 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 camilamaia / scanapi / tests / unit / test_variable_parser.py View on Github external
def test_should_raise_bad_configuration_error(self):
                    with pytest.raises(BadConfigurationError) as excinfo:
                        evaluate_env_var("${BASE_URL}")

                    assert (
                        str(excinfo.value)
                        == "'BASE_URL' environment variable not set or badly configured"
                    )
github camilamaia / scanapi / tests / unit / evaluators / test_string_evaluator.py View on Github external
def test_should_raise_bad_configuration_error(self):
                    with pytest.raises(BadConfigurationError) as excinfo:
                        StringEvaluator._evaluate_env_var("${BASE_URL}")

                    assert (
                        str(excinfo.value)
                        == "'BASE_URL' environment variable not set or badly configured"
                    )
github camilamaia / scanapi / scanapi / refactor / evaluators / string_evaluator.py View on Github external
def evaluate(cls, sequence, vars):
        try:
            sequence = cls._evaluate_env_var(sequence)
        except BadConfigurationError as e:
            logger.error(e)
            sys.exit()

        sequence = cls._evaluate_custom_var(sequence, vars)

        try:
            return CodeEvaluator.evaluate(sequence, vars)
        except InvalidPythonCodeError as e:
            logger.error(e)
            sys.exit()
github camilamaia / scanapi / scanapi / tree / node.py View on Github external
def evaluate(self, sequence):
        try:
            return self.evaluate_env_var(sequence)
        except BadConfigurationError as e:
            logger.error(e)
            sys.exit()
github camilamaia / scanapi / scanapi / errors.py View on Github external
def __init__(self, env_var, *args):
        super(BadConfigurationError, self).__init__(
            f"{env_var} environment variable not set or badly configured", *args
        )
github camilamaia / scanapi / scanapi / refactor / evaluators / string_evaluator.py View on Github external
def _evaluate_env_var(cls, sequence):
        matches = cls.variable_pattern.finditer(sequence)

        if not matches:
            return sequence

        for match in matches:
            variable_name = match.group("variable")

            if any(letter.islower() for letter in variable_name):
                continue

            try:
                variable_value = os.environ[variable_name]
            except KeyError as e:
                raise BadConfigurationError(e)

            sequence = cls.replace_var_with_value(
                sequence, match.group(), variable_value
            )

        return sequence
github camilamaia / scanapi / scanapi / tree / node.py View on Github external
def evaluate_env_var(self, sequence):
        matches = self.variable_pattern.finditer(sequence)

        if not matches:
            return sequence

        for match in matches:
            variable_name = match.group("variable")

            if any(letter.islower() for letter in variable_name):
                continue

            try:
                variable_value = os.environ[variable_name]
            except KeyError as e:
                raise BadConfigurationError(e)

            sequence = self.replace_var_with_value(
                sequence, match.group(), variable_value
            )

        return sequence
github camilamaia / scanapi / scanapi / evaluators / string_evaluator.py View on Github external
def _evaluate_env_var(cls, sequence):
        matches = cls.variable_pattern.finditer(sequence)

        if not matches:
            return sequence

        for match in matches:
            variable_name = match.group("variable")

            if any(letter.islower() for letter in variable_name):
                continue

            try:
                variable_value = os.environ[variable_name]
            except KeyError as e:
                raise BadConfigurationError(e)

            sequence = cls.replace_var_with_value(
                sequence, match.group(), variable_value
            )

        return sequence