How to use the scanapi.exit_code.ExitCode 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 / scanapi / scan.py View on Github external
def scan():
    spec_path = settings["spec_path"]

    try:
        api_spec = load_config_file(spec_path)
    except FileNotFoundError as e:
        error_message = f"Could not find API spec file: {spec_path}. {str(e)}"
        logger.error(error_message)
        raise SystemExit(ExitCode.USAGE_ERROR)
    except EmptyConfigFileError as e:
        error_message = f"API spec file is empty. {str(e)}"
        logger.error(error_message)
        raise SystemExit(ExitCode.USAGE_ERROR)
    except (yaml.YAMLError, FileFormatNotSupportedError) as e:
        logger.error(e)
        raise SystemExit(ExitCode.USAGE_ERROR)

    try:
        if API_KEY not in api_spec:
            raise MissingMandatoryKeyError({API_KEY}, ROOT_SCOPE)

        root_node = EndpointNode(api_spec[API_KEY])
        results = root_node.run()

    except (
github camilamaia / scanapi / scanapi / session.py View on Github external
def exit(self):
        if self.errors:
            sys.exit(ExitCode.TESTS_ERROR)

        if self.failures:
            sys.exit(ExitCode.TESTS_FAILED)

        sys.exit(self.exit_code)
github camilamaia / scanapi / scanapi / scan.py View on Github external
if API_KEY not in api_spec:
            raise MissingMandatoryKeyError({API_KEY}, ROOT_SCOPE)

        root_node = EndpointNode(api_spec[API_KEY])
        results = root_node.run()

    except (
        InvalidKeyError,
        MissingMandatoryKeyError,
        KeyError,
        InvalidPythonCodeError,
    ) as e:
        error_message = "Error loading API spec."
        error_message = "{} {}".format(error_message, str(e))
        logger.error(error_message)
        raise SystemExit(ExitCode.USAGE_ERROR)

    try:
        write_report(results)
    except (BadConfigurationError, InvalidPythonCodeError) as e:
        logger.error(e)
        raise SystemExit(ExitCode.USAGE_ERROR)

    session.exit()
github camilamaia / scanapi / scanapi / tree / endpoint_node.py View on Github external
def run(self):
        for request in self._get_requests():
            try:
                yield request.run()
            except Exception as e:
                error_message = (
                    f"\nError to make request `{request.full_url_path}`. \n{str(e)}\n"
                )
                logger.error(error_message)
                session.exit_code = ExitCode.REQUEST_ERROR
                continue
github camilamaia / scanapi / scanapi / session.py View on Github external
def __init__(self):
        self.successes = 0
        self.failures = 0
        self.errors = 0
        self.exit_code = ExitCode.OK