How to use the scanapi.errors.InvalidKeyError 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_scan.py View on Github external
def invalid_key(*args, **kwargs):
    raise InvalidKeyError("foo", "endpoint", ["bar", "other"])
github camilamaia / scanapi / tests / unit / tree / test_api_node.py View on Github external
def test_should_raise_an_exception(self):
                keys = ["key1", "key2"]
                available_keys = ("key1", "key3")
                scope = "root"

                with pytest.raises(InvalidKeyError) as excinfo:
                    APINode.validate_keys(keys, available_keys, scope)

                assert (
                    str(excinfo.value)
                    == "Invalid key `key2` at `root` scope. Available keys are: ('key1', 'key3')"
                )
github camilamaia / scanapi / tests / unit / test_utils.py View on Github external
def test_should_raise_an_exception(self):
            keys = ["key1", "key2"]
            available_keys = ("key1", "key3")
            mandatory_keys = ("key1", "key2")
            scope = "endpoint"

            with pytest.raises(InvalidKeyError) as excinfo:
                validate_keys(keys, available_keys, mandatory_keys, scope)

            assert (
                str(excinfo.value)
                == "Invalid key 'key2' at 'endpoint' scope. Available keys are: ('key1', 'key3')"
            )
github camilamaia / scanapi / scanapi / scan.py View on Github external
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,
        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 / utils.py View on Github external
def _validate_allowed_keys(keys, available_keys, scope):
    for key in keys:
        if not key in available_keys:
            raise InvalidKeyError(key, scope, available_keys)
github camilamaia / scanapi / scanapi / tree / api_node.py View on Github external
def validate_keys(self, keys, available_keys, scope):
        for key in keys:
            if not key in available_keys:
                raise InvalidKeyError(key, scope, available_keys)
github camilamaia / scanapi / scanapi / errors.py View on Github external
def __init__(self, key, scope, available_keys, *args):
        message = f"Invalid key '{key}' at '{scope}' scope. Available keys are: {available_keys}"
        super(InvalidKeyError, self).__init__(message, *args)