How to use the marshmallow.ValidationError function in marshmallow

To help you get started, we’ve selected a few marshmallow 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 xen0l / aws-gate / test / unit / test_cli.py View on Github external
def test_cli_invalid_config(self):
        with patch('aws_gate.cli.parse_arguments', return_value=MagicMock(subcommand='bootstrap')), \
             patch('aws_gate.cli.load_config_from_files', side_effect=ValidationError(message='error')):
            with self.assertRaises(ValueError):
                main()
github packit-service / packit / tests / unit / test_package_config.py View on Github external
def test_package_config_validate(raw, is_valid):
    if not is_valid:
        with pytest.raises((ValidationError, ValueError)):
            PackageConfig.get_from_dict(raw)
    else:
        PackageConfig.get_from_dict(raw)
github polyaxon / polyaxon / tests / test_polyflow / test_schedule.py View on Github external
def test_interval_schedule(self):
        config_dict = {"frequency": 2, "start_at": "foo"}
        with self.assertRaises(ValidationError):
            IntervalScheduleConfig.from_dict(config_dict)

        config_dict = {"frequency": "foo", "start_at": local_now().isoformat()}
        with self.assertRaises(ValidationError):
            IntervalScheduleConfig.from_dict(config_dict)

        config_dict = {
            "kind": "cron",
            "frequency": 2,
            "start_at": local_now().isoformat(),
            "end_at": local_now().isoformat(),
        }
        with self.assertRaises(ValidationError):
            IntervalScheduleConfig.from_dict(config_dict)

        config_dict = {"frequency": 2, "start_at": local_now().isoformat()}
        IntervalScheduleConfig.from_dict(config_dict)

        config_dict = {
            "frequency": 2,
github polyaxon / polyaxon / tests / test_ops / test_container / test_container.py View on Github external
def test_config_with_without_image(self):
        with self.assertRaises(ValidationError):
            ContainerConfig.from_dict({})

        with self.assertRaises(ValidationError):
            ContainerConfig.from_dict({"command": ["foo"], "args": ["foo"]})
github andreoliwa / nitpick / src / nitpick / fields.py View on Github external
def validate_section_dot_field(section_field: str) -> bool:
    """Validate if the combinatio section/field has a dot separating them."""
    common = "Use ."
    if "." not in section_field:
        raise ValidationError("Dot is missing. {}".format(common))
    parts = section_field.split(".")
    if len(parts) > 2:
        raise ValidationError("There's more than one dot. {}".format(common))
    if not parts[0].strip():
        raise ValidationError("Empty section name. {}".format(common))
    if not parts[1].strip():
        raise ValidationError("Empty field name. {}".format(common))
    return True
github polyaxon / polyaxon / cli / polyaxon / deploy / schemas / persistence.py View on Github external
def validate_named_persistence(values, persistence):
    if not values:
        return
    for key, value in six.iteritems(values):
        try:
            PersistenceEntityConfig.from_dict(value)
        except (KeyError, ValidationError):
            raise ValidationError(
                "Persistence name `{}` under `{}` is not valid.".format(
                    key, persistence
                )
github govau / notify / api / app / schemas.py View on Github external
def check_unknown_fields(self, data, original_data):
        for key in original_data:
            if key not in self.fields:
                raise ValidationError('Unknown field name {}'.format(key))
github polyaxon / polyaxon / cli / polyaxon / main.py View on Github external
def cli(context, verbose, offline):
    """ Polyaxon CLI tool to:

        * Parse, Validate, and Check Polyaxonfiles.

        * Interact with Polyaxon server.

        * Run and Monitor experiments.

    Check the help available for each command listed below.
    """

    try:
        configure_logger(verbose or ClientConfigManager.get_value("debug"))
    except ValidationError:
        ClientConfigManager.purge()
    non_check_cmds = [
        "completion",
        "config",
        "version",
        "login",
        "logout",
        "deploy",
        "admin",
        "teardown",
    ]
    context.obj = context.obj or {}
    if not settings.CLIENT_CONFIG.client_header:
        settings.CLIENT_CONFIG.set_cli_header()
    context.obj["offline"] = offline
    if offline:
github smallwat3r / shhh / shhh / api / validators.py View on Github external
def validate_haveibeenpwned(passphrase: str) -> None:
    """Validate passphrase against haveibeenpwned API."""
    try:
        times_pwned = services.pwned_password(passphrase)
    except Exception as err:  # pylint: disable=broad-except
        app.logger.error(err)
        times_pwned = False  # don't break if service isn't reachable.

    if times_pwned:
        raise ValidationError(
            f"This password has been pwned {times_pwned} times "
            "(haveibeenpwned.com), please chose another one."
github Scille / umongo / umongo / frameworks / pymongo.py View on Github external
errors = {}
    for name, field in schema.fields.items():
        if partial and name not in partial:
            continue
        value = data_proxy.get(name)
        if value is ma.missing:
            continue
        try:
            if field.io_validate_recursive:
                field.io_validate_recursive(field, value)
            if field.io_validate:
                _run_validators(field.io_validate, field, value)
        except ma.ValidationError as exc:
            errors[name] = exc.messages
    if errors:
        raise ma.ValidationError(errors)