Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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()
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)
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,
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"]})
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
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
)
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))
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:
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."
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)