How to use the scanapi.errors.MissingMandatoryKeyError 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 missing_mandatory_key(*args, **kwargs):
    raise MissingMandatoryKeyError(["foo", "bar"], "endpoint")
github camilamaia / scanapi / tests / unit / tree / test_request_node.py View on Github external
def test_missing_required_keys(self):
            with pytest.raises(MissingMandatoryKeyError) as excinfo:
                request = RequestNode(
                    spec={}, endpoint=EndpointNode({"name": "foo", "requests": [{}]})
                )

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

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

            assert str(excinfo.value) == "Missing 'key2' key(s) at 'endpoint' scope"
github camilamaia / scanapi / tests / unit / tree / test_testing_node.py View on Github external
def test_missing_required_keys(self):
            with pytest.raises(MissingMandatoryKeyError) as excinfo:
                request_node = RequestNode(
                    spec={"name": "foo", "path": "bar"},
                    endpoint=EndpointNode({"name": "foo", "requests": [{}]}),
                )
                test_node = TestingNode(spec={}, request=request_node)

            assert (
                str(excinfo.value) == "Missing 'assert', 'name' key(s) at 'test' scope"
            )
github camilamaia / scanapi / tests / unit / tree / test_endpoint_node.py View on Github external
def test_missing_required_keys(self):
            with pytest.raises(MissingMandatoryKeyError) as excinfo:
                endpoints = [{}, {}]
                node = EndpointNode({"endpoints": endpoints})

            assert str(excinfo.value) == "Missing 'name' key(s) at 'endpoint' scope"
github camilamaia / scanapi / scanapi / scan.py View on Github external
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,
        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:
github camilamaia / scanapi / scanapi / utils.py View on Github external
def _validate_required_keys(keys, required_keys, scope):
    if not set(required_keys) <= set(keys):
        missing_keys = set(required_keys) - set(keys)
        raise MissingMandatoryKeyError(missing_keys, scope)
github camilamaia / scanapi / scanapi / errors.py View on Github external
def __init__(self, missing_keys, scope, *args):
        missing_keys_str = ", ".join(f"'{k}'" for k in sorted(missing_keys))
        message = f"Missing {missing_keys_str} key(s) at '{scope}' scope"
        super(MissingMandatoryKeyError, self).__init__(message, *args)