How to use the scanapi.errors.EmptyConfigFileError 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_config_loader.py View on Github external
def test_should_raise_exception(self):
            with pytest.raises(EmptyConfigFileError) as excinfo:
                load_config_file("tests/data/empty.yaml")

            assert str(excinfo.value) == "File 'tests/data/empty.yaml' is empty."
github camilamaia / scanapi / tests / unit / test_scan.py View on Github external
def empty_config_file(*args, **kwargs):
    raise EmptyConfigFileError("valid_path/api.yaml")
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 (
        InvalidKeyError,
github camilamaia / scanapi / scanapi / config_loader.py View on Github external
def load_config_file(file_path):
    extension = os.path.splitext(file_path)[-1]

    if extension not in (".yaml", ".yml", ".json"):
        raise FileFormatNotSupportedError(extension, file_path)

    with open(file_path, "r") as stream:
        logger.info(f"Loading file {file_path}")
        data = yaml.load(stream, Loader)

        if not data:
            raise EmptyConfigFileError(file_path)

        return data
github camilamaia / scanapi / scanapi / errors.py View on Github external
def __init__(self, file_path, *args):
        message = f"File '{file_path}' is empty."
        super(EmptyConfigFileError, self).__init__(message, *args)